本文整理汇总了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());
}
}
}
示例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);
}
示例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));
}
示例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);
}
}
}
示例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));
}
示例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;
}
示例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));
}
示例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);
}
示例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);
}
}
}
示例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');
}
}
示例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;
}
示例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;
}
}
示例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]);
}
}
}
}
示例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'))];
}
示例15: getFileContents
/**
* @param $file
* @return array
*/
public function getFileContents($file)
{
if (file_exists($file)) {
return $this->parser->parse(file_get_contents($file));
}
return [];
}