当前位置: 首页>>代码示例>>PHP>>正文


PHP Yaml::decode方法代码示例

本文整理汇总了PHP中Drupal\Component\Serialization\Yaml::decode方法的典型用法代码示例。如果您正苦于以下问题:PHP Yaml::decode方法的具体用法?PHP Yaml::decode怎么用?PHP Yaml::decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Drupal\Component\Serialization\Yaml的用法示例。


在下文中一共展示了Yaml::decode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: mergeInfoFile

 /**
  * Merges an info file into a package's info file.
  *
  * @param string $package_info
  *   The Yaml encoded package info.
  * @param string $info_file_uri
  *   The info file's URI.
  */
 protected function mergeInfoFile($package_info, $info_file_uri) {
   $package_info = Yaml::decode($package_info);
   $existing_info = \Drupal::service('info_parser')->parse($info_file_uri);
   // Ensure the entire 'features' data is replaced by new data.
   unset($existing_info['features']);
   return Yaml::encode($this->featuresManager->arrayMergeUnique($existing_info, $package_info));
 }
开发者ID:jeetendrasingh,项目名称:manage_profile,代码行数:15,代码来源:FeaturesGenerationMethodBase.php

示例2: findAll

 /**
  * {@inheritdoc}
  */
 public function findAll()
 {
     $all = array();
     $files = $this->findFiles();
     $file_cache = FileCacheFactory::get('yaml_discovery:' . $this->fileCacheKeySuffix);
     // Try to load from the file cache first.
     foreach ($file_cache->getMultiple(array_keys($files)) as $file => $data) {
         $all[$files[$file]][$this->getIdentifier($file, $data)] = $data;
         unset($files[$file]);
     }
     // If there are files left that were not returned from the cache, load and
     // parse them now. This list was flipped above and is keyed by filename.
     if ($files) {
         foreach ($files as $file => $provider) {
             // If a file is empty or its contents are commented out, return an empty
             // array instead of NULL for type consistency.
             try {
                 $data = Yaml::decode(file_get_contents($file)) ?: [];
             } catch (InvalidDataTypeException $e) {
                 throw new DiscoveryException("The {$file} contains invalid YAML", 0, $e);
             }
             $data[static::FILE_KEY] = $file;
             $all[$provider][$this->getIdentifier($file, $data)] = $data;
             $file_cache->set($file, $data);
         }
     }
     return $all;
 }
开发者ID:sojo,项目名称:d8_friendsofsilence,代码行数:31,代码来源:YamlDirectoryDiscovery.php

示例3: testExport

 /**
  * Tests export of configuration.
  */
 function testExport()
 {
     // Verify the export page with export submit button is available.
     $this->drupalGet('admin/config/development/configuration/full/export');
     $this->assertFieldById('edit-submit', t('Export'));
     // Submit the export form and verify response.
     $this->drupalPostForm('admin/config/development/configuration/full/export', array(), t('Export'));
     $this->assertResponse(200, 'User can access the download callback.');
     // Get the archived binary file provided to user for download.
     $archive_data = $this->drupalGetContent();
     // Temporarily save the archive file.
     $uri = file_unmanaged_save_data($archive_data, 'temporary://config.tar.gz');
     // Extract the archive and verify it's not empty.
     $file_path = file_directory_temp() . '/' . file_uri_target($uri);
     $archiver = new Tar($file_path);
     $archive_contents = $archiver->listContents();
     $this->assert(!empty($archive_contents), 'Downloaded archive file is not empty.');
     // Prepare the list of config files from active storage, see
     // \Drupal\config\Controller\ConfigController::downloadExport().
     $storage_active = $this->container->get('config.storage');
     $config_files = array();
     foreach ($storage_active->listAll() as $config_name) {
         $config_files[] = $config_name . '.yml';
     }
     // Assert that the downloaded archive file contents are the same as the test
     // site active store.
     $this->assertIdentical($archive_contents, $config_files);
     // Ensure the test configuration override is in effect but was not exported.
     $this->assertIdentical(\Drupal::config('system.maintenance')->get('message'), 'Foo');
     $archiver->extract(file_directory_temp(), array('system.maintenance.yml'));
     $file_contents = file_get_contents(file_directory_temp() . '/' . 'system.maintenance.yml');
     $exported = Yaml::decode($file_contents);
     $this->assertNotIdentical($exported['message'], 'Foo');
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:37,代码来源:ConfigExportUITest.php

示例4: mergeInfoFile

 /**
  * Merges an info file into a package's info file.
  *
  * @param string $package_info
  *   The Yaml encoded package info.
  * @param string $info_file_uri
  *   The info file's URI.
  */
 protected function mergeInfoFile($package_info, $info_file_uri)
 {
     $package_info = Yaml::decode($package_info);
     /** @var \Drupal\Core\Extension\InfoParserInterface $existing_info */
     $existing_info = \Drupal::service('info_parser')->parse($info_file_uri);
     return Yaml::encode($this->featuresManager->mergeInfoArray($existing_info, $package_info));
 }
开发者ID:selwynpolit,项目名称:d8_test2,代码行数:15,代码来源:FeaturesGenerationMethodBase.php

示例5: execute

 public function execute()
 {
     $file = $this->getUnaliasedPath($this->configuration['in']);
     $data = file_exists($file) ? YAML::decode(file_get_contents($file)) : [];
     $keys = explode('/', $this->configuration['key']);
     NestedArray::setValue($data, $keys, $this->configuration['value']);
     file_put_contents($file, YAML::encode($data));
 }
开发者ID:nishantkumar155,项目名称:drupal8.crackle,代码行数:8,代码来源:Define.php

示例6: findAll

 /**
  * {@inheritdoc}
  */
 public function findAll()
 {
     $all = array();
     foreach ($this->findFiles() as $provider => $file) {
         $all[$provider] = Yaml::decode(file_get_contents($file));
     }
     return $all;
 }
开发者ID:davidsoloman,项目名称:drupalconsole.com,代码行数:11,代码来源:YamlDiscovery.php

示例7: validateForm

 /**
  * {@inheritdoc}
  */
 public function validateForm(array &$form, FormStateInterface $form_state)
 {
     $config_text = $form_state->getValue('config') ?: 'attributes:';
     try {
         $form_state->set('config', Yaml::decode($config_text));
     } catch (InvalidDataTypeException $e) {
         $form_state->setErrorByName('config', $e->getMessage());
     }
     parent::validateForm($form, $form_state);
 }
开发者ID:MGApcDev,项目名称:MGApcDevCom,代码行数:13,代码来源:ConfigForm.php

示例8: getDerivativeDefinitions

 /**
  * {@inheritdoc}
  */
 public function getDerivativeDefinitions($base_plugin_definition)
 {
     $sweets_list = drupal_get_path('module', 'breakfast') . '/sweets.yml';
     $sweets = Yaml::decode(file_get_contents($sweets_list));
     foreach ($sweets as $key => $sweet) {
         $this->derivatives[$key] = $base_plugin_definition;
         $this->derivatives[$key] += array('label' => $sweet['label'], 'image' => $sweet['image'], 'ingredients' => $sweet['ingredients']);
     }
     return $this->derivatives;
 }
开发者ID:kerro,项目名称:breakfast,代码行数:13,代码来源:Sweets.php

示例9: testServerSerialization

 /**
  * Tests that serialization of server entities doesn't lead to data loss.
  */
 public function testServerSerialization()
 {
     // As our test server, just use the one from the DB Defaults module.
     $path = __DIR__ . '/../../../search_api_db/search_api_db_defaults/config/optional/search_api.server.default_server.yml';
     $values = Yaml::decode(file_get_contents($path));
     $server = new Server($values, 'search_api_server');
     $serialized = unserialize(serialize($server));
     $this->assertNotEmpty($serialized);
     $this->assertEquals($server, $serialized);
 }
开发者ID:nB-MDSO,项目名称:mdso-d8blog,代码行数:13,代码来源:EntitySerializationTest.php

示例10: testIndexSerialization

 /**
  * Tests that serialization of index entities doesn't lead to data loss.
  */
 public function testIndexSerialization()
 {
     // As our test index, just use the one from the DB Defaults module.
     $path = __DIR__ . '/../../../search_api_db/search_api_db_defaults/config/optional/search_api.index.default_index.yml';
     $index_values = Yaml::decode(file_get_contents($path));
     $index = new Index($index_values, 'search_api_index');
     /** @var \Drupal\search_api\IndexInterface $serialized */
     $serialized = unserialize(serialize($index));
     $this->assertNotEmpty($serialized);
     $this->assertEquals($index, $serialized);
 }
开发者ID:curveagency,项目名称:intranet,代码行数:14,代码来源:EntitySerializationTest.php

示例11: yamlDecode

 protected static function yamlDecode($file, $aliases = [])
 {
     $code = "alias:\n";
     $aliases['path'] = dirname($file);
     $yaml = new Dumper();
     $yaml->setIndentation(2);
     foreach ($aliases as $key => $value) {
         $code .= '  - &' . $key . "\n" . $yaml->dump($value, PHP_INT_MAX, 4, TRUE, FALSE) . "\n";
     }
     return Yaml::decode($code . file_get_contents($file));
 }
开发者ID:d-f-d,项目名称:d_submodules,代码行数:11,代码来源:YamlLoader.php

示例12: submitForm

 /**
  * {@inheritdoc}
  */
 public function submitForm(array &$form, FormStateInterface $form_state)
 {
     $config = $this->config('jquery_ui_filter.settings');
     $data = $form_state->getValue('jquery_ui_filter');
     foreach (jQueryUiFilter::$widgets as $name => $widget) {
         $data[$name]['options'] = (Yaml::decode($data[$name]['options']) ?: []) + $widget['options'];
     }
     $config->setData($data);
     $config->save();
     parent::submitForm($form, $form_state);
 }
开发者ID:justincletus,项目名称:webdrupalpro,代码行数:14,代码来源:jQueryUiFilterSettingsForm.php

示例13: getBreakpointByName

 /**
  * @param $group    String
  */
 private function getBreakpointByName($group)
 {
     $breakpointsManager = $this->getDrupalService('breakpoint.manager');
     $typeExtension = implode(',', array_values($breakpointsManager->getGroupProviders($group)));
     if ($typeExtension == 'theme') {
         $projectPath = drupal_get_path('theme', $group);
     }
     if ($typeExtension == 'module') {
         $projectPath = drupal_get_path('module', $group);
     }
     return Yaml::decode(file_get_contents($projectPath . '/' . $group . '.breakpoints.yml'));
 }
开发者ID:durgeshs,项目名称:DrupalConsole,代码行数:15,代码来源:DebugCommand.php

示例14: testWriteBackConfig

 /**
  * Test ConfigDevelAutoExportSubscriber::writeBackConfig().
  */
 public function testWriteBackConfig()
 {
     $config_data = array('id' => $this->randomMachineName(), 'langcode' => 'en', 'uuid' => '836769f4-6791-402d-9046-cc06e20be87f');
     $config = $this->getMockBuilder('\\Drupal\\Core\\Config\\Config')->disableOriginalConstructor()->getMock();
     $config->expects($this->any())->method('getName')->will($this->returnValue($this->randomMachineName()));
     $config->expects($this->any())->method('get')->will($this->returnValue($config_data));
     $file_names = array(vfsStream::url('public://' . $this->randomMachineName() . '.yml'), vfsStream::url('public://' . $this->randomMachineName() . '.yml'));
     $configDevelSubscriber = new ConfigDevelAutoExportSubscriber($this->configFactory, $this->configManager);
     $configDevelSubscriber->writeBackConfig($config, $file_names);
     $data = $config_data;
     unset($data['uuid']);
     foreach ($file_names as $file_name) {
         $this->assertEquals($data, Yaml::decode(file_get_contents($file_name)));
     }
 }
开发者ID:ddrozdik,项目名称:dmaps,代码行数:18,代码来源:ConfigDevelAutoExportSubscriberTest.php

示例15: getAllTemplates

 /**
  * {@inheritdoc}
  */
 public function getAllTemplates()
 {
     $templates = [];
     foreach ($this->moduleHandler->getModuleDirectories() as $directory) {
         $full_directory = $directory . '/' . $this->directory;
         if (file_exists($full_directory)) {
             $files = scandir($full_directory);
             foreach ($files as $file) {
                 if ($file[0] !== '.' && fnmatch('*.yml', $file)) {
                     $templates[basename($file, '.yml')] = Yaml::decode(file_get_contents("{$full_directory}/{$file}"));
                 }
             }
         }
     }
     return $templates;
 }
开发者ID:shawnmmatthews,项目名称:gerber8,代码行数:19,代码来源:MigrateTemplateStorage.php


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