本文整理汇总了PHP中yaml_emit函数的典型用法代码示例。如果您正苦于以下问题:PHP yaml_emit函数的具体用法?PHP yaml_emit怎么用?PHP yaml_emit使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了yaml_emit函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: emitFile
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);
}
示例2: serialize
public function serialize()
{
if (!$this->object instanceof \Serializable) {
throw new \Exception('Object is not an instance of Serializable.');
}
return \yaml_emit($this->object->serialize());
}
示例3: encode
/**
* @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);
}
示例4: do_serialize
/**
* @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;
}
示例5: _sendContent
/**
* 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);
}
示例6: __invoke
public function __invoke($data)
{
set_error_handler($this->generateErrorHandler($data));
$parsed = yaml_emit($data);
restore_error_handler();
return $parsed;
}
示例7: to
/**
* {@inheritdoc}
*/
public function to(array $data, $comments = null)
{
if ($comments) {
return $comments . PHP_EOL . yaml_emit($data);
}
return yaml_emit($data);
}
示例8: exec
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;
}
}
示例9: buildFile
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'];
}
示例10: write
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;
}
示例11: run
/**
* 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.');
}
}
示例12: toString
/**
* 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;
}
示例13: onEnable
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!");
}
示例14: actionMSDS
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);
}
示例15: actionInfo
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);
}
}