• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP YAML类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了PHP中YAML的典型用法代码示例。如果您正苦于以下问题:PHP YAML类的具体用法?PHP YAML怎么用?PHP YAML使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了YAML类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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));
 }
开发者ID:gekt,项目名称:www,代码行数:7,代码来源:YAMLTest.php


示例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'));
     });
 }
开发者ID:QDigitalStudio,项目名称:statamic-globes,代码行数:28,代码来源:hooks.globes.php


示例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;
 }
开发者ID:nob,项目名称:joi,代码行数:40,代码来源:localization.php


示例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>");
 }
开发者ID:xendk,项目名称:proctor,代码行数:31,代码来源:SetupDrupal.php


示例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'];
     }
 }
开发者ID:abghosh82,项目名称:datacash_payment_library,代码行数:34,代码来源:SSLAgent.php


示例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";
 }
开发者ID:roobottom,项目名称:roobottom-statamic,代码行数:29,代码来源:pi.wordpress.php


示例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();
 }
开发者ID:abghosh82,项目名称:datacash_payment_library,代码行数:13,代码来源:Response.php


示例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);
     }
 }
开发者ID:andorpandor,项目名称:git-deploy.eu2.frbit.com-yr-prototype,代码行数:16,代码来源:_environment.php


示例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);
     }
 }
开发者ID:nob,项目名称:joi,代码行数:16,代码来源:environment.php


示例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;
 }
开发者ID:zane-insight,项目名称:WhiteLaceInn,代码行数:10,代码来源:fieldset.php


示例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);
     }
 }
开发者ID:stevenosloan,项目名称:acreage,代码行数:10,代码来源:boot.php


示例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);
}
开发者ID:phaedryx,项目名称:wannabe-mvc,代码行数:12,代码来源:schema.php


示例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;
 }
开发者ID:mytoysgroup,项目名称:patternlab-php-core,代码行数:19,代码来源:Documentation.php


示例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;
 }
开发者ID:eadz,项目名称:chyrp,代码行数:17,代码来源:Theme.php


示例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);
         }
     }
 }
开发者ID:mikejw,项目名称:elib-experimental,代码行数:14,代码来源:Config.php


示例16: getUserProfile

 /**
  * Returns a given user's profile
  * 
  * @param string  $username  Username's profile to return
  * @return array
  */
 public static function getUserProfile($username)
 {
     if (!UserAuth::isUser($username)) {
         return null;
     }
     $content = substr(File::get(Config::getConfigPath() . "/users/" . $username . ".yaml"), 3);
     $divide = strpos($content, "\n---");
     $front_matter = trim(substr($content, 0, $divide));
     $content_raw = trim(substr($content, $divide + 4));
     $profile = YAML::parse($front_matter);
     $profile['biography_raw'] = $content_raw;
     $profile['biography'] = Content::transform($content_raw);
     $profile['username'] = $username;
     return $profile;
 }
开发者ID:kwanpt,项目名称:kwan-website,代码行数:21,代码来源:userauth.php


示例17: testYAMLSerializer

 public function testYAMLSerializer()
 {
     $yaml_output = $this->debtAmortizatorFactory->getSerializedResult(new YAMLSerializer());
     $yamlObject = YAML::parse($yaml_output);
     // WE WILL TEST EACH AND EVERY PROPERTY OF THIS OBJECT
     // Debt principal
     $this->assertEquals("40000", $yamlObject["debtPrincipal"]);
     // Debt number of compounding periods
     $this->assertEquals("6", $yamlObject["debtNoOfCompoundingPeriods"]);
     // Debt length period
     $this->assertEquals("1", $yamlObject["debtPeriodLength"]["years"]);
     $this->assertEquals("12", $yamlObject["debtPeriodLength"]["months"]);
     $this->assertEquals("360", $yamlObject["debtPeriodLength"]["days"]);
     // Debt interest
     $this->assertEquals("0.12", $yamlObject["debtInterest"]);
     // Debt discount factor
     $this->assertEquals("0.89", $this->round2DP($yamlObject["debtDiscountFactor"]));
     // Debt duration
     $this->assertEquals("6", $yamlObject["debtDuration"]["years"]);
     $this->assertEquals("72", $yamlObject["debtDuration"]["months"]);
     $this->assertEquals("2160", $yamlObject["debtDuration"]["days"]);
     // Debt amount of single repayment
     $INDIVIDUAL_REPAYMENT = "9729.03";
     $this->assertEquals($INDIVIDUAL_REPAYMENT, $this->round2DP($yamlObject["debtSingleRepayment"]));
     // Debt repayments (principal part, interest part, total = principal part + interest part)
     $this->assertEquals("4929.03", $this->round2DP($yamlObject["debtRepayments"]["1"]["principalAmount"]));
     $this->assertEquals("4800.00", $this->round2DP($yamlObject["debtRepayments"]["1"]["interestAmount"]));
     $this->assertEquals($INDIVIDUAL_REPAYMENT, $this->round2DP($yamlObject["debtRepayments"]["1"]["totalAmount"]));
     $this->assertEquals("5520.51", $this->round2DP($yamlObject["debtRepayments"]["2"]["principalAmount"]));
     $this->assertEquals("4208.52", $this->round2DP($yamlObject["debtRepayments"]["2"]["interestAmount"]));
     $this->assertEquals($INDIVIDUAL_REPAYMENT, $this->round2DP($yamlObject["debtRepayments"]["2"]["totalAmount"]));
     $this->assertEquals("6182.97", $this->round2DP($yamlObject["debtRepayments"]["3"]["principalAmount"]));
     $this->assertEquals("3546.06", $this->round2DP($yamlObject["debtRepayments"]["3"]["interestAmount"]));
     $this->assertEquals($INDIVIDUAL_REPAYMENT, $this->round2DP($yamlObject["debtRepayments"]["3"]["totalAmount"]));
     $this->assertEquals("6924.93", $this->round2DP($yamlObject["debtRepayments"]["4"]["principalAmount"]));
     $this->assertEquals("2804.10", $this->round2DP($yamlObject["debtRepayments"]["4"]["interestAmount"]));
     $this->assertEquals($INDIVIDUAL_REPAYMENT, $this->round2DP($yamlObject["debtRepayments"]["4"]["totalAmount"]));
     $this->assertEquals("7755.92", $this->round2DP($yamlObject["debtRepayments"]["5"]["principalAmount"]));
     $this->assertEquals("1973.11", $this->round2DP($yamlObject["debtRepayments"]["5"]["interestAmount"]));
     $this->assertEquals($INDIVIDUAL_REPAYMENT, $this->round2DP($yamlObject["debtRepayments"]["5"]["totalAmount"]));
     $this->assertEquals("8686.63", $this->round2DP($yamlObject["debtRepayments"]["6"]["principalAmount"]));
     $this->assertEquals("1042.4", $this->round2DP($yamlObject["debtRepayments"]["6"]["interestAmount"]));
     $this->assertEquals($INDIVIDUAL_REPAYMENT, $this->round2DP($yamlObject["debtRepayments"]["6"]["totalAmount"]));
 }
开发者ID:uruba,项目名称:financalc-yamlserializer,代码行数:44,代码来源:YAMLSerializerTest.php


示例18: parse_manifest

 private function parse_manifest($package_path)
 {
     $package_path = preg_replace('/\\/$/', '', $package_path) . '/';
     $manifest = YAML::decode_file($package_path . 'package.yml');
     if (empty($manifest)) {
         throw new Exception("package.yml not found in {$package_path}, or unable to parse manifest.");
     }
     $package_name = $manifest['name'];
     if ($this->root == null) {
         $this->root = $package_name;
     }
     if (array_has($this->manifests, $package_name)) {
         return;
     }
     $manifest['path'] = $package_path;
     $this->manifests[$package_name] = $manifest;
     foreach ($manifest['sources'] as $i => $path) {
         $path = $package_path . $path;
         // this is where we "hook" for possible other replacers.
         $source = $this->replace_build($package_path, file_get_contents($path));
         $descriptor = array();
         // get contents of first comment
         preg_match('/^\\s*\\/\\*\\s*(.*?)\\s*\\*\\//s', $source, $matches);
         if (!empty($matches)) {
             // get contents of YAML front matter
             preg_match('/^-{3}\\s*$(.*?)^(?:-{3}|\\.{3})\\s*$/ms', $matches[1], $matches);
             if (!empty($matches)) {
                 $descriptor = YAML::decode($matches[1]);
             }
         }
         // populate / convert to array requires and provides
         $requires = (array) (!empty($descriptor['requires']) ? $descriptor['requires'] : array());
         $provides = (array) (!empty($descriptor['provides']) ? $descriptor['provides'] : array());
         $file_name = !empty($descriptor['name']) ? $descriptor['name'] : basename($path, '.js');
         // "normalization" for requires. Fills up the default package name from requires, if not present.
         foreach ($requires as $i => $require) {
             $requires[$i] = implode('/', $this->parse_name($package_name, $require));
         }
         $license = array_get($descriptor, 'license');
         $this->packages[$package_name][$file_name] = array_merge($descriptor, array('package' => $package_name, 'requires' => $requires, 'provides' => $provides, 'source' => $source, 'path' => $path, 'package/name' => $package_name . '/' . $file_name, 'license' => empty($license) ? array_get($manifest, 'license') : $license));
     }
 }
开发者ID:pizarrodiego,项目名称:packager,代码行数:42,代码来源:packager.php


示例19: load

 /**
  * Load a config file, and optionally force a file reload
  *
  * @param String $config_file the name of the config to load (excl ".yaml")
  * @param Boolean $reload whether to reload a file that's already loaded
  * @return Array the config data as an assoc array
  */
 public static function load($config_file = 'app', $reload = FALSE)
 {
     // Return a matching loaded config (unless reloading)
     if ($reload) {
         self::$configs[$config_file] = NULL;
     }
     if ($config = array_key(self::$configs, $config_file)) {
         return $config;
     }
     // Load a config file by looking in "app" and "yawf"
     $file = '/configs/' . $config_file . '.yaml';
     if (file_exists(Symbol::APP . $file)) {
         self::$configs[$config_file] = YAML::parse_file(Symbol::APP . $file);
     } elseif (file_exists(Symbol::YAWF . $file)) {
         self::$configs[$config_file] = YAML::parse_file(Symbol::YAWF . $file);
     } else {
         throw new Exception("Config file \"{$config_file}.yaml\" not found");
     }
     // Return the loaded config file as a PHP data array
     return self::$configs[$config_file];
 }
开发者ID:hutchike,项目名称:YAWF,代码行数:28,代码来源:Config.php


示例20: run

 public function run($depth, $ext, $path, $pathName, $name)
 {
     // load default vars
     $patternTypeDash = PatternData::getPatternTypeDash();
     // should this pattern get rendered?
     $hidden = $name[0] == "_";
     // set-up the names, $name == foo.json
     $pattern = str_replace("." . $ext, "", $name);
     // foo
     $patternDash = $this->getPatternName($pattern, false);
     // foo
     $patternPartial = $patternTypeDash . "-" . $patternDash;
     // atoms-foo
     if (!$hidden) {
         $patternStoreData = array("category" => "pattern");
         $file = file_get_contents(Config::getOption("patternSourceDir") . "/" . $pathName);
         if ($ext == "json") {
             $data = json_decode($file, true);
             if ($jsonErrorMessage = JSON::hasError()) {
                 JSON::lastErrorMsg($name, $jsonErrorMessage, $data);
             }
         } else {
             try {
                 $data = YAML::parse($file);
             } catch (ParseException $e) {
                 printf("unable to parse " . $pathNameClean . ": %s..\n", $e->getMessage());
             }
             // single line of text won't throw a YAML error. returns as string
             if (gettype($data) == "string") {
                 $data = array();
             }
         }
         $patternStoreData["data"] = $data;
         // create a key for the data store
         $patternStoreKey = $patternPartial;
         // if the pattern data store already exists make sure it is merged and overwrites this data
         $patternStoreData = PatternData::checkOption($patternStoreKey) ? array_replace_recursive(PatternData::getOption($patternStoreKey), $patternStoreData) : $patternStoreData;
         PatternData::setOption($patternStoreKey, $patternStoreData);
     }
 }
开发者ID:mytoysgroup,项目名称:patternlab-php-core,代码行数:40,代码来源:PatternInfoRule.php



注:本文中的YAML类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP YDConfig类代码示例发布时间:2022-05-23
下一篇:
PHP Y类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap