public static function emitFile($data, $file) { if (file_exists($file) and !is_writable($file)) { throw new pakeException('Not enough rights to overwrite "' . $file . '"'); } $dir = dirname($file); pake_mkdirs($dir); if (!is_writable($dir)) { throw new pakeException('Not enough rights to create file in "' . $dir . '"'); } if (extension_loaded('yaml')) { // not yet implemented: // yaml_emit_file($file, $data); // so using this instead: if (false === file_put_contents($file, yaml_emit($data))) { throw new pakeException("Couldn't create file"); } } else { sfYaml::setSpecVersion('1.1'); // more compatible $dumper = new sfYamlDumper(); if (false === file_put_contents($file, $dumper->dump($data, 1))) { throw new pakeException("Couldn't create file"); } } pake_echo_action('file+', $file); }
function yaml_sfyaml_encode($struct, $opt = array()) { require_once _DIR_PLUGIN_YAML . 'sfyaml/sfYaml.php'; require_once _DIR_PLUGIN_YAML . 'sfyaml/sfYamlDumper.php'; $opt = array_merge(array('inline' => 2), $opt); $yaml = new sfYamlDumper(); return $yaml->dump($struct, $opt['inline']); }
protected function doWriteFixture($file) { if (empty($this->permissions)) { return; } $permissions = array('DmPermission' => $this->permissions); $dumped = new sfYamlDumper(); $fixture = $dumped->dump($permissions, 5); $this->getFilesystem()->mkdirs(dirname($file)); file_put_contents($file, $fixture); $this->logSection('file+', $file); }
protected function execute($arguments = array(), $options = array()) { // initialize the database connection $databaseManager = new sfDatabaseManager($this->configuration); $connection = $databaseManager->getDatabase($options['connection'])->getConnection(); // Checking that the csv file exist $file = sfConfig::get('sf_root_dir') . DIRECTORY_SEPARATOR . $arguments['file']; if (!file_exists($file)) { throw new sfException(sprintf('File %s does not exist.', $file)); } // building fixture file name and path $user = isset($options['User']) ? $options['User'] : '******'; $vehicle = isset($options['Vehicle']) ? $options['Vehicle'] : 'astra'; $fixture_file = isset($options['fixture']) ? $options['fixture'] : $this->getFixtureFile('11_' . $user . '_' . $vehicle); $fixture_file = sfConfig::get('sf_data_dir') . DIRECTORY_SEPARATOR . $fixture_file; if (file_exists($fixture_file)) { $answer = $this->askConfirmation(sprintf('A yaml fixture already exist in "%s". Overwrite? [Y/n]', $fixture_file)); if (!$answer) { return false; } } $file_handle = fopen($file, "r"); $fixtures = array(); $id = 0; while (!feof($file_handle)) { $line_of_text = fgetcsv($file_handle, 1024); $s = $this->importLine($line_of_text, $options); if (!$s) { continue; } $id++; $fname = $s['User'] . '_' . $s['Vehicle'] . '_' . $id; $fixtures[$fname] = $s; $this->log(sprintf('Read line %d', $id)); } fclose($file_handle); // Writing yaml file $fixtures = array('Charge' => $fixtures); $dumper = new sfYamlDumper(); $yaml = $dumper->dump($fixtures, 3); file_put_contents($fixture_file, $yaml); $this->log(sprintf('OK fixture file successfully created in %s.', $fixture_file)); }
/** * A failure occurred. * * @param PHPUnit_Framework_Test $test * @param PHPUnit_Framework_AssertionFailedError $e * @param float $time */ public function addFailure(PHPUnit_Framework_Test $test, PHPUnit_Framework_AssertionFailedError $e, $time) { $this->writeNotOk($test, 'Failure'); $message = explode("\n", PHPUnit_Framework_TestFailure::exceptionToString($e)); $diagnostic = array('message' => $message[0], 'severity' => 'fail'); if ($e instanceof PHPUnit_Framework_ExpectationFailedException) { $cf = $e->getComparisonFailure(); if ($cf !== NULL) { $diagnostic['data'] = array('got' => $cf->getActual(), 'expected' => $cf->getExpected()); } } $yaml = new sfYamlDumper(); $this->write(sprintf(" ---\n%s ...\n", $yaml->dump($diagnostic, 2, 2))); }
/** * Dump YAML from PHP array statically * * The dump method, when supplied with an array, will do its best * to convert the array into friendly YAML. * * @param array $array PHP array * * @return string */ public static function dump($array, $inline = 2) { require_once dirname(__FILE__) . '/sfYamlDumper.class.php'; $yaml = new sfYamlDumper(); return $yaml->dump($array, $inline); }
/** * Dumps a PHP array to a YAML string. * * The dump method, when supplied with an array, will do its best * to convert the array into friendly YAML. * * @param array $array PHP array * @param integer $inline The level where you switch to inline YAML * * @return string A YAML string representing the original PHP array */ public static function dump($array, $inline = 2) { require_once 'yaml/sfYamlDumper.php'; $yaml = new sfYamlDumper(); return $yaml->dump($array, $inline); }
<?php /* * This file is part of the symfony package. * (c) Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once dirname(__FILE__) . '/../../bootstrap/unit.php'; sfYaml::setSpecVersion('1.1'); $t = new lime_test(149); $parser = new sfYamlParser(); $dumper = new sfYamlDumper(); $path = dirname(__FILE__) . '/fixtures'; $files = $parser->parse(file_get_contents($path . '/index.yml')); foreach ($files as $file) { $t->diag($file); $yamls = file_get_contents($path . '/' . $file . '.yml'); // split YAMLs documents foreach (preg_split('/^---( %YAML\\:1\\.0)?/m', $yamls) as $yaml) { if (!$yaml) { continue; } $test = $parser->parse($yaml); if (isset($test['dump_skip']) && $test['dump_skip']) { continue; } else { if (isset($test['todo']) && $test['todo']) { $t->todo($test['test']); } else {
/** * Преобразуем данные из кучи в Yaml * @return void */ private function _setYmlData() { foreach ($this->_heap as $key => $value) { if (preg_match("/_keys\$/", $key)) { unset($this->_heap[$key]); } else { } } $yamlDumper = new sfYamlDumper(); $this->_ymlData = $yamlDumper->dump($this->_heap, 3); }
/** * Create a Yaml file * * Array must be passed to dump yo Yaml format and then * write a file with to the specified path. * * @param string $file File name * @param string $path Specific path to save the file * @param array $array PHP array */ public function write_yml($file, $array, $path = '') { $file = trim($file); if ($path != '' and is_dir($path)) { $path = rtrim($path, '/') . '/'; } else { $path = ''; } require_once dirname(__FILE__) . '/yaml/sfYamlDumper.php'; $dumper = new sfYamlDumper(); $yaml = $dumper->dump($array, $inline = 2); return file_put_contents($path . $file, $yaml); }
/** * Convert $data (using $options) for writing as a string. * * @param string $data The data to convert. * @param array $options The options for converting data. * @return string * @access public */ public function output($data, $options = array()) { include_once CURATOR_APP_DIR . DS . 'Vendors' . DS . 'yaml' . DS . 'dist' . DS . 'lib' . DS . 'sfYamlDumper.php'; $yaml = new \sfYamlDumper(); $result = null; try { $result = $yaml->dump($data); } catch (\Exception $e) { \Curator\Console::stderr('** Unable to convert array to YAML:'); \Curator\Console::stderr(' ', $e->getMessage()); } return $result; }
public static function dump($array, $inline = 2) { $yaml = new sfYamlDumper(); return $yaml->dump($array, $inline); }
public function createSchema() { $dumper = new sfYamlDumper(); $yaml = $dumper->dump($this->mountSchema(), 4); WriteToFile::writeContent($yaml, PATH_CONFIG, 'schemaTemp.yml'); }