當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Yaml::parse方法代碼示例

本文整理匯總了PHP中Symfony\Component\Yaml\Yaml::parse方法的典型用法代碼示例。如果您正苦於以下問題:PHP Yaml::parse方法的具體用法?PHP Yaml::parse怎麽用?PHP Yaml::parse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Symfony\Component\Yaml\Yaml的用法示例。


在下文中一共展示了Yaml::parse方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: parse

 /**
  * @param      $string
  * @param null $path
  * @return string
  */
 public function parse($string, $path = null)
 {
     $headers = [];
     $parts = preg_split('/[\\n]*[-]{3}[\\n]/', $string, 3);
     if (count($parts) == 3) {
         $string = $parts[0] . "\n" . $parts[2];
         $headers = $this->yaml->parse($parts[1]);
     }
     $file = new SplFileInfo($path, '', '');
     $date = Carbon::createFromTimestamp($file->getMTime());
     $dateFormat = config('fizl-pages::date_format', 'm/d/Y g:ia');
     $headers['date_modified'] = $date->toDateTimeString();
     if (isset($headers['date'])) {
         try {
             $headers['date'] = Carbon::createFromFormat($dateFormat, $headers['date'])->toDateTimeString();
         } catch (\InvalidArgumentException $e) {
             $headers['date'] = $headers['date_modified'];
             //dd($e->getMessage());
         }
     } else {
         $headers['date'] = $headers['date_modified'];
     }
     $this->execute(new PushHeadersIntoCollectionCommand($headers, $this->headers));
     $viewPath = PageHelper::filePathToViewPath($path);
     $cacheKey = "{$viewPath}.headers";
     $this->cache->put($cacheKey, $headers);
     return $string;
 }
開發者ID:hscale,項目名稱:fizl-pages,代碼行數:33,代碼來源:PageHeaderParser.php

示例2: prepend

 /**
  * Allow an extension to prepend the extension configurations.
  *
  * @param \Symfony\Component\DependencyInjection\ContainerBuilder $container
  */
 public function prepend(ContainerBuilder $container)
 {
     $configFile = __DIR__ . '/../Resources/config/templates.yml';
     $config = Yaml::parse(file_get_contents($configFile));
     $container->prependExtensionConfig('ezpublish', $config);
     $container->addResource(new FileResource($configFile));
 }
開發者ID:eab-dev,項目名稱:UniqueDatatypesBundle,代碼行數:12,代碼來源:EabUniqueDatatypesExtension.php

示例3: testAdd

 public function testAdd()
 {
     global $testHelpers, $mockPosts;
     $testHelpers->writeAppsettings(['keepDefaultContent' => true], 'yaml');
     $yaml = new Yaml();
     \WP_Mock::wpFunction('get_post', ['times' => '1', 'return' => (object) $mockPosts['testpost1']]);
     \WP_Mock::wpFunction('get_posts', ['times' => '1', 'return' => [(object) $mockPosts['testpost1']]]);
     $app = $testHelpers->getAppWithMockCli();
     Bootstrap::setApplication($app);
     $cli = $app['cli'];
     $p = new Commands\Posts();
     $p->add(array(10), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertTrue(isset($settings['content']['posts']['post']));
     $this->assertEquals(1, count($settings['content']['posts']['post']));
     $this->assertEquals('testpost1', $settings['content']['posts']['post'][0]);
     file_put_contents(WPBOOT_BASEPATH . '/appsettings.yml', "foobar: true\n");
     $p->add(array('testpost1'), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertTrue(isset($settings['content']['posts']['post']));
     $this->assertEquals(1, count($settings['content']['posts']['post']));
     $this->assertEquals('testpost1', $settings['content']['posts']['post'][0]);
     \WP_Mock::wpFunction('get_posts', ['times' => '1', 'return' => false]);
     file_put_contents(WPBOOT_BASEPATH . '/appsettings.yml', "foobar: true\n");
     $p->add(array('testpost1'), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertFalse(isset($settings['content']['posts']['post']));
 }
開發者ID:eriktorsner,項目名稱:wp-bootstrap-test,代碼行數:28,代碼來源:PostsManagerTest.php

示例4: testAdd

 public function testAdd()
 {
     global $testHelpers, $mockTerms;
     $testHelpers->writeAppsettings(['keepDefaultContent' => true], 'yaml');
     $yaml = new Yaml();
     $app = $testHelpers->getAppWithMockCli();
     Bootstrap::setApplication($app);
     $m = new Commands\Menus();
     $cli = $app['cli'];
     $cli->launch_self_return = (object) ['return_code' => 0, 'stdout' => json_encode([(object) ['term_id' => 1, 'name' => 'Main menu', 'slug' => 'main', 'locations' => ['primary', 'footer'], 'count' => 2]])];
     $m->add(array('main'), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertTrue(isset($settings['content']['menus']));
     $this->assertEquals(1, count($settings['content']['menus']));
     $this->assertEquals('main', $settings['content']['menus'][0]);
     file_put_contents(WPBOOT_BASEPATH . '/appsettings.yml', "foobar: true\n");
     $m->add(array(1), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertTrue(isset($settings['content']['menus']));
     $this->assertEquals(1, count($settings['content']['menus']));
     $this->assertEquals('main', $settings['content']['menus'][0]);
     file_put_contents(WPBOOT_BASEPATH . '/appsettings.yml', "foobar: true\n");
     $m->add(array(999), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertFalse(isset($settings['content']['menus']));
 }
開發者ID:eriktorsner,項目名稱:wp-bootstrap-test,代碼行數:26,代碼來源:MenusManagerTest.php

示例5: import

 public function import()
 {
     $app = Bootstrap::getApplication();
     $settings = $app['settings'];
     $yaml = new Yaml();
     $helpers = $app['helpers'];
     $baseUrl = get_option('siteurl');
     if (!isset($settings['content']['menus'])) {
         return;
     }
     foreach ($settings['content']['menus'] as $menu) {
         $dir = WPBOOT_BASEPATH . "/bootstrap/menus/{$menu}";
         $menuMeta = $yaml->parse(file_get_contents(WPBOOT_BASEPATH . "/bootstrap/menus/{$menu}_manifest"));
         $newMenu = new \stdClass();
         $newMenu->slug = $menu;
         $newMenu->locations = $menuMeta['locations'];
         $newMenu->items = array();
         foreach ($helpers->getFiles($dir) as $file) {
             $menuItem = new \stdClass();
             $menuItem->done = false;
             $menuItem->id = 0;
             $menuItem->parentId = 0;
             $menuItem->slug = $file;
             //$menuItem->menu = unserialize(file_get_contents($dir.'/'.$file));
             $menuItem->menu = $yaml->parse(file_get_contents("{$dir}/{$file}"));
             $newMenu->items[] = $menuItem;
         }
         usort($newMenu->items, function ($a, $b) {
             return (int) $a->menu['menu_order'] - (int) $b->menu['menu_order'];
         });
         $this->menus[] = $newMenu;
     }
     $helpers->fieldSearchReplace($this->menus, Bootstrap::NEUTRALURL, $baseUrl);
     $this->process();
 }
開發者ID:eriktorsner,項目名稱:wp-bootstrap,代碼行數:35,代碼來源:ImportMenus.php

示例6: import

 public function import()
 {
     $app = Bootstrap::getApplication();
     $helpers = $app['helpers'];
     $baseUrl = get_option('siteurl');
     $yaml = new Yaml();
     $dir = WPBOOT_BASEPATH . '/bootstrap/sidebars';
     foreach ($helpers->getFiles($dir) as $sidebar) {
         if (!is_dir(WPBOOT_BASEPATH . "/bootstrap/sidebars/{$sidebar}")) {
             continue;
         }
         $subdir = WPBOOT_BASEPATH . "/bootstrap/sidebars/{$sidebar}";
         $manifest = WPBOOT_BASEPATH . "/bootstrap/sidebars/{$sidebar}_manifest";
         $newSidebar = new \stdClass();
         $newSidebar->slug = $sidebar;
         $newSidebar->items = array();
         $newSidebar->meta = $yaml->parse(file_get_contents($manifest));
         foreach ($newSidebar->meta as $key => $widgetRef) {
             $widget = new \stdClass();
             $parts = explode('-', $widgetRef);
             $ord = end($parts);
             $type = substr($widgetRef, 0, -1 * strlen('-' . $ord));
             $widget->type = $type;
             $widget->ord = $ord;
             $widget->meta = $yaml->parse(file_get_contents($subdir . '/' . $widgetRef));
             $newSidebar->items[] = $widget;
         }
         $this->sidebars[] = $newSidebar;
     }
     $helpers->fieldSearchReplace($this->sidebars, Bootstrap::NEUTRALURL, $baseUrl);
     $this->process();
 }
開發者ID:eriktorsner,項目名稱:wp-bootstrap,代碼行數:32,代碼來源:ImportSidebars.php

示例7: testAdd

 public function testAdd()
 {
     global $testHelpers, $mockTerms;
     $testHelpers->writeAppsettings(['keepDefaultContent' => true], 'yaml');
     $yaml = new Yaml();
     \WP_Mock::wpFunction('get_term_by', ['times' => '2', 'return' => (object) $mockTerms['catTerm1']]);
     $app = $testHelpers->getAppWithMockCli();
     Bootstrap::setApplication($app);
     $t = new Commands\Taxonomies();
     $t->add(array('category', 21), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertTrue(isset($settings['content']['taxonomies']['category']));
     $this->assertEquals(1, count($settings['content']['taxonomies']['category']));
     $this->assertEquals('catTerm1', $settings['content']['taxonomies']['category'][0]);
     file_put_contents(WPBOOT_BASEPATH . '/appsettings.yml', "foobar: true\n");
     $t->add(array('category', 'catTerm1'), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertTrue(isset($settings['content']['taxonomies']['category']));
     $this->assertEquals(1, count($settings['content']['taxonomies']['category']));
     $this->assertEquals('catTerm1', $settings['content']['taxonomies']['category'][0]);
     file_put_contents(WPBOOT_BASEPATH . '/appsettings.yml', "foobar: true\n");
     $t->add(array('category', '*'), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertTrue(isset($settings['content']['taxonomies']['category']));
     $this->assertEquals(1, count($settings['content']['taxonomies']['category']));
     $this->assertEquals('*', $settings['content']['taxonomies']['category'][0]);
     \WP_Mock::wpFunction('get_term_by', ['times' => '1', 'return' => false]);
     file_put_contents(WPBOOT_BASEPATH . '/appsettings.yml', "foobar: true\n");
     $t->add(array('category', 'yadayada'), array());
     $settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
     $this->assertFalse(isset($settings['content']['taxonomies']['category']));
 }
開發者ID:eriktorsner,項目名稱:wp-bootstrap-test,代碼行數:32,代碼來源:TaxonomiesManagerTest.php

示例8: __construct

 public function __construct(GruverConfig $config)
 {
     $this->config = $config;
     $this->options = array();
     $yaml = new Yaml();
     $this->options = array_merge($this->options, $yaml->parse(__DIR__ . '/../Resources/data/fixture-animals.yml'));
     $this->options = array_merge($this->options, $yaml->parse(__DIR__ . '/../Resources/data/fixture-colors.yml'));
 }
開發者ID:mindgruve,項目名稱:gruver,代碼行數:8,代碼來源:UrlFactory.php

示例9: createMainMenu

 /**
  * @param MenuEvent $event
  * @return Item
  * @throws InvalidYamlStructureException
  */
 public function createMainMenu(MenuEvent $event)
 {
     $config = $this->yaml->parse(file_get_contents($this->configFilePath), true, true);
     if (!isset($config['menu'])) {
         throw new InvalidYamlStructureException(sprintf('File "%s" should contain top level "menu:" key', $this->configFilePath));
     }
     $menu = $event->getMenu();
     $menu->setOptions(array('attr' => array('id' => 'top-menu', 'class' => 'nav navbar-nav')));
     $this->populateMenu($menu, $config['menu']);
     return $menu;
 }
開發者ID:kbedn,項目名稱:admin-bundle,代碼行數:16,代碼來源:MainMenuListener.php

示例10: read

 /**
  * Reads a settings file.
  *
  * @param  string $file A file to read.
  * @return array  The settings read.
  */
 public function read($file)
 {
     $file = '/settings/' . $file;
     /**
      * @todo validate that $file is a string
      */
     $result = [];
     if ($this->source_filesystem->has($file . '.yml')) {
         $result = $this->yaml->parse($this->source_filesystem->read($file . '.yml'));
     }
     return $result;
 }
開發者ID:erickmerchant,項目名稱:wright,代碼行數:18,代碼來源:YamlSettings.php

示例11: parseFile

 /**
  * @param $fileName
  * @return mixed
  */
 protected function parseFile($fileName)
 {
     $definitions = $this->parser->parse(file_get_contents($fileName));
     if (count($definitions) == 0) {
         // Erreur
     }
     if (count($definitions) > 1) {
         // Erreur
     }
     $mappings = $this->mappingsExtract($definitions);
     $mappings = $this->mappingsNormalizeSyntax($mappings);
     return $mappings;
 }
開發者ID:mehdi-ghezal,項目名稱:sellsy-api,代碼行數:17,代碼來源:MappingsParser.php

示例12: testYamlCacheHit

 public function testYamlCacheHit()
 {
     $cacheMock = $this->getMockBuilder('Doctrine\\Common\\Cache\\CacheProvider')->setMethods(array('contains', 'fetch'))->getMockForAbstractClass();
     $cacheMock->expects($this->once())->method('contains')->will($this->returnValue(true));
     $cacheMock->expects($this->once())->method('fetch')->will($this->returnValue(Yaml::parse($this->validYamlData)));
     new YamlConfig($this->validYamlData, $cacheMock);
 }
開發者ID:Focus-Flow,項目名稱:silverstripe-cacheinclude,代碼行數:7,代碼來源:YamlConfigTest.php

示例13: execute

 /**
  * Validate the configuration file
  *
  * @param InputInterface  $input  An InputInterface instance
  * @param OutputInterface $output An OutputInterface instance
  *
  * @return null
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->iohandler_factory->set_environment('cli');
     /** @var \phpbb\install\helper\iohandler\cli_iohandler $iohandler */
     $iohandler = $this->iohandler_factory->get();
     $style = new SymfonyStyle($input, $output);
     $iohandler->set_style($style, $output);
     $config_file = $input->getArgument('config-file');
     if (!is_file($config_file)) {
         $iohandler->add_error_message(array('MISSING_FILE', array($config_file)));
         return 1;
     }
     try {
         $config = Yaml::parse(file_get_contents($config_file), true, false);
     } catch (ParseException $e) {
         $iohandler->add_error_message('INVALID_YAML_FILE');
         return 1;
     }
     $processor = new Processor();
     $configuration = new updater_configuration();
     try {
         $processor->processConfiguration($configuration, $config);
     } catch (Exception $e) {
         $iohandler->add_error_message('INVALID_CONFIGURATION', $e->getMessage());
         return 1;
     }
     $iohandler->add_success_message('CONFIGURATION_VALID');
     return 0;
 }
開發者ID:phpbb,項目名稱:phpbb-core,代碼行數:37,代碼來源:validate.php

示例14: fromString

 /**
  * {@inheritdoc}
  */
 public static function fromString($string, Translations $translations, array $options = [])
 {
     $messages = YamlParser::parse($string);
     if (is_array($messages)) {
         self::fromArray($messages, $translations);
     }
 }
開發者ID:parkerj,項目名稱:eduTrac-SIS,代碼行數:10,代碼來源:YamlDictionary.php

示例15: testParseAndDump

 public function testParseAndDump()
 {
     $data = array('lorem' => 'ipsum', 'dolor' => 'sit');
     $yml = Yaml::dump($data);
     $parsed = Yaml::parse($yml);
     $this->assertEquals($data, $parsed);
 }
開發者ID:Ceciceciceci,項目名稱:MySJSU-Class-Registration,代碼行數:7,代碼來源:YamlTest.php


注:本文中的Symfony\Component\Yaml\Yaml::parse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。