Esempio n. 1
0
File: Yaml.php Progetto: jasny/Q
 /**
  * Transform array to yaml and return the result
  *
  * @param mixed $data
  * @return string
  */
 public function process($data)
 {
     if ($this->chainInput) {
         $data = $this->chainInput->process($data);
     }
     if ($this->fastDump) {
         return syck_dump($data);
     }
     return $this->serialize($data);
 }
Esempio n. 2
0
 /**
  *  Given a php structure, returns a valid YAML string representation.
  *
  *  @param mixed PHP data
  *  @return string YAML equivalent.
  */
 public static function dump($phpData)
 {
     if (function_exists('yaml_emit')) {
         return yaml_emit($phpData);
     } else {
         if (function_exists('syck_dump')) {
             // php-lib-c version, much faster!
             return syck_dump($phpData);
         } else {
             // php version
             return Horde_Yaml::dump($phpData);
         }
     }
 }
Esempio n. 3
0
File: YAML.php Progetto: ksst/kf
 /**
  * Write the config array to a yaml file.
  *
  * @param   string The yaml file.
  *
  * @return bool True, if successfully written, else False.
  */
 public static function write($file, array $array)
 {
     // prefer yaml, then syck, else use Spyc - faster one first
     if (extension_loaded('yaml')) {
         return yaml_emit_file($file, $array);
     } elseif (extension_loaded('syck')) {
         $yaml = syck_dump($array);
     } elseif (class_exists('Spyc')) {
         $spyc = new Spyc();
         $yaml = $spyc->dump($array);
     } else {
         throw new \Koch\Exception\Exception('No YAML Parser available. Get Spyc or Syck!');
     }
     return (bool) file_put_contents($file, $yaml, LOCK_EX);
 }
Esempio n. 4
0
 public function testLargeArrays()
 {
     $obj = range(1, 10000);
     $this->assertSame($obj, syck_load(syck_dump($obj)));
 }
Esempio n. 5
0
 public function save($locale, $path)
 {
     file_put_contents($this->get_translation_file_path($path, $locale), 
                       syck_dump($this->translations[$locale]));
 }
Esempio n. 6
0
File: Syck.php Progetto: Nivl/Ninaca
 public function dump(array $array)
 {
     return syck_dump($array);
 }
Esempio n. 7
0
 /**
  * Write the config array to a yaml file
  *
  * @param   string  The filename
  * @return array | boolean false
  * @todo fix this return true/false thingy
  */
 public static function writeConfig($file, array $array)
 {
     /**
      * transform PHP Array into YAML Format
      */
     // take syck, as the faster one first
     if (extension_loaded('syck')) {
         // convert to YAML via SYCK
         $yaml = syck_dump($data);
     } elseif (is_file(ROOT_LIBRARIES . '/spyc/Spyc.class.php') === true) {
         // ok, load spyc
         if (false === class_exists('Spyc', false)) {
             include ROOT_LIBRARIES . '/spyc/Spyc.class.php';
         }
         $spyc = new Spyc();
         // convert to YAML via SPYC
         $yaml = $spyc->dump($array);
     } else {
         // we have no YAML Parser - too bad :(
         throw new Koch_Exception('No YAML Parser available. Get Spyc or Syck!');
     }
     /**
      * write array
      */
     // write YAML content to file
     file_put_contents($file, $yaml);
 }
Esempio n. 8
0
			throw new OC_Shorty_Exception ( "Sorry, no payload format specified." );

			case 'json':
				// check availability of phps yaml extension ("syck")
				if ( ! extension_loaded('json') )
					throw new OC_Shorty_Exception ( "Sorry, support for payload format 'json' not installed." );
				// output payload
				print json_encode($reply);
			break;

			case 'yaml':
				// first option: php extension 'yaml'
				if ( extension_loaded('yaml') )
					print yaml_emit($reply);
				elseif ( function_exists('syck_dump') )
					syck_dump($reply);
				elseif (class_exists('Spyc'))
					Spyc::YAMLDump($reply);
				else
					// no implementation found, sorry...
					throw new OC_Shorty_Exception ( "Sorry, support for payload format 'yaml' not installed." );
			break;

			case 'csv':
				// apparently php _always_ offers csv support...
				// output payload
				$buffer = fopen('php://temp', 'r+');
				foreach ($reply as $entry) {
					fputcsv($buffer, $entry);
				} // foreach
				rewind($buffer);
Esempio n. 9
0
 /**
  * Dumps configuration array and returns it as a string
  *
  * @param array $configuration Configuration array     
  * @return string Configuration in string format
  */
 public function serialize(array $configuration)
 {
     // TODO: Implement using http://spyc.sourceforge.net/ if syck is not available
     return syck_dump($configuration);
 }
Esempio n. 10
0
 function _buildYaml($tables)
 {
     if (!is_array($tables)) {
         $tables = array($tables);
     }
     foreach ($tables as $table) {
         $dbShema['UP']['create_table'][$table] = $this->__buildUpSchema($table);
         $dbShema['DOWN']['drop_table'][] = $table;
     }
     if (count($dbShema['DOWN']['drop_table']) == 1) {
         $dbShema['DOWN']['drop_table'] = $dbShema['DOWN']['drop_table'][0];
     }
     // print file header
     $out = '#' . "\n";
     $out .= '# migration YAML file' . "\n";
     $out .= '#' . "\n";
     if (function_exists('syck_dump')) {
         return syck_dump($dbShema);
     } else {
         App::import('Vendor', 'Spyc');
         return Spyc::YAMLDump($dbShema);
     }
 }
Esempio n. 11
0
 	public function save()
 	{
 		switch($this->format)
 		{
 			case 'js':
 				file_put_contents($this->filename.'.js',json_encode($this->items));
 				break;
 			case 'yaml':
 				file_put_contents($this->filename.'.conf',syck_dump($this->items));
 				break;
 			default:
 				throw new Exception("Invalid format for saving.");
 		}
 	}
Esempio n. 12
0
 function startFixture($name)
 {
     $file = FIXTURES_PATH . DS . $name . '.yml';
     if (function_exists('syck_dump')) {
         $data = syck_dump($this->_parsePhp($file));
     } else {
         App::import('Vendor', 'Spyc');
         $data = Spyc::YAMLDump($this->_parsePhp($file));
     }
     if (!is_array($data) || count($data) === 0) {
         $this->out('* Fixtures undefined *');
         return false;
     }
     if (!is_array($data) || !count($data)) {
         $this->err("Unable to parse YAML Fixture file: '{$file}'");
     }
     $model = new Model(false, $name);
     $this->db->truncate($model);
     $count = 0;
     $created = array();
     foreach ($data as $ri => $r) {
         $records = array();
         foreach ($r as $fi => $f) {
             if (preg_match("/_id\$/", $fi) && !is_id($f)) {
                 $records[$fi] = $created[$f]['id'];
             } elseif (preg_match("/^\\.([A-Z_]+)\$/", $f, $matches)) {
                 $helper = Inflector::variable(strtolower($matches[1]));
                 if (!method_exists($this->helpers, $helper)) {
                     $this->err("Found Helper '{$f}' in fixture '{$name}.yml', but Helper method '{$helper}()' does not exist.");
                 }
                 $records[$fi] = $this->helpers->{$helper}();
             } else {
                 $records[$fi] = $f;
             }
         }
         if (isset($model->_schema['created']) && !array_key_exists('created', $records)) {
             $records['created'] = date('Y-m-d H:i:s');
         }
         $use_uuid = false;
         if (!array_key_exists('id', $r) && isset($model->_schema['id']) && $model->_schema['id']['type'] == 'string' && $model->_schema['id']['length'] == 36) {
             $records['id'] = String::uuid();
             $use_uuid = true;
         }
         $res = $this->db->create($model, array_keys($records), array_values($records));
         if ($res) {
             $records['id'] = $use_uuid ? $records['id'] : $model->id;
             $created[$ri] = $records;
         }
         $count++;
     }
     $this->out("{$count} rows inserted.");
 }
Esempio n. 13
0
 public function arrayToYaml(array $array)
 {
     return syck_dump($array);
 }