當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。