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


PHP Serialization\Yaml类代码示例

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


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

示例1: getRestByID

 /**
  * @param $output         OutputInterface
  * @param $table          TableHelper
  * @param $config_name    String
  */
 private function getRestByID($output, $table, $resource_id)
 {
     // Get the list of enabled and disabled resources.
     $config = $this->getRestDrupalConfig();
     $resourcePluginManager = $this->getPluginManagerRest();
     $plugin = $resourcePluginManager->getInstance(array('id' => $resource_id));
     if (empty($plugin)) {
         $output->writeln('[+] <error>' . sprintf($this->trans('commands.rest.debug.messages.not-found'), $resource_id) . '</error>');
         return false;
     }
     $resource = $plugin->getPluginDefinition();
     $configuration = array();
     $configuration[$this->trans('commands.rest.debug.messages.id')] = $resource['id'];
     $configuration[$this->trans('commands.rest.debug.messages.label')] = (string) $resource['label'];
     $configuration[$this->trans('commands.rest.debug.messages.canonical_url')] = $resource['uri_paths']['canonical'];
     $configuration[$this->trans('commands.rest.debug.messages.status')] = isset($config[$resource['id']]) ? $this->trans('commands.rest.debug.messages.enabled') : $this->trans('commands.rest.debug.messages.disabled');
     $configuration[$this->trans('commands.rest.debug.messages.provider')] = $resource['provider'];
     $configurationEncoded = Yaml::encode($configuration);
     $output->writeln($configurationEncoded);
     $table->render($output);
     $table->setHeaders([$this->trans('commands.rest.debug.messages.rest-state'), $this->trans('commands.rest.debug.messages.supported-formats'), $this->trans('commands.rest.debug.messages.supported_auth')]);
     foreach ($config[$resource['id']] as $method => $settings) {
         $table->addRow([$method, implode(', ', $settings['supported_formats']), implode(', ', $settings['supported_auth'])]);
     }
     $table->render($output);
 }
开发者ID:palantirnet,项目名称:DrupalConsole,代码行数:31,代码来源:RestDebugCommand.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: 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

示例4: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $messageHelper = $this->getHelperSet()->get('message');
     $directory = $input->getArgument('directory');
     if (!$directory) {
         $config = $this->getConfigFactory()->get('system.file');
         $directory = $config->get('path.temporary') ?: file_directory_temp();
         $directory .= '/' . CONFIG_STAGING_DIRECTORY;
     }
     if (!is_dir($directory)) {
         mkdir($directory, 0777, true);
     }
     $config_export_file = $directory . '/config.tar.gz';
     file_unmanaged_delete($config_export_file);
     try {
         $archiver = new ArchiveTar($config_export_file, 'gz');
         $this->configManager = $this->getConfigManager();
         // Get raw configuration data without overrides.
         foreach ($this->configManager->getConfigFactory()->listAll() as $name) {
             $archiver->addString("{$name}.yml", Yaml::encode($this->configManager->getConfigFactory()->get($name)->getRawData()));
         }
         $this->targetStorage = $this->getConfigStorage();
         // Get all override data from the remaining collections.
         foreach ($this->targetStorage->getAllCollectionNames() as $collection) {
             $collection_storage = $this->targetStorage->createCollection($collection);
             foreach ($collection_storage->listAll() as $name) {
                 $archiver->addString(str_replace('.', '/', $collection) . "/{$name}.yml", Yaml::encode($collection_storage->read($name)));
             }
         }
     } catch (\Exception $e) {
         $output->writeln('[+] <error>' . $e->getMessage() . '</error>');
         return;
     }
     $messageHelper->addSuccessMessage(sprintf($this->trans('commands.config.export.messages.directory'), $config_export_file));
 }
开发者ID:amira2r,项目名称:DrupalConsole,代码行数:38,代码来源:ConfigExportCommand.php

示例5: geViewByID

 /**
  * @param $output         OutputInterface
  * @param $table          TableHelper
  * @param $resource_id    String
  */
 private function geViewByID($output, $table, $view_id)
 {
     $entity_manager = $this->getEntityManager();
     $view = $entity_manager->getStorage('view')->load($view_id);
     if (empty($view)) {
         $output->writeln('[+] <error>' . sprintf($this->trans('commands.views.debug.messages.not-found'), $view_id) . '</error>');
         return false;
     }
     $configuration = array();
     $configuration[$this->trans('commands.views.debug.messages.view-id')] = $view->get('id');
     $configuration[$this->trans('commands.views.debug.messages.view-name')] = (string) $view->get('label');
     $configuration[$this->trans('commands.views.debug.messages.tag')] = $view->get('tag');
     $configuration[$this->trans('commands.views.debug.messages.status')] = $view->status() ? $this->trans('commands.common.status.enabled') : $this->trans('commands.common.status.disabled');
     $configuration[$this->trans('commands.views.debug.messages.description')] = $view->get('description');
     $configurationEncoded = Yaml::encode($configuration);
     $output->writeln($configurationEncoded);
     $table->render($output);
     $table->setHeaders([$this->trans('commands.views.debug.messages.display-id'), $this->trans('commands.views.debug.messages.display-name'), $this->trans('commands.views.debug.messages.display-description'), $this->trans('commands.views.debug.messages.display-paths')]);
     $displays = $this->getDisplaysList($view);
     $paths = $this->getDisplayPaths($view);
     $output->writeln('<info>' . sprintf($this->trans('commands.views.debug.messages.display-list'), $view_id) . '</info>');
     foreach ($displays as $display_id => $display) {
         $table->addRow([$display_id, $display['name'], $display['description'], $this->getDisplayPaths($view, $display_id)]);
     }
     $table->render($output);
 }
开发者ID:xsw3ws,项目名称:DrupalConsole,代码行数:31,代码来源:ViewsDebugCommand.php

示例6: 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

示例7: 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

示例8: 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

示例9: setUp

 protected function setUp()
 {
     $this->info = array('type' => 'profile', 'core' => \Drupal::CORE_COMPATIBILITY, 'name' => 'Override standard', 'hidden' => TRUE);
     // File API functions are not available yet.
     $path = $this->siteDirectory . '/profiles/standard';
     mkdir($path, 0777, TRUE);
     file_put_contents("{$path}/standard.info.yml", Yaml::encode($this->info));
     parent::setUp();
 }
开发者ID:HakS,项目名称:drupal8_training,代码行数:9,代码来源:SingleVisibleProfileTest.php

示例10: setUp

 /**
  * {@inheritdoc}
  */
 protected function setUp()
 {
     $this->info = array('type' => 'profile', 'core' => \Drupal::CORE_COMPATIBILITY, 'name' => 'Distribution profile', 'distribution' => array('name' => 'My Distribution', 'langcode' => $this->langcode, 'install' => array('theme' => 'bartik')));
     // File API functions are not available yet.
     $path = $this->siteDirectory . '/profiles/mydistro';
     mkdir($path, 0777, TRUE);
     file_put_contents("{$path}/mydistro.info.yml", Yaml::encode($this->info));
     parent::setUp();
 }
开发者ID:aWEBoLabs,项目名称:taxi,代码行数:12,代码来源:DistributionProfileTranslationTest.php

示例11: getYamlConfig

 /**
  * @param $config_name String
  *
  * @return array
  */
 protected function getYamlConfig($config_name)
 {
     $configStorage = $this->getConfigStorage();
     if ($configStorage->exists($config_name)) {
         $configuration = $configStorage->read($config_name);
         $configurationEncoded = Yaml::encode($configuration);
     }
     return $configurationEncoded;
 }
开发者ID:amira2r,项目名称:DrupalConsole,代码行数:14,代码来源:ConfigEditCommand.php

示例12: 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

示例13: 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

示例14: 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

示例15: 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


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