本文整理汇总了PHP中Symfony\Component\Yaml\Yaml::dump方法的典型用法代码示例。如果您正苦于以下问题:PHP Yaml::dump方法的具体用法?PHP Yaml::dump怎么用?PHP Yaml::dump使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Yaml\Yaml
的用法示例。
在下文中一共展示了Yaml::dump方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createMergeRule
/** @return MergeRule */
private function createMergeRule($ruleLine)
{
if (is_array($ruleLine)) {
if (!isset($ruleLine[ParserConstants::KEY_MERGE_FILE]) || !isset($ruleLine[ParserConstants::KEY_MERGE_GITPATH])) {
throw new RuleParsingException($this->yaml->dump($ruleLine));
}
return new MergeRule($ruleLine[ParserConstants::KEY_MERGE_FILE], $ruleLine[ParserConstants::KEY_MERGE_GITPATH]);
} else {
return new MergeRule($ruleLine);
}
}
示例2: write
/**
* Writes a settings file.
*
* @param string $file The file name
* @param array $settings Settings to write to the file.
* @return void
*/
public function write($file, $settings)
{
$file = '/settings/' . $file;
/**
* @todo validate that $file is a string
* @todo validate that $settings is a string
*/
$settings = json_decode(json_encode($settings), true);
$settings = $this->yaml->dump($settings);
$this->source_filesystem->put($file . '.yml', $settings);
}
示例3: testParseAndDump
public function testParseAndDump()
{
$data = array('lorem' => 'ipsum', 'dolor' => 'sit');
$yml = Yaml::dump($data);
$parsed = Yaml::parse($yml);
$this->assertEquals($data, $parsed);
}
示例4: encode
/**
* Convert an array to a Yaml string.
*
* {@inheritDoc}
*/
public static function encode($array)
{
if (count($array) < 1) {
return "";
}
return SymfonyYaml::dump($array);
}
示例5: processFile
public function processFile(array $config)
{
$config = $this->processConfig($config);
$realFile = $config['file'];
$parameterKey = $config['parameter-key'];
$exists = is_file($realFile);
$yamlParser = new Parser();
$action = $exists ? 'Updating' : 'Creating';
$this->io->write(sprintf('<info>%s the "%s" file</info>', $action, $realFile));
// Find the expected params
$expectedValues = $yamlParser->parse(file_get_contents($config['dist-file']));
if (!isset($expectedValues[$parameterKey])) {
throw new \InvalidArgumentException(sprintf('The top-level key %s is missing.', $parameterKey));
}
$expectedParams = (array) $expectedValues[$parameterKey];
// find the actual params
$actualValues = array_merge($expectedValues, array($parameterKey => array()));
if ($exists) {
$existingValues = $yamlParser->parse(file_get_contents($realFile));
if ($existingValues === null) {
$existingValues = array();
}
if (!is_array($existingValues)) {
throw new \InvalidArgumentException(sprintf('The existing "%s" file does not contain an array', $realFile));
}
$actualValues = array_merge($actualValues, $existingValues);
}
$actualValues[$parameterKey] = $this->processParams($config, $expectedParams, (array) $actualValues[$parameterKey]);
if (!is_dir($dir = dirname($realFile))) {
mkdir($dir, 0755, true);
}
file_put_contents($realFile, "# This file is auto-generated during the composer install\n" . Yaml::dump($actualValues, 99));
}
示例6: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
if (NULL !== ($file = $input->getOption('file'))) {
if (is_file($file) && !$input->getOption('overwrite')) {
$output->writeln(sprintf('File <info>%s</info> already exists, use option <comment>-o</comment> to overwrite it.', $file));
return;
}
$backup = $output;
$fp = fopen($file, 'wb');
$output = new StreamOutput($fp);
}
$request = new HttpRequest(new Uri('http://test.me/'));
$this->requestScope->enter($request);
try {
$output->writeln('routes:');
$routes = $this->router->getRoutes($this->context)->getSortedRoutes();
foreach (array_reverse($routes) as $name => $route) {
$output->writeln(sprintf(' %s:', $name));
foreach (explode("\n", trim(Yaml::dump($route->toArray($this->context), 100))) as $line) {
$output->writeln(sprintf(' %s', $line));
}
}
} finally {
$this->requestScope->leave($request);
}
if (isset($fp) && is_resource($fp)) {
@fclose($fp);
$backup->writeln(sprintf('Config dumped to <info>%s</info>', $file));
}
}
示例7: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
if (empty($input->getOption('save-config'))) {
return true;
}
$configFilePath = $this->getLocalConfigFilePath();
$config = file_exists($configFilePath) ? Yaml::parse(file_get_contents($configFilePath)) : [];
$commandName = $this->getName();
if (empty($config[$commandName])) {
$config[$commandName] = [];
}
$commandConfig = $config[$commandName];
$options = array_filter($this->getDefinition()->getOptions(), function (InputOption $option) {
return $option->getName() !== 'save-config';
});
/** @var InputOption $option */
foreach ($options as $option) {
$optionName = $option->getName();
$optionValue = $input->getOption($optionName);
if (empty($optionValue)) {
continue;
}
$commandConfig[$optionName] = $optionValue;
}
$config[$commandName] = $commandConfig;
$yamlDump = Yaml::dump($config);
file_put_contents($configFilePath, $this->getConfigFilePrefix() . "\n\n" . $yamlDump);
$output->writeln('<info>[' . $commandName . '] command configuration saved to [' . $configFilePath . '] file.</info>');
}
示例8: writeConfig
public function writeConfig($destinationDir = null)
{
if (!$destinationDir) {
$destinationDir = Platform::rootDir();
}
return file_put_contents($destinationDir . '/' . self::PLATFORM_CONFIG, Yaml::dump($this->config, 2));
}
示例9: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
if (null === ($name = $input->getArgument('name'))) {
$this->listBundles($io);
$io->comment('Provide the name of a bundle as the first argument of this command to dump its configuration. (e.g. <comment>debug:config FrameworkBundle</comment>)');
$io->comment('For dumping a specific option, add its path as the second argument of this command. (e.g. <comment>debug:config FrameworkBundle serializer</comment> to dump the <comment>framework.serializer</comment> configuration)');
return;
}
$extension = $this->findExtension($name);
$container = $this->compileContainer();
$extensionAlias = $extension->getAlias();
$configs = $container->getExtensionConfig($extensionAlias);
$configuration = $extension->getConfiguration($configs, $container);
$this->validateConfiguration($extension, $configuration);
$configs = $container->getParameterBag()->resolveValue($configs);
$processor = new Processor();
$config = $processor->processConfiguration($configuration, $configs);
if (null === ($path = $input->getArgument('path'))) {
$io->title(sprintf('Current configuration for %s', $name === $extensionAlias ? sprintf('extension with alias "%s"', $extensionAlias) : sprintf('"%s"', $name)));
$io->writeln(Yaml::dump(array($extensionAlias => $config), 10));
return;
}
try {
$config = $this->getConfigForPath($config, $path, $extensionAlias);
} catch (LogicException $e) {
$io->error($e->getMessage());
return;
}
$io->title(sprintf('Current configuration for "%s.%s"', $extensionAlias, $path));
$io->writeln(Yaml::dump($config, 10));
}
示例10: execute
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$name = $input->getArgument('name');
if (empty($name)) {
$this->listBundles($output);
return;
}
$extension = $this->findExtension($name);
$kernel = $this->getContainer()->get('kernel');
$method = new \ReflectionMethod($kernel, 'buildContainer');
$method->setAccessible(true);
$container = $method->invoke($kernel);
$configs = $container->getExtensionConfig($extension->getAlias());
$configuration = $extension->getConfiguration($configs, $container);
$this->validateConfiguration($extension, $configuration);
$configs = $container->getParameterBag()->resolveValue($configs);
$processor = new Processor();
$config = $processor->processConfiguration($configuration, $configs);
if ($name === $extension->getAlias()) {
$output->writeln(sprintf('# Current configuration for extension with alias: "%s"', $name));
} else {
$output->writeln(sprintf('# Current configuration for "%s"', $name));
}
$output->writeln(Yaml::dump(array($extension->getAlias() => $config), 3));
}
示例11: testLoad
/**
* Tests success case for loading a valid and readable YAML file.
*
* @covers ::load
*/
public function testLoad()
{
$initialContent = ['hello' => 'world'];
$ymlContent = Yaml::dump($initialContent);
vfsStream::create(['file1' => $ymlContent], $this->root);
$this->assertEquals($initialContent, (new YamlFileLoader())->load(vfsStream::url('test/file1')));
}
示例12: dump
/**
* Dumps an array into the parameters.yml file.
*
* @param array $config
*/
public function dump(array $config, $mode = 0777)
{
$values = ['parameters' => array_merge($this->getConfigValues(), $config)];
$yaml = Yaml::dump($values);
$this->fileSystem->dumpFile($this->configFile, $yaml, $mode);
$this->fileSystem->remove(sprintf('%s/%s.php', $this->kernel->getCacheDir(), $this->kernel->getContainerCacheClass()));
}
示例13: doExecute
/**
* {@inheritdoc}
*/
protected function doExecute(InputInterface $input, OutputInterface $output)
{
$paths = $this->extractPath($this->container->getApplicationBox());
foreach ($paths as $path) {
$this->container['filesystem']->mkdir($path);
}
$type = strtolower($input->getArgument('type'));
$enabled = $input->getOption('enabled');
$factory = new H264Factory($this->container['monolog'], true, $type, $this->computeMapping($paths));
$mode = $factory->createMode(true);
$currentConf = isset($this->container['phraseanet.configuration']['h264-pseudo-streaming']) ? $this->container['phraseanet.configuration']['h264-pseudo-streaming'] : [];
$currentMapping = isset($currentConf['mapping']) && is_array($currentConf['mapping']) ? $currentConf['mapping'] : [];
$conf = ['enabled' => $enabled, 'type' => $type, 'mapping' => $mode->getMapping()];
if ($input->getOption('write')) {
$output->write("Writing configuration ...");
$this->container['phraseanet.configuration']['h264-pseudo-streaming'] = $conf;
$output->writeln(" <info>OK</info>");
$output->writeln("");
$output->write("It is now strongly recommended to use <info>h264-pseudo-streaming:dump-configuration</info> command to upgrade your virtual-host");
} else {
$output->writeln("Configuration will <info>not</info> be written, use <info>--write</info> option to write it");
$output->writeln("");
$output->writeln(Yaml::dump(['h264-pseudo-streaming' => $conf], 4));
}
return 0;
}
示例14: execute
public function execute(InputInterface $input, OutputInterface $output)
{
$suite = $input->getArgument('suite');
$guy = $input->getArgument('guy');
$config = \Codeception\Configuration::config($input->getOption('config'));
$dir = \Codeception\Configuration::projectDir() . $config['paths']['tests'] . DIRECTORY_SEPARATOR;
if (file_exists($dir . DIRECTORY_SEPARATOR . $suite)) {
throw new \Exception("Directory {$suite} already exists.");
}
if (file_exists($dir . $suite . '.suite.yml')) {
throw new \Exception("Suite configuration file '{$suite}.suite.yml' already exists.");
}
@mkdir($dir . DIRECTORY_SEPARATOR . $suite);
// generate bootstrap
file_put_contents($dir . DIRECTORY_SEPARATOR . $suite . '/_bootstrap.php', "<?php\n// Here you can initialize variables that will for your tests\n");
if (strpos(strrev($guy), 'yuG') !== 0) {
$guy = $guy . 'Guy';
}
$guyname = substr($guy, 0, -3);
// generate helper
file_put_contents(\Codeception\Configuration::projectDir() . $config['paths']['helpers'] . DIRECTORY_SEPARATOR . $guyname . 'Helper.php', "<?php\nnamespace Codeception\\Module;\n\n// here you can define custom functions for {$guy} \n\nclass {$guyname}Helper extends \\Codeception\\Module\n{\n}\n");
$conf = array('class_name' => $guy, 'modules' => array('enabled' => array($guyname . 'Helper')));
file_put_contents($dir . $suite . '.suite.yml', Yaml::dump($conf, 2));
$output->writeln("<info>Suite {$suite} generated</info>");
}
示例15: makeConfigTemplates
protected function makeConfigTemplates()
{
$json_options = 0;
if (defined('JSON_PRETTY_PRINT')) {
$json_options = $json_options | JSON_PRETTY_PRINT;
}
if (defined('JSON_UNESCAPED_SLASHES')) {
$json_options = $json_options | JSON_UNESCAPED_SLASHES;
}
$templates = array();
foreach ($this->config as $file => $rawContents) {
$ext = pathinfo($file, PATHINFO_EXTENSION);
if ($ext == 'dist') {
$fileSubName = substr($file, 0, strlen($file) - 5);
$ext = pathinfo($fileSubName, PATHINFO_EXTENSION);
}
switch ($ext) {
case 'yml':
$contents = $this->yamlPretty(Yaml::dump($rawContents, 3));
break;
case 'json':
$contents = json_encode($rawContents, $json_options);
break;
default:
if (is_scalar($rawContents)) {
$contents = $rawContents;
} else {
throw new \RuntimeException('Unable to identify config file parser for ' . $file);
}
}
$templates[$file] = $contents;
}
return $templates;
}