本文整理汇总了PHP中YAML类的典型用法代码示例。如果您正苦于以下问题:PHP YAML类的具体用法?PHP YAML怎么用?PHP YAML使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了YAML类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDecoding
public function testDecoding()
{
$formatter = new YAML();
$data = array('name' => 'Joe', 'age' => 21, 'employed' => true);
$raw = file_get_contents(__DIR__ . '/fixtures/joe.yaml');
$this->assertEquals($data, $formatter->decode($raw));
}
示例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: fetch
/**
* Fetch an L10n content string
*
* @param $key string YAML key of the desired text string
* @param $language string Optionally override the desired language
* @return mixed
*/
public static function fetch($key, $language = null, $lower = false)
{
$app = \Slim\Slim::getInstance();
$language = $language ? $language : Config::getCurrentLanguage();
$value = $key;
/*
|--------------------------------------------------------------------------
| Check for new language
|--------------------------------------------------------------------------
|
| English is loaded by default. If requesting a language not already
| cached, go grab it.
|
*/
if (!isset($app->config['_translations'][$language])) {
$app->config['_translations'][$language] = YAML::parse(Config::getTranslation($language));
}
/*
|--------------------------------------------------------------------------
| Resolve translation
|--------------------------------------------------------------------------
|
| If the set language is found and the key exists, return it. Falls back to
| English, and then falls back to the slug-style key itself.
|
*/
if (array_get($app->config['_translations'][$language]['translations'], $value, false)) {
$value = array_get($app->config['_translations'][$language]['translations'], $value);
} else {
$value = array_get($app->config['_translations']['en']['translations'], $value, $value);
}
return $lower ? strtolower($value) : $value;
}
示例4: 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>");
}
示例5: __construct
/**
* Singleton pattern.
*
* @throws Exceptions\DatacashRequestException
*/
protected function __construct()
{
// Get the default configurations.
$env_config = YAML::parse(file_get_contents(__DIR__ . "/../../config/environment.yaml"));
$datacash_config = YAML::parse(file_get_contents(__DIR__ . "/../../config/datacash.yaml"));
$datacash_config = $datacash_config[$env_config['environment']]['parameters'];
// Set the configurations for the request.
if (!empty($datacash_config['server_url'])) {
$this->hostName = $datacash_config['server_url'];
} else {
throw new DatacashRequestException("Not set or invalid hostname.");
}
if (!empty($datacash_config['timeout'])) {
$this->timeout = $datacash_config['timeout'];
}
if (!empty($datacash_config['datacash_network_ssl_path'])) {
$this->sslCertPath = $datacash_config['datacash_network_ssl_path'];
// Do not set cert SSL verifiation if we don't have a certificate.
if (!empty($datacash_config['datacash_network_ssl_verify'])) {
$this->sslVerify = $datacash_config['datacash_network_ssl_verify'];
}
} else {
$this->sslVerify = FALSE;
}
// Use proxy only if proxy url is available.
if (!empty($datacash_config['proxy_url'])) {
$this->proxyUrl = $datacash_config['proxy_url'];
}
}
示例6: 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";
}
示例7: getRedirectUrl
/**
* Get datacash redirect URL for payment page.
*
* @return string
*/
public function getRedirectUrl()
{
// Get the default configurations.
$env_config = YAML::parse(file_get_contents(__DIR__ . "/../../config/environment.yaml"));
$datacash_config = YAML::parse(file_get_contents(__DIR__ . "/../../config/datacash.yaml"));
$datacash_config = $datacash_config[$env_config['environment']]['parameters'];
return $datacash_config['redirect_url'] . $this->HpsTxn->session_id->getValue();
}
示例8: set
/**
* Sets the current environment to the given $environment
*
* @param string $environment Environment to set
* @param array $config Config to set to
* @return void
*/
public static function set($environment, &$config)
{
$config['environment'] = $environment;
$config['is_' . $environment] = true;
$environment_config = YAML::parse("_config/environments/{$environment}.yaml");
if (is_array($environment_config)) {
$config = array_merge($config, $environment_config);
}
}
示例9: set
/**
* Sets the current environment to the given $environment
*
* @param string $environment Environment to set
* @return void
*/
public static function set($environment)
{
$app = \Slim\Slim::getInstance();
$app->config['environment'] = $environment;
$app->config['is_' . $environment] = TRUE;
$environment_config = YAML::parse("_config/environments/{$environment}.yaml");
if (is_array($environment_config)) {
$app->config = array_merge($app->config, $environment_config);
}
}
示例10: fetch_fieldset
public static function fetch_fieldset($fieldset)
{
$defaults = array('fields' => array());
if (File::exists("_config/fieldsets/{$fieldset}.yaml")) {
$meta_raw = file_get_contents("_config/fieldsets/{$fieldset}.yaml");
$meta = array_merge($defaults, YAML::Parse($meta_raw));
return $meta;
}
return $defaults;
}
示例11: fetch
public static function fetch($form_name)
{
$filename = dirname(__DIR__) . '/forms/' . $form_name . '.yaml';
if (file_exists($filename)) {
return YAML::parse(file_get_contents($filename));
} else {
$error = 'missing form: ' . $filename;
throw new Exception($error);
}
}
示例12: generate_schema
function generate_schema($model)
{
global $mysql;
$cols = array();
$result = mysql_query("DESCRIBE `{$model}`") or die("Error in query: {$sql} \n" . mysql_error() . "\n");
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$cols[$row['Field']] = $row;
}
$yaml = YAML::encode($cols);
$comments = "# This file is auto-generated by script/generate_schema \n# Do not edit or you'll ruin Christmas!!\n\n";
file_put_contents("db/schemas/{$model}.yml", $comments . $yaml);
}
示例13: convertYAML
/**
* Parse YAML data into an array
* @param {String} the text to be parsed
*
* @return {Array} the parsed content
*/
public static function convertYAML($text)
{
try {
$yaml = YAML::parse($text);
} catch (ParseException $e) {
printf("unable to parse documentation: %s..\n", $e->getMessage());
}
// single line of text won't throw a YAML error. returns as string
if (gettype($yaml) == "string") {
$yaml = array();
}
return $yaml;
}
示例14: __construct
/**
* Function: __construct
* Loads the Twig parser into <Theme>, and sets up the theme l10n domain.
*/
private function __construct()
{
$config = Config::current();
# Load the theme translator
if (file_exists(THEME_DIR . "/locale/" . $config->locale . ".mo")) {
load_translator("theme", THEME_DIR . "/locale/" . $config->locale . ".mo");
}
# Load the theme's info into the Theme class.
foreach (YAML::load(THEME_DIR . "/info.yaml") as $key => $val) {
$this->{$key} = $val;
}
$this->url = THEME_URL;
}
示例15: load
public static function load($config_dir)
{
$config_file = $config_dir . '/elib.yml';
if (!file_exists($config_file)) {
die('Config error: ' . $config_file . ' does not exist');
}
$config = YAML::load($config_file);
foreach ($config as $index => $item) {
if (!is_array($item)) {
$index = 'ELIB_' . $index;
define(strtoupper($index), $item);
}
}
}