当前位置: 首页>>代码示例>>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;未经允许,请勿转载。