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); }
public function serialize() { if (!$this->object instanceof \Serializable) { throw new \Exception('Object is not an instance of Serializable.'); } return \yaml_emit($this->object->serialize()); }
/** * @param mixed $data * @param string $format * @param array $context * * @return string */ public function encode($data, $format, array $context = array()) { if ($this->native) { return yaml_emit($data, YAML_UTF8_ENCODING, YAML_LN_BREAK); } return $this->encoder->dump($data); }
/** * @see sys/app/driver/serializer/ArraySerializer#do_serialize() */ public function do_serialize() { $result = parent::do_serialize(); $syck = yaml_emit($result); $syck = preg_replace('#"([^"]+)":#m', '$1:', $syck); return $syck; }
/** * Sends a content string to the client. * * If the content is a callable, it is invoked. The callable should either * return a string or output content directly and have no return value. * * @param array|string $content String to send as response body or callable * which returns/outputs content. * @return void */ protected function _sendContent($content) { if (is_array($content)) { $content = yaml_emit($content); } parent::_sendContent($content); }
public function __invoke($data) { set_error_handler($this->generateErrorHandler($data)); $parsed = yaml_emit($data); restore_error_handler(); return $parsed; }
/** * {@inheritdoc} */ public function to(array $data, $comments = null) { if ($comments) { return $comments . PHP_EOL . yaml_emit($data); } return yaml_emit($data); }
public function exec() { try { $mod_cnf = yaml_parse_file(__DIR__ . '/../../../../conf/module.yml'); if (false === $mod_cnf) { throw new \err\ComErr('could not read module config file', 'please check ' . __DIR__ . '/../../../../conf/module.yml'); } for ($loop = 0; $loop < count($mod_cnf); $loop++) { /* check for the module name(*chkmod) 'select' value is 'true' */ if (true === $mod_cnf[$loop]['select'] && 0 === strcmp($this->parm, $mod_cnf[$loop]['name'])) { /* nothing to do */ /* it is already selected if chkmod and specified module name is same */ return; } $mod_cnf[$loop]['select'] = false; if (0 === strcmp($this->parm, $mod_cnf[$loop]['name'])) { /* switching 'select' value(true) from module config */ $mod_cnf[$loop]['select'] = true; } } /* edit module config from (spac dir)/conf/module.yml */ if (false === copy(__DIR__ . '/../../../../conf/module.yml', __DIR__ . '/../../../../conf/module.yml_')) { throw new \err\ComErr('could not create backup of module config', 'please check ' . __DIR__ . '/../../../../conf'); } if (false === file_put_contents(__DIR__ . '/../../../../conf/module.yml', yaml_emit($mod_cnf))) { throw new \err\ComErr('could not edit module config file', 'please check ' . __DIR__ . '/../../../../conf/module.yml'); } unlink(__DIR__ . '/../../../../conf/module.yml_'); echo 'switched generater module ' . $this->parm . PHP_EOL; } catch (\Exception $e) { throw $e; } }
function buildFile() { $updated_date = strtotime($_POST['date']) > time() ? $_POST['date'] : date("Y-m-d"); $content = array('rss' => false, 'layout' => 'update', 'published' => $_POST['published'] == 'true' ? true : false, 'title' => $_POST['title'], 'date' => $_POST['date'], 'article' => array('written_on' => $_POST['date'], 'updated_on' => $updated_date), 'authors' => array($_POST['author']), 'collection' => 'updates', 'type' => $_POST['type'], 'category' => $_POST['product'] == 'none' || $_POST['product'] == 'chrome' ? 'generic' : 'tools'); $content['product'] = $_POST['product']; if ($_POST['tags']) { $content['tags'] = preg_split("/[\\s,]+/", $_POST['tags']); } if ($_POST['description']) { $content['description'] = $_POST['description']; } if ($_POST['featured-image']) { $content['featured-image'] = $_POST['featured-image']; } if ($_POST['source_name']) { $content['source_name'] = $_POST['source_name']; } if ($_POST['source_url']) { $content['source_url'] = $_POST['source_url']; } $content['permalink'] = '/updates/' . str_replace('-', '/', $_POST['date']) . '/' . slugify($_POST['title']) . '.html'; $file = yaml_emit($content, YAML_UTF8_ENCODING); // we need to replace the weird ... block at bottom with a valid front matter --- $file = str_replace('...', '---', $file); // additionally, Jekyll doesn't like dates as string, so fix $file = str_replace('"' . $_POST['date'] . '"', $_POST['date'], $file); $file = str_replace('"' . $updated_date . '"', $updated_date, $file); return $file . $_POST['content']; }
public function write() { $output = PKWK_YAMLCONFIG_HEAD . yaml_emit($this->getArrayCopy()) . PKWK_YAMLCONFIG_TAIL; $source = get_source($this->page, TRUE, TRUE); $source = $source != FALSE && preg_match(PKWK_YAMLCONFIG_PATTERN, $source) ? preg_replace(PKWK_YAMLCONFIG_PATTERN, $output, $source) : $output; page_write($this->page, $source); return $source; }
/** * write yaml to file * * @param string $path * @param mixed $data */ function run($path, $data) { if (extension_loaded('yaml')) { $this->logAction('yaml', $path); Helper::put($path, yaml_emit($data)); } else { $this->getLogger()->error('yaml extension not found.'); } }
/** * Write a config object to a YAML string. * * @param ObjectConfig $config * @return string|false Returns a YAML encoded string on success. False on failure. */ public function toString() { $result = false; if (function_exists('yaml_emit')) { $data = $this->toArray(); $result = yaml_emit($data, \YAML_UTF8_ENCODING); } return $result; }
public function onEnable() { @mkdir($this->getDataFolder()); if (!file_exists($this->getDataFolder() . "config.yml")) { file_put_contents($this->getDataFolder() . "config.yml", yaml_emit(array())); } $this->config = new Config($this->getDataFolder() . "config.yml", Config::YAML, ["Rules1" => "No right to Spam chatting!", "Rules2" => "No right to use mod", "Rules3" => "No right to contact admin to Give / Item", "Rules4" => "No right to Grief other players", "Rules5" => "No right to be rude in chat"]); $this->getLogger()->info(TextFormat::GREEN . "-SimpleRules Enabled!"); }
public function actionMSDS($args) { $cas_no = $args[0]; $msds = a('chemical/msds', ['cas_no' => $cas_no]); if (!$msds->id) { die("MSDS not found for {$cas_no}!\n"); } echo yaml_emit($msds->getData()['_extra'], YAML_UTF8_ENCODING); }
public function actionInfo($args) { $path = $args[0] ?: APP_ID; $info = \Gini\Core::moduleInfo($path); if ($info) { $info = (array) $info; unset($info['path']); echo yaml_emit($info); } }
public static function encode($data) { if (!$data) { return null; } $yaml = yaml_emit($data, YAML_UTF8_ENCODING, YAML_ANY_BREAK, ['mongo\\type\\DateTime' => 'self::bsonUnserialize', 'mongo\\type\\Timestamp' => 'self::bsonUnserialize', 'MongoDB\\BSON\\ObjectID' => 'self::bsonUnserialize', 'MongoDB\\BSON\\Binary' => 'self::bsonUnserialize', 'MongoDB\\BSON\\Javascript' => 'self::bsonUnserialize', 'MongoDB\\BSON\\Regex' => 'self::bsonUnserialize', 'MongoDB\\BSON\\MaxKey' => 'self::bsonUnserialize', 'MongoDB\\BSON\\MinKey' => 'self::bsonUnserialize']); $yaml = preg_replace('/^---/', '', $yaml); $yaml = preg_replace('/\\n\\.\\.\\.$/', '', $yaml); return $yaml; }
public function actionList($args) { $cron = (array) \Gini\Config::get('cron'); foreach ($cron as &$job) { if (!isset($job['schedule']) && $job['interval']) { $job['schedule'] = $job['interval']; unset($job['interval']); } } echo yaml_emit($cron, YAML_UTF8_ENCODING); }
/** * {@inheritdoc} */ public static function encode($data) { static $init; if (!isset($init)) { ini_set('yaml.output_indent', 2); // Do not break lines at 80 characters. ini_set('yaml.output_width', -1); $init = TRUE; } return yaml_emit($data, YAML_UTF8_ENCODING, YAML_LN_BREAK); }
/** * @param $player * @param $message */ public function saveStatus($player, $message) { @mkdir($this->getDataFolder()); file_put_contents($this->getDataFolder() . "WhatsUp/" . $player->getName() . ".yml", yaml_emit(["Status" => implode(" ", $message)])); if (!empty($message)) { $player->sendMessage(TXT::GREEN . "Successfully saved status as '" . implode(" ", $message) . "'."); } else { return; } return; }
public function test_serialization() { $path = realpath(dirname(__FILE__)) . '/../../configuration/defaults.yml'; $data = yaml_parse(file_get_contents($path)); $serialized = yaml_emit($data); $serialized2 = $this->_core->configuration->serialize($data); if ($serialized === $serialized2) { $this->assertTrue(true); } else { $this->assertTrue(false); } }
function store_data() { global $privateconfig; if (isset($privateconfig["paths"]["errorlog"])) { $path = $privateconfig["paths"]["errorlog"]; $handle = fopen($path, "a"); $date = date(DATE_RFC2822); $a = array("date" => $date, "HTTP_REFERER" => $_SERVER["HTTP_REFERER"], "HTTP_ACCEPT_LANGUAGE" => $_SERVER["HTTP_ACCEPT_LANGUAGE"], "HTTP_USER_AGENT" => $_SERVER["HTTP_USER_AGENT"], "HTTP_ACCEPT_ENCODING" => $_SERVER["HTTP_ACCEPT_ENCODING"], "REMOTE_ADDR" => $_SERVER["REMOTE_ADDR"], "_REQUEST" => $_REQUEST); $buffer = yaml_emit($a, YAML_UTF8_ENCODING); fwrite($handle, $buffer); fclose($handle); } }
/** * Convert an array into a YAML string. * * @param array $array The data to convert * * @return string The converted YAML */ public static function convert(array $array) { if (function_exists('yaml_emit')) { $yaml = yaml_emit($array); // PHP-Yaml adds strange separators to the outputted YAML, we do // some manipulation of the outputted string to remove these. $yaml = explode("\n", $yaml); array_shift($yaml); array_pop($yaml); array_pop($yaml); return implode("\n", $yaml); } return spyc_dump($array); }
function chunk_of_results($title, $json) { global $mirrorconfig; global $privateconfig; $r = json_decode($json, true); $n = array(); $n["tests"] = array(); foreach ($r["tests"] as $key => $array) { $n["tests"][$key] = $array["status"] . " " . sprintf('%.03f', $array["time_ms"] / 1000.0); } $n["tokens"] = $r["tokens"]; $y = yaml_emit($n); return chunk_of_text($title, $y, 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); } } }
public function exec() { try { /* check installed module */ if (false === isInstalled($this->parm)) { /* target module is already installed */ throw new \err\ComErr('specified module is not installed', 'please check \'spac mod list\''); } /* confirm */ echo 'Uninstall ' . $this->parm . ' module.' . PHP_EOL; echo 'Are you sure ?(y,n):'; $line = rtrim(fgets(STDIN), "\n"); if (!(0 === strcmp($line, 'y') || 0 === strcmp($line, 'Y'))) { exit; } /* delete module files */ if (true === isDirExists(__DIR__ . '/../../mod/' . $this->parm)) { try { delDir(__DIR__ . '/../../mod/' . $this->parm); } catch (\Exception $e) { throw new \err\ComErr('could not delete ' . __DIR__ . '/../../mod/' . $this->parm, 'please check directory'); } } /* edit module config */ $modcnf = yaml_parse_file(__DIR__ . '/../../../../conf/module.yml'); if (false === $modcnf) { throw new \err\ComErr('could not read module config file', 'please check ' . __DIR__ . '/../../../../conf/module.yml'); } $newcnf = array(); foreach ($modcnf as $elm) { if (0 === strcmp($this->parm, $elm['name'])) { continue; } $newcnf[] = $elm; } if (0 === count($newcnf)) { $newcnf = null; } if (false === copy(__DIR__ . '/../../../../conf/module.yml', __DIR__ . '/../../../../conf/module.yml_')) { throw new \err\ComErr('could not create backup of module config', 'please check ' . __DIR__ . '/../../../../conf'); } if (false === file_put_contents(__DIR__ . '/../../../../conf/module.yml', yaml_emit($newcnf))) { throw new \err\ComErr('could not edit module config file', 'please check ' . __DIR__ . '/../../../../conf/module.yml'); } unlink(__DIR__ . '/../../../../conf/module.yml_'); echo 'Successful uninstall ' . $this->parm . ' module ' . PHP_EOL; } catch (\Exception $e) { throw $e; } }
public function actionExport($args) { $opt = \Gini\Util::getOpt($args, 'h', ['help', 'json', 'yaml']); if (isset($opt['h']) || isset($opt['help'])) { echo "Usage: gini config export [-h|--help] [--json|--yaml]\n"; return; } \Gini\Config::setup(); $items = \Gini\Config::export(); if (isset($opt['json'])) { echo J($items, JSON_PRETTY_PRINT) . "\n"; } else { echo yaml_emit($items, YAML_UTF8_ENCODING); } }
public function adaptableOutput($data) { if (isset($_REQUEST['callback'])) { $cb = preg_replace("/[^][.\\'\\\"_A-Za-z0-9]/", '', $_GET['callback']); self::send_js_headers(); print sprintf('%s(%s);', $cb, json_encode($data)); exit(0); } if (isset($_REQUEST['format']) && $_REQUEST['format'] == 'xml') { self::send_xml_headers(); require_once 'XML/Serializer.php'; $serializer_options = array('addDecl' => TRUE, 'encoding' => 'UTF-8', 'indent' => ' ', 'rootName' => 'quantum', 'mode' => 'simplexml'); $Serializer = new \XML_Serializer($serializer_options); $status = $Serializer->serialize($data); if (\PEAR::isError($status)) { die($status->getMessage()); } echo $Serializer->getSerializedData(); exit(0); } if (isset($_REQUEST['format']) && $_REQUEST['format'] == 'serialized') { self::send_text_headers(); echo serialize($data); exit(0); } if (isset($_REQUEST['format']) && $_REQUEST['format'] == 'text') { self::send_text_headers(); echo print_r($data); exit(0); } if (isset($_REQUEST['format']) && $_REQUEST['format'] == 'yaml') { self::send_text_headers(); $yaml = yaml_emit($data); echo $yaml; exit(0); } if (isset($_REQUEST['format']) && $_REQUEST['format'] == 'dbug') { self::send_text_headers(); echo var_dump($data); exit(0); } self::send_json_headers(); echo json_encode($data); exit(0); }
public function updateYml($client = null, $data = null) { $this->isYmlExtensionLoaded(); if ($client === null) { throw new \Exception("Client Number not found."); } if (!is_array($data)) { throw new \Exception("Data must be array."); } $yamlParse = yaml_parse(file_get_contents($this->ymlFile)); $key = key($data); $value = $data[$key]; if (!isset($data[$this->prefix][$client])) { $yamlParse[$this->prefix][$client][$key] = $value; } copy($this->ymlFile, $this->backupFolder); file_put_contents($this->ymlFile, yaml_emit($yamlParse)); }
public function actionRequest($args) { if (count($args) < 1) { die("Usage: gini cgi request <URL>\n"); } $route = array_shift($args); array_map(function ($arg) { list($k, $v) = explode('=', $arg); $_GET[$k] = $v; }, $args); $env = ['get' => $_GET, 'post' => $_POST, 'files' => $_FILES, 'route' => $route]; echo "Requesting {$route}...\n"; $content = \Gini\CGI::request($route, $env)->execute()->content(); if (is_string($content)) { echo $content; } else { echo yaml_emit($content, YAML_UTF8_ENCODING); } }
public function exec() { try { /* check specified directory */ chkRequireConts($this->getPrm()); $desc = yaml_parse_file($this->getPrm() . 'conf/desc.yml'); if (false === $desc) { throw new \err\ComErr('could not read module description file', 'please check ' . $tgt . 'conf/desc.yml'); } /* check installed module */ if (true === isInstalled($desc['name'])) { /* target module is already installed */ throw new \err\ComErr('specified module is already installed', 'please check \'spac mod list\''); } /* copy module contents */ copyDir($this->getPrm(), __DIR__ . '/../../mod/' . $desc['name']); /* add module name to module config file */ $modcnf = yaml_parse_file(__DIR__ . '/../../../../conf/module.yml'); $first = false; if (null === $modcnf) { $first = true; $modcnf = array(); } $add = array('name' => $desc['name'], 'select' => false); if (true === $first) { $add['select'] = true; } $modcnf[] = $add; if (false === copy(__DIR__ . '/../../../../conf/module.yml', __DIR__ . '/../../../../conf/module.yml_')) { throw new \err\ComErr('could not create backup of module config', 'please check ' . __DIR__ . '/../../../../conf'); } if (false === file_put_contents(__DIR__ . '/../../../../conf/module.yml', yaml_emit($modcnf))) { throw new \err\ComErr('could not edit module config file', 'please check ' . __DIR__ . '/../../../../conf/module.yml'); } unlink(__DIR__ . '/../../../../conf/module.yml_'); echo 'Successful install ' . $desc['name'] . ' module' . PHP_EOL; echo 'You can check installed module \'spac mod list\',' . PHP_EOL; } catch (\Exception $e) { throw $e; } }