本文整理汇总了PHP中YAML::dump方法的典型用法代码示例。如果您正苦于以下问题:PHP YAML::dump方法的具体用法?PHP YAML::dump怎么用?PHP YAML::dump使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类YAML
的用法示例。
在下文中一共展示了YAML::dump方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: go
public function go()
{
//$feed = file_get_contents($_SERVER['DOCUMENT_ROOT'].'/_add-ons/wordpress/wp_posts.xml');
//$items = simplexml_load_string($feed);
$posts_object = simplexml_load_file($_SERVER['DOCUMENT_ROOT'] . '/_add-ons/wordpress/roobottom_old_posts.xml');
$posts = object_to_array($posts_object);
$yaml_path = $_SERVER['DOCUMENT_ROOT'] . '/_content/01-blog/';
foreach ($posts['table'] as $post) {
if ($post['column'][8] == "publish") {
$slug = Slug::make($post['column'][5]);
$slug = preg_replace('/[^a-z\\d]+/i', '-', $slug);
if (substr($slug, -1) == '-') {
$slug = substr($slug, 0, -1);
}
$date = date('Y-m-d-Hi', strtotime($post['column'][3]));
$file = $date . "-" . $slug . ".md";
if (!File::exists($yaml_path . $file)) {
$yaml = [];
$yaml['title'] = $post['column'][5];
$content = $post['column'][4];
$markdown = new HTML_To_Markdown($content, array('header_style' => 'atx'));
File::put($yaml_path . $file, YAML::dump($yaml) . '---' . "\n" . $markdown);
}
echo $slug . "-" . $date;
echo "<br/><hr/><br/>";
}
}
return "ok";
}
示例2: control_panel__add_routes
public function control_panel__add_routes()
{
$app = \Slim\Slim::getInstance();
$app->get('/globes', function () use($app) {
authenticateForRole('admin');
doStatamicVersionCheck($app);
Statamic_View::set_templates(array('globes-overview'), __DIR__ . '/templates');
$data = $this->tasks->getThemeSettings();
$app->render(null, array('route' => 'globes', 'app' => $app) + $data);
})->name('globes');
// Update global vars
$app->post('/globes/update', function () use($app) {
authenticateForRole('admin');
doStatamicVersionCheck($app);
$data = $this->tasks->getThemeSettings();
$vars = Request::fetch('pageglobals');
foreach ($vars as $name => $var) {
foreach ($data['globals'] as $key => $item) {
if ($item['name'] === $name) {
$data['globals'][$key]['value'] = $var;
}
}
}
File::put($this->tasks->getThemeSettingsPath(), YAML::dump($data, 1));
$app->flash('success', Localization::fetch('update_success'));
$app->redirect($app->urlFor('globes'));
});
}
示例3: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$method = $input->getOption('method');
switch ($method) {
case 'drush':
$alias = $input->getOption('alias');
if (empty($alias)) {
throw new RuntimeException("You must supply a valid Drush alias using the --alias argument.");
}
if ($alias[0] != '@') {
throw new RuntimeException("Invalid alias \"{$alas}\".");
}
$config = array('fetch-method' => $method, 'fetch-alias' => $alias);
break;
case 'dump-n-config':
$config = array('fetch-method' => $method, 'fetch-dumpfile' => $input->getOption('dumpfile'), 'fetch-staging' => $input->getOption('staging'));
break;
default:
throw new RuntimeException("Unknown fetching method \"{$method}\".");
}
$fileName = 'tests/proctor/drupal.yml';
$dirName = dirname($fileName);
if (!file_exists($dirName) && !mkdir($dirName, 0777, true)) {
throw new RuntimeException("Could not create {$dirName}", 1);
}
$config = YAML::dump($config);
if (file_put_contents($fileName, $config) === false) {
throw new RuntimeException("Could not write {$fileName}", 1);
}
$output->writeln("<info>Wrote " . $fileName . "</info>");
}
示例4: export
//.........这里部分代码省略.........
foreach ($post->attributes as $key => $val) {
$posts_atom .= ' <' . $key . '>' . fix($val) . '</' . $key . '>' . "\r";
}
$posts_atom .= ' </content>' . "\r";
foreach (array("feather", "clean", "url", "pinned", "status") as $attr) {
$posts_atom .= ' <chyrp:' . $attr . '>' . fix($post->{$attr}) . '</chyrp:' . $attr . '>' . "\r";
}
$trigger->filter($posts_atom, "posts_export", $post);
$posts_atom .= ' </entry>' . "\r";
}
$posts_atom .= '</feed>' . "\r";
$exports["posts.atom"] = $posts_atom;
}
if (isset($_POST['pages'])) {
list($where, $params) = keywords($_POST['filter_pages'], "title LIKE :query OR body LIKE :query", "pages");
$pages = Page::find(array("where" => $where, "params" => $params, "order" => "id ASC"), array("filter" => false));
$latest_timestamp = 0;
foreach ($pages as $page) {
if (strtotime($page->created_at) > $latest_timestamp) {
$latest_timestamp = strtotime($page->created_at);
}
}
$pages_atom = '<?xml version="1.0" encoding="utf-8"?>' . "\r";
$pages_atom .= '<feed xmlns="http://www.w3.org/2005/Atom" xmlns:chyrp="http://chyrp.net/export/1.0/">' . "\r";
$pages_atom .= ' <title>' . fix($config->name) . ' Pages</title>' . "\r";
$pages_atom .= ' <subtitle>' . fix($config->description) . '</subtitle>' . "\r";
$pages_atom .= ' <id>tag:' . parse_url($config->url, PHP_URL_HOST) . ',' . date("Y", $latest_timestamp) . ':Chyrp</id>' . "\r";
$pages_atom .= ' <updated>' . date("c", $latest_timestamp) . '</updated>' . "\r";
$pages_atom .= ' <link href="' . $config->url . '" rel="self" type="application/atom+xml" />' . "\r";
$pages_atom .= ' <generator uri="http://chyrp.net/" version="' . CHYRP_VERSION . '">Chyrp</generator>' . "\r";
foreach ($pages as $page) {
$updated = $page->updated ? $page->updated_at : $page->created_at;
$tagged = substr(strstr($page->url(), "//"), 2);
$tagged = str_replace("#", "/", $tagged);
$tagged = preg_replace("/(" . preg_quote(parse_url($page->url(), PHP_URL_HOST)) . ")/", "\\1," . when("Y-m-d", $updated) . ":", $tagged, 1);
$url = $page->url();
$pages_atom .= ' <entry xml:base="' . fix($url) . '" chyrp:parent_id="' . $page->parent_id . '">' . "\r";
$pages_atom .= ' <title type="html">' . fix($page->title) . '</title>' . "\r";
$pages_atom .= ' <id>tag:' . $tagged . '</id>' . "\r";
$pages_atom .= ' <updated>' . when("c", $updated) . '</updated>' . "\r";
$pages_atom .= ' <published>' . when("c", $page->created_at) . '</published>' . "\r";
$pages_atom .= ' <link href="' . fix($trigger->filter($url, "page_export_url", $page)) . '" />' . "\r";
$pages_atom .= ' <author chyrp:user_id="' . fix($page->user_id) . '">' . "\r";
$pages_atom .= ' <name>' . fix(oneof($page->user->full_name, $page->user->login)) . '</name>' . "\r";
if (!empty($page->user->website)) {
$pages_atom .= ' <uri>' . fix($page->user->website) . '</uri>' . "\r";
}
$pages_atom .= ' <chyrp:login>' . fix($page->user->login) . '</chyrp:login>' . "\r";
$pages_atom .= ' </author>' . "\r";
$pages_atom .= ' <content type="html">' . fix($page->body) . '</content>' . "\r";
foreach (array("show_in_list", "list_order", "clean", "url") as $attr) {
$pages_atom .= ' <chyrp:' . $attr . '>' . fix($page->{$attr}) . '</chyrp:' . $attr . '>' . "\r";
}
$trigger->filter($pages_atom, "pages_export", $page);
$pages_atom .= ' </entry>' . "\r";
}
$pages_atom .= '</feed>' . "\r";
$exports["pages.atom"] = $pages_atom;
}
if (isset($_POST['groups'])) {
list($where, $params) = keywords($_POST['filter_groups'], "name LIKE :query", "groups");
$groups = Group::find(array("where" => $where, "params" => $params, "order" => "id ASC"));
$groups_yaml = array("groups" => array(), "permissions" => array());
foreach (SQL::current()->select("permissions", "*", array("group_id" => 0))->fetchAll() as $permission) {
$groups_yaml["permissions"][$permission["id"]] = $permission["name"];
}
foreach ($groups as $index => $group) {
$groups_yaml["groups"][$group->name] = $group->permissions;
}
$exports["groups.yaml"] = YAML::dump($groups_yaml);
}
if (isset($_POST['users'])) {
list($where, $params) = keywords($_POST['filter_users'], "login LIKE :query OR full_name LIKE :query OR email LIKE :query OR website LIKE :query", "users");
$users = User::find(array("where" => $where, "params" => $params, "order" => "id ASC"));
$users_yaml = array();
foreach ($users as $user) {
$users_yaml[$user->login] = array();
foreach ($user as $name => $attr) {
if (!in_array($name, array("no_results", "group_id", "group", "id", "login", "belongs_to", "has_many", "has_one", "queryString"))) {
$users_yaml[$user->login][$name] = $attr;
} elseif ($name == "group_id") {
$users_yaml[$user->login]["group"] = $user->group->name;
}
}
}
$exports["users.yaml"] = YAML::dump($users_yaml);
}
$trigger->filter($exports, "export");
require INCLUDES_DIR . "/lib/zip.php";
$zip = new ZipFile();
foreach ($exports as $filename => $content) {
$zip->addFile($content, $filename);
}
$zip_contents = $zip->file();
$filename = sanitize(camelize($config->name), false, true) . "_Export_" . date("Y-m-d");
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"" . $filename . ".zip\"");
header("Content-length: " . strlen($zip_contents) . "\n\n");
echo $zip_contents;
}
示例5: remove
/**
* Function: remove
* Removes a configuration setting.
*
* Parameters:
* $setting - The name of the setting to remove.
*/
public function remove($setting)
{
if (isset($this->file) and file_exists($this->file)) {
$contents = str_replace("<?php header(\"Status: 403\"); exit(\"Access denied.\"); ?>\n", "", file_get_contents($this->file));
$this->yaml = YAML::load($contents);
}
# Add the setting
unset($this->yaml[$setting]);
# Add the PHP protection!
$contents = "<?php header(\"Status: 403\"); exit(\"Access denied.\"); ?>\n";
# Generate the new YAML settings
$contents .= YAML::dump($this->yaml);
file_put_contents(INCLUDES_DIR . "/config.yaml.php", $contents);
}
示例6: to_yaml
/**
* Encode data as YAML and return YAML text
*
* @param Array/Object $data the data to encode
* @return String the encoded data as YAML text
*/
public static function to_yaml($data)
{
load_tool('YAML');
return YAML::dump(object_to_array($data));
}
示例7: ajax_tag_post
public function ajax_tag_post()
{
if (empty($_POST['name']) or empty($_POST['post'])) {
exit("{}");
}
$sql = SQL::current();
$post = new Post($_POST['post']);
$tag = $_POST['name'];
if (!$post->editable()) {
exit("{}");
}
$tags = $sql->select("post_attributes", "value", array("name" => "tags", "post_id" => $post->id));
if ($tags and $value = $tags->fetchColumn()) {
$tags = YAML::load($value);
} else {
$tags = array();
}
$tags[$tag] = sanitize($tag);
$sql->replace("post_attributes", array("post_id", "name"), array("name" => "tags", "value" => YAML::dump($tags), "post_id" => $post->id));
exit("{ url: \"" . url("tag/" . $tags[$tag], MainController::current()) . "\", tag: \"" . $_POST['name'] . "\" }");
}
示例8: header
<?php
header('Content-Type: text/plain');
load_tool('YAML');
// Get the data to encode into YAML
if (!isset($data)) {
$data = array();
}
// Now for our elegant YAML encoding
echo YAML::dump($data);
示例9: admin_edit_aggregate
public function admin_edit_aggregate($admin)
{
if (empty($_GET['id'])) {
error(__("No ID Specified"), __("An ID is required to delete an aggregate.", "aggregator"));
}
if (!Visitor::current()->group->can("edit_aggregate")) {
show_403(__("Access Denied"), __("You do not have sufficient privileges to delete this aggregate.", "aggregator"));
}
$admin->context["users"] = User::find();
$config = Config::current();
$aggregate = $config->aggregates[$_GET['id']];
if (empty($_POST)) {
return $admin->display("edit_aggregate", array("users" => User::find(), "aggregate" => array("name" => $_GET['id'], "url" => $aggregate["url"], "feather" => $aggregate["feather"], "author" => $aggregate["author"], "data" => preg_replace("/---\n/", "", YAML::dump($aggregate["data"])))));
}
if (!isset($_POST['hash']) or $_POST['hash'] != Config::current()->secure_hashkey) {
show_403(__("Access Denied"), __("Invalid security key."));
}
$aggregate = array("url" => $_POST['url'], "last_updated" => 0, "feather" => $_POST['feather'], "author" => $_POST['author'], "data" => YAML::load($_POST['data']));
unset($config->aggregates[$_GET['id']]);
$config->aggregates[$_POST['name']] = $aggregate;
$config->set("aggregates", $config->aggregates);
$config->set("last_aggregation", 0);
// to force a refresh
Flash::notice(__("Aggregate updated.", "aggregator"), "/admin/?action=manage_aggregates");
}
示例10: putYAML
/**
* Parses the given $content array and puts a file to this plugin's namespaced storage
*
* @param string $filename Name of file to put
* @param array $content Array to parse and write to file
* @return void
*/
public function putYAML($filename, Array $content)
{
$this->verifyStorageFolder();
$this->put($filename, YAML::dump($content));
}
示例11: buildContent
/**
* Builds a file with YAML front-matter
*
* @param array $data Front-matter data
* @param string $content Content
* @return string
*/
public static function buildContent(array $data, $content)
{
$file_content = "---\n";
$file_content .= preg_replace('/\\A^---\\s/ism', "", YAML::dump($data));
$file_content .= "---\n";
$file_content .= $content;
return $file_content;
}
示例12: putYAML
/**
* Parses the given $content array and puts a file to this plugin's namespaced cache
*
* @param string $filename Name of file to put
* @param array $content Array to parse and write to file
* @return int
*/
public function putYAML($filename, array $content)
{
return $this->put($filename, YAML::dump($content));
}
示例13: createPhotoCollection
public function createPhotoCollection()
{
$yaml_path = $_SERVER['DOCUMENT_ROOT'] . '/_content/photos/';
$files = glob($yaml_path . '*.{md,collection}', GLOB_BRACE);
$arr_files = [];
//put each file into an array
foreach ($files as $file) {
if (basename($file) != "page.md") {
$temp = array('date' => substr(basename($file), 0, 10), 'time' => substr(basename($file), 11, 4), 'hour' => substr(basename($file), 11, 2), 'file' => basename($file));
$arr_files[] = $temp;
}
}
//now split these into more arrays, grouped by date.
//this is where we're loosing a file
$last_date = $arr_files[0]['date'];
$arr_groups = [];
$i = 0;
foreach ($arr_files as $file) {
if ($last_date != $file['date']) {
$i++;
}
$arr_groups[$i][] = $file;
$last_date = $file['date'];
}
reset($arr_groups);
//now further split this into similar times (+ or - 2 hours of eachother)
$last_time = $arr_groups[0][0]['hour'];
foreach ($arr_groups as $group) {
if (count($group) > 1) {
$last_time = $group[0]['hour'];
foreach ($group as $item) {
$max = $last_time + 2;
$min = $last_time - 2;
if ($min < $item['hour'] && $item['hour'] > $max) {
$i++;
}
$time_groups[$i][] = $item;
$last_time = $item['hour'];
}
$i++;
}
}
//now write out these groups into new YAML files.
foreach ($time_groups as $times) {
$YAML_arr = [];
$images_arr = [];
$i = 0;
if (count($times) > 1) {
foreach ($times as $item) {
//convert this array into the -images part of the YAML
$images_arr[] = YAML::parseFile($yaml_path . $item['file']);
$i++;
}
$YAML_arr['title'] = $images_arr[0]['title'];
$YAML_arr['cover'] = $images_arr[0]['image'];
$YAML_arr['first_time'] = $times[0]['time'];
$YAML_arr['last_time'] = $times[$i - 1]['time'];
$YAML_arr['images'] = $images_arr;
$slug = Slug::make($images_arr[0]['flickr_id']);
$file = $times[0]['date'] . "-" . $times[0]['time'] . "-" . $slug . ".md";
if (!File::exists($yaml_path . "collections/" . $file)) {
File::put($yaml_path . "collections/" . $file, YAML::dump($YAML_arr) . '---' . "\n");
foreach ($times as $item) {
$arhive_file = $archive_file = preg_replace('"\\.md$"', '.collection', $item['file']);
if (File::exists($yaml_path . $item['file'])) {
rename($yaml_path . $item['file'], $yaml_path . $archive_file);
}
}
}
}
}
return true;
}
示例14: update
/**
* Function: update
* Updates the version.
*
* Parameters:
* $title - The new title.
* $description - The new description.
*/
public function update($number = null, $description = null, $compatible = null, $tags = null, $filename = null, $image = null, $loves = null, $downloads = null, $extension = null, $created_at = null, $updated_at = null)
{
if ($this->no_results) {
return false;
}
$sql = SQL::current();
$trigger = Trigger::current();
$old = clone $this;
if (is_array($tags)) {
$tags = array_map("strip_tags", $tags);
$compatible = array_map("strip_tags", $compatible);
$tags = array_combine($tags, array_map("sanitize", $tags));
}
foreach (array("number", "description", "compatible", "tags", "filename", "image", "loves", "downloads", "extension_id", "created_at", "updated_at") as $attr) {
if (substr($attr, -3) == "_id") {
$arg = ${substr($attr, 0, -3)};
$this->{$attr} = ${$attr} = oneof($arg instanceof Model ? $arg->id : $arg, $this->{$attr});
} elseif ($attr == "updated_at") {
if (${$attr} === null) {
$this->{$attr} = ${$attr} = datetime();
} elseif (${$attr} === false) {
$this->{$attr} = ${$attr} = $this->{$attr};
} else {
$this->{$attr} = ${$attr};
}
} else {
$this->{$attr} = ${$attr} = ${$attr} !== null ? ${$attr} : $this->{$attr};
}
}
$sql->update("versions", array("id" => $this->id), array("number" => $number, "description" => $description, "compatible" => is_array($compatible) ? YAML::dump($compatible) : $compatible, "tags" => is_array($tags) ? YAML::dump($tags) : $tags, "filename" => $filename, "image" => $image, "loves" => $loves, "downloads" => $downloads, "extension_id" => $extension_id, "created_at" => $created_at, "updated_at" => $updated_at));
$trigger->call("update_version", $this, $old);
if (module_enabled("cacher")) {
Modules::$instances["cacher"]->regenerate();
}
}
示例15: buildContent
/**
* Builds a file with YAML front-matter
*
* @param array $data Front-matter data
* @param string $content Content
* @return string
*/
public static function buildContent(array $data, $content)
{
Debug::increment('content', 'files_built');
$file_content = "---\n";
$file_content .= preg_replace('/\\A^---\\s/ism', "", YAML::dump($data));
$file_content .= "---\n";
$file_content .= $content;
return $file_content;
}