Welcome Guest, Not a member yet? Register   Sign In
Yaml library
#2

[eluser]OliverHR[/eluser]
Wrapper (codeigniter library) and sfyaml.

-ci_sfyaml.zip

Tested with codeigniter versions:
- 1.7.2


To load this library:
Code:
$this->load->library('yaml');


[h3]Method Summary[/h3]

load
Loads YAML into a PHP array.
* @param string $input Path of YAML file or string containing YAML
Code:
$input = APPPATH . 'directory/filename.yml';
$this->yaml->load($input); // return array


dump
Dumps a PHP array to a YAML string.
* @param integer $inline - The level where you switch to inline YAML

Code:
$this->yaml->dump($array, $inline); // return string
Code:
$array = array(
   'one' => array (
         'id' => 1,
         'username' => 'administrator',
         'password' => 'adminpass',
         'email' => '[email protected]',
         'fullname' => 'Jonh Doe',
         'role' => 1
   ),

   'two' => array (
         'id' => 2,
         'username' => 'manager',
         'password' => 'manpass',
         'email' => '[email protected]',
         'fullname' => 'Jane Doe',
         'role' => 2
   )
);
$inline = 2;
$this->yaml->dump($array, $inline);

Returns this YAML string representing the original PHP array:
Code:
one:
  id: 1
  username: administrator
  password: adminpass
  email: [email protected]
  fullname: 'John Doe'
  role: 1
two:
  id: 2
  username: manager
  password: manpass
  email: [email protected]
  fullname: 'Jane Doe'
  role: 2


write_yml
Save a file with a YAML string Dumped from a PHP array.
* @param string $file File name
* @param array $array PHP array
* @param string $path Optional specific directory path to save the file
Code:
$this->yaml->write_yml($file, $array, $path = '');
Code:
$path = APPPATH.'fixtures';
$this->yaml->write_yml('temp.yml', $array, $path);
Code:
$file = APPPATH.'fixtures/temp.yml';
$this->yaml->write_yml($file, $array);
In both cases the file is saved to: application/fixtures/temp.yml


getSpecVersion
Gets the YAML specification version to use.
Code:
$this->yaml->getSpecVersion() // return string


setSpecVersion
Sets the YAML specification version to use.
Code:
$this->yaml->setSpecVersion($version) // return void

Note: Default Yaml specification version is 1.2


Messages In This Thread
Yaml library - by El Forum - 09-25-2010, 08:40 PM
Yaml library - by El Forum - 09-25-2010, 09:20 PM
Yaml library - by El Forum - 09-26-2010, 12:24 AM
Yaml library - by El Forum - 09-27-2010, 03:02 PM
Yaml library - by El Forum - 09-28-2010, 08:17 AM
Yaml library - by El Forum - 10-22-2010, 08:23 AM
Yaml library - by El Forum - 10-22-2010, 01:25 PM
Yaml library - by El Forum - 07-30-2011, 07:17 PM



Theme © iAndrew 2016 - Forum software by © MyBB