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


PHP Parser::parse方法代码示例

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


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

示例1: updateAppVersion

 public static function updateAppVersion(CommandEvent $event)
 {
     $configs = self::getConfigs($event);
     $yamlParser = new Parser();
     foreach ($configs as $config) {
         $config = self::processConfig($config);
         $realFile = $config['file'];
         $parameterKey = $config['parameter-key'];
         $versionKey = $config['app-version-key'];
         try {
             $distValues = $yamlParser->parse(file_get_contents($config['dist-file']));
             $actualValues = $yamlParser->parse(file_get_contents($realFile));
             // Checking on dist file is enough as Incenteev's parameter builder runs first
             if (array_key_exists($versionKey, $distValues[$parameterKey])) {
                 $currentVersion = $actualValues[$parameterKey][$versionKey];
                 $newVersion = $distValues[$parameterKey][$versionKey];
                 // Replace the current version with the updated from the dist file if changed
                 if ($currentVersion != $newVersion) {
                     $actualValues[$parameterKey][$versionKey] = $newVersion;
                     file_put_contents($realFile, Yaml::dump($actualValues, 99));
                     $event->getIO()->write(sprintf('<info>App version updated to "%s"</info>', $newVersion));
                 }
             }
         } catch (ParseException $e) {
             printf("Unable to parse the YAML string: %s", $e->getMessage());
         }
     }
 }
开发者ID:hkmshb,项目名称:OpitHrm,代码行数:28,代码来源:ScriptHandler.php

示例2: decode

 /**
  * @param string $data
  * @param string $format
  * @param array  $context
  *
  * @return mixed
  */
 public function decode($data, $format, array $context = array())
 {
     if ($this->native) {
         return yaml_parse($data);
     }
     return $this->decoder->parse($data);
 }
开发者ID:mihai-stancu,项目名称:serializer,代码行数:14,代码来源:YamlEncoder.php

示例3: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $configName = $input->getArgument('name');
     $fileName = $input->getArgument('file');
     $config = $this->getDrupalService('config.factory')->getEditable($configName);
     $ymlFile = new Parser();
     if (!empty($fileName) && file_exists($fileName)) {
         $value = $ymlFile->parse(file_get_contents($fileName));
     } else {
         $value = $ymlFile->parse(stream_get_contents(fopen("php://stdin", "r")));
     }
     if (empty($value)) {
         $io->error($this->trans('commands.config.import.single.messages.empty-value'));
         return;
     }
     $config->setData($value);
     try {
         $config->save();
     } catch (\Exception $e) {
         $io->error($e->getMessage());
         return 1;
     }
     $io->success(sprintf($this->trans('commands.config.import.single.messages.success'), $configName));
 }
开发者ID:mnico,项目名称:DrupalConsole,代码行数:28,代码来源:ImportSingleCommand.php

示例4: load

 /**
  * Loads and parses the config file
  *
  * @param string $env  Environment
  * @param string $file Config filename
  * @return void
  * @throws \Exception
  */
 private function load($env = 'local', $file = 'config')
 {
     $path = BASE_PATH . ($file === '.env' ? '' : '/config');
     // File paths
     $configPath = "{$path}/{$file}.yml";
     $envConfigPath = "{$path}/{$file}_{$env}.yml";
     if (!file_exists($configPath)) {
         throw new \Exception("Config file not found at \"{$configPath}\".");
     }
     $data = file_get_contents($configPath);
     if ($data === false) {
         throw new \Exception("Unable to load configuration from: {$configPath}");
     }
     $yaml = new Parser();
     // Load config
     $config = $yaml->parse($data);
     $this->config = $config ? $config : [];
     // Load environment specific config
     if (file_exists($envConfigPath)) {
         $data = file_get_contents($envConfigPath);
         if ($data) {
             $config = $yaml->parse($data);
             $config = $config ? $config : [];
             // Merge config values
             $this->config = array_merge($this->config, $config);
         }
     }
 }
开发者ID:torann,项目名称:skosh-generator,代码行数:36,代码来源:Config.php

示例5: parseConfig

 /**
  * @param string $filePath
  *
  * @throws ConfigNotFoundException
  * @throws ParseException
  *
  * @return array The parsed configuration
  */
 public function parseConfig($filePath)
 {
     if (!file_exists($filePath)) {
         throw new ConfigNotFoundException(sprintf('Configuration file not found: %s', $filePath));
     }
     return $this->yamlParser->parse(file_get_contents($filePath));
 }
开发者ID:j7mbo,项目名称:aurex,代码行数:15,代码来源:Parser.php

示例6: loadFile

 /**
  * @param string $file
  * @return array
  */
 protected function loadFile($file)
 {
     if (!class_exists('Symfony\\Component\\Yaml\\Parser')) {
         throw new \RuntimeException('Unable to load YAML config files as the Symfony Yaml Component is not installed.');
     }
     if (!stream_is_local($file)) {
         throw new \InvalidArgumentException(sprintf('This is not a local file "%s".', $file));
     }
     if (!file_exists($file)) {
         throw new \InvalidArgumentException(sprintf('The service file "%s" is not valid.', $file));
     }
     if (null === $this->yamlParser) {
         $this->yamlParser = new Parser();
     }
     try {
         $config = $this->yamlParser->parse(file_get_contents($file));
         if (!is_array($config)) {
             throw new \InvalidArgumentException(sprintf('The contents of the file "%s" is not an array.', $file));
         }
     } catch (ParseException $e) {
         throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $file), 0, $e);
     }
     $this->app->parseParameters($config);
     return $config;
 }
开发者ID:vudaltsov,项目名称:silex-project,代码行数:29,代码来源:YamlConfigLoader.php

示例7: setConfig

 public function setConfig($config)
 {
     if (!file_exists($config) || !is_readable($config)) {
         throw new \Exception('Unable to parse configuration file.');
     }
     $this->config = $this->parser->parse(file_get_contents($config));
 }
开发者ID:zilkil,项目名称:zilack,代码行数:7,代码来源:ConfigManager.php

示例8: configureAction

 public function configureAction()
 {
     $data = [];
     $data['data']['page'] = 'config';
     $parametersFile = __DIR__ . '/../../../../app/config/parameters.yml';
     $parametersFileDist = $parametersFile . '.dist';
     $formData = new Config();
     $parser = new Parser();
     if (file_exists($parametersFile)) {
         $formDataFile = $parser->parse(file_get_contents($parametersFile));
     } else {
         $formDataFile = $parser->parse(file_get_contents($parametersFileDist));
     }
     foreach ($formDataFile['parameters'] as $key => $value) {
         $setter = 'set' . implode('', array_map(function ($s) {
             return ucfirst($s);
         }, explode('_', $key)));
         if (method_exists($formData, $setter)) {
             $formData->{$setter}($value);
         }
     }
     $form = $this->createForm(new ConfigType(), $formData, ['method' => 'post', 'action' => $this->get('router')->generate('ojs_installer_save_configure')]);
     $data['form'] = $form->createView();
     return $this->render("OjsInstallerBundle:Default:configure.html.twig", $data);
 }
开发者ID:necatikartal,项目名称:ojs,代码行数:25,代码来源:ConfigController.php

示例9: processFile

 public function processFile(array $config)
 {
     $config = $this->processConfig($config);
     $realFile = $config['file'];
     $distFile = $config['dist-file'];
     $parameterKey = $config['parameter-key'];
     $exists = is_file($realFile);
     $yamlParser = new Parser();
     if (!$exists) {
         if ($this->checkPermissionToInstall()) {
             $this->io->write(sprintf('<info>%s the "%s" file</info>', 'Creating', $realFile));
             // Find the expected params
             $expectedValues = $yamlParser->parse(file_get_contents($distFile));
             if (!isset($expectedValues[$parameterKey])) {
                 throw new \InvalidArgumentException(sprintf('The top-level key %s is missing.', $parameterKey));
             }
             $expectedParams = (array) $expectedValues[$parameterKey]['endpoints'];
             // find the actual params
             $actualValues = array_merge($expectedValues, array($parameterKey => array('endpoints' => array())));
             $actualValues[$parameterKey]['endpoints'] = $this->processParams($config, $expectedParams, (array) $actualValues[$parameterKey]['endpoints']);
             $ch = curl_init();
             curl_setopt($ch, CURLOPT_URL, 'http://' . $actualValues[$parameterKey]['endpoints'][$this->getEndPointName()]['host'] . ':' . $actualValues[$parameterKey]['endpoints'][$this->getEndPointName()]['port'] . $actualValues[$parameterKey]['endpoints'][$this->getEndPointName()]['path'] . '/admin/cores?action=CREATE&name=' . $actualValues[$parameterKey]['endpoints'][$this->getEndPointName()]['core'] . '&configSet=configset1');
             curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
             curl_exec($ch);
             curl_close($ch);
             $this->processWriteValuesToFile($actualValues, $realFile);
             $this->importToConfigFile($realFile);
         } else {
             $this->processWriteValuesToFile($yamlParser->parse(file_get_contents($distFile)), $realFile);
         }
     }
 }
开发者ID:symbio,项目名称:orangegate4-search-bundle,代码行数:32,代码来源:Processor.php

示例10: load

 /**
  * {@inheritDoc}
  */
 public function load(array $configs, ContainerBuilder $container)
 {
     $configuration = new Configuration();
     $config = $this->processConfiguration($configuration, $configs);
     $this->bindParameters($container, $this->getAlias(), $config);
     // Fallback for missing intl extension
     $intlExtensionInstalled = extension_loaded('intl');
     $container->setParameter('lunetics_locale.intl_extension_installed', $intlExtensionInstalled);
     $iso3166 = array();
     $iso639one = array();
     $iso639two = array();
     $localeScript = array();
     if (!$intlExtensionInstalled) {
         $yamlParser = new YamlParser();
         $file = new FileLocator(__DIR__ . '/../Resources/config');
         $iso3166 = $yamlParser->parse(file_get_contents($file->locate('iso3166-1-alpha-2.yml')));
         $iso639one = $yamlParser->parse(file_get_contents($file->locate('iso639-1.yml')));
         $iso639two = $yamlParser->parse(file_get_contents($file->locate('iso639-2.yml')));
         $localeScript = $yamlParser->parse(file_get_contents($file->locate('locale_script.yml')));
     }
     $container->setParameter('lunetics_locale.intl_extension_fallback.iso3166', $iso3166);
     $mergedValues = array_merge($iso639one, $iso639two);
     $container->setParameter('lunetics_locale.intl_extension_fallback.iso639', $mergedValues);
     $container->setParameter('lunetics_locale.intl_extension_fallback.script', $localeScript);
     $loader = new Loader\XmlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
     $loader->load('validator.xml');
     $loader->load('guessers.xml');
     $loader->load('services.xml');
     $loader->load('switcher.xml');
     $loader->load('form.xml');
     if (!$config['strict_match']) {
         $container->removeDefinition('lunetics_locale.best_locale_matcher');
     }
 }
开发者ID:Sententiaregum,项目名称:LocaleBundle,代码行数:37,代码来源:LuneticsLocaleExtension.php

示例11: load

 /**
  * Loads a resource.
  *
  * @param mixed  $resource The resource
  * @param string $type     The resource type
  * @return array
  */
 public function load($resource, $type = NULL)
 {
     $path = $this->locator->locate($resource);
     $file = $this->filesystem->openFile($path);
     $configValues = $this->yamlParser->parse($file->getContents());
     return $configValues;
 }
开发者ID:hexa2k9,项目名称:typo3-typoscript-lint,代码行数:14,代码来源:YamlConfigurationLoader.php

示例12: execute

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new DrupalStyle($input, $output);
     $configName = $input->getArgument('name');
     $fileName = $input->getArgument('file');
     $ymlFile = new Parser();
     if (!empty($fileName) && file_exists($fileName)) {
         $value = $ymlFile->parse(file_get_contents($fileName));
     } else {
         $value = $ymlFile->parse(stream_get_contents(fopen("php://stdin", "r")));
     }
     if (empty($value)) {
         $io->error($this->trans('commands.config.import.single.messages.empty-value'));
         return;
     }
     try {
         $source_storage = new StorageReplaceDataWrapper($this->configStorage);
         $source_storage->replaceData($configName, $value);
         $storage_comparer = new StorageComparer($source_storage, $this->configStorage, $this->configManager);
         if ($this->configImport($io, $storage_comparer)) {
             $io->success(sprintf($this->trans('commands.config.import.single.messages.success'), $configName));
         }
     } catch (\Exception $e) {
         $io->error($e->getMessage());
         return 1;
     }
 }
开发者ID:jeyram,项目名称:DrupalConsole,代码行数:30,代码来源:ImportSingleCommand.php

示例13: load

 /**
  * Load the YAML config's
  */
 public function load()
 {
     if (file_exists($this->config_path . '/' . $this->config_file)) {
         $yaml = new Parser();
         global $config;
         $config = (array) $yaml->parse(file_get_contents($this->config_path . '/' . $this->config_file));
         if (!empty($config['WP_ENV']) && file_exists($this->config_path . '/config_' . $config['WP_ENV'] . '.yml')) {
             $env = $yaml->parse(file_get_contents($this->config_path . '/config_' . $config['WP_ENV'] . '.yml'));
             if (!empty($env)) {
                 $config = array_merge($config, $env);
             }
         }
         if (!empty($config['imports'])) {
             foreach ($config['imports'] as $import) {
                 if (!empty($import['resource']) && file_exists($this->config_path . '/' . $import['resource'])) {
                     $import = $yaml->parse(file_get_contents($this->config_path . '/' . $import['resource']));
                     $config = array_merge($config, $import);
                 }
             }
             unset($config['imports']);
         }
         foreach ($config as $key => $value) {
             if (!is_array($value)) {
                 define($key, $value);
                 unset($config[$key]);
             }
         }
     }
 }
开发者ID:kevinkiel,项目名称:wp-yaml-loader,代码行数:32,代码来源:YamlLoader.php

示例14: configureParameters

 private function configureParameters()
 {
     $yaml = new Parser();
     $this['root_dir'] = __DIR__ . '/../..';
     $this['config_dir'] = __DIR__ . '/Resources/config';
     $this['config'] = ['settings' => $yaml->parse(file_get_contents($this['config_dir'] . '/settings.yml')), 'heroes' => $yaml->parse(file_get_contents($this['config_dir'] . '/heroes.yml')), 'items' => $yaml->parse(file_get_contents($this['config_dir'] . '/items.yml')), 'map' => $yaml->parse(file_get_contents($this['config_dir'] . '/map.yml'))];
 }
开发者ID:joshlopes,项目名称:dota2.mapapi,代码行数:7,代码来源:Application.php

示例15: getFileContents

 /**
  * @param $file
  * @return array
  */
 public function getFileContents($file)
 {
     if (file_exists($file)) {
         return $this->parser->parse(file_get_contents($file));
     }
     return [];
 }
开发者ID:durgeshs,项目名称:DrupalConsole,代码行数:11,代码来源:Config.php


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