本文整理汇总了PHP中Symfony\Component\Yaml\Yaml类的典型用法代码示例。如果您正苦于以下问题:PHP Yaml类的具体用法?PHP Yaml怎么用?PHP Yaml使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Yaml类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __invoke
/**
* Update wp-cli.yml with settings from .env files
*
* ## OPTIONS
*
* <environment>
* : The name of the environment to set. Typically matched by a .env-<environemnt> file in the project root
*
* @param $args
* @param $assocArgs
*
* @when before_wp_load
*/
public function __invoke($args, $assocArgs)
{
$environment = $args[0];
if (file_exists(WPBOOT_BASEPATH . "/.env")) {
$dotEnv = new Dotenv(WPBOOT_BASEPATH);
$dotEnv->load();
}
$file = '.env-' . $environment;
if (file_exists(WPBOOT_BASEPATH . "/{$file}")) {
$dotEnv = new Dotenv(WPBOOT_BASEPATH, $file);
$dotEnv->overload();
}
try {
$dotEnv = new Dotenv(__DIR__);
$dotEnv->required('wppath');
} catch (\Exception $e) {
echo $e->getMessage() . "\n";
return;
}
$runner = WP_CLI::get_runner();
$ymlPath = $runner->project_config_path;
$yaml = new Yaml();
$config = $yaml->parse(file_get_contents($ymlPath));
$config['path'] = $_ENV['wppath'];
$config['environment'] = $environment;
$dumper = new Dumper();
file_put_contents($ymlPath, $dumper->dump($config, 2));
}
示例2: generateRestRouting
public function generateRestRouting(BundleInterface $bundle, $controller)
{
$file = $bundle->getPath() . '/Resources/config/routing.rest.yml';
if (file_exists($file)) {
$content = file_get_contents($file);
} elseif (!is_dir($dir = $bundle->getPath() . '/Resources/config')) {
mkdir($dir);
}
$resource = $bundle->getNamespace() . "\\Controller\\" . $controller . 'Controller';
$name = strtolower(preg_replace('/([A-Z])/', '_\\1', $bundle->getName() . $controller . '_rest'));
$name_prefix = strtolower(preg_replace('/([A-Z])/', '_\\1', $bundle->getName() . '_api_'));
if (!isset($content)) {
$content = '';
} else {
$yml = new Yaml();
$route = $yml->parse($content);
if (isset($route[$name])) {
return false;
}
}
$content .= sprintf("\n%s:\n type: rest\n resource: %s\n name_prefix: %s\n", $name, $resource, $name_prefix);
$flink = fopen($file, 'w');
if ($flink) {
$write = fwrite($flink, $content);
if ($write) {
fclose($flink);
} else {
throw new \RunTimeException(sprintf('We cannot write into file "%s", has that file the correct access level?', $file));
}
} else {
throw new \RunTimeException(sprintf('Problems with generating file "%s", did you gave write access to that directory?', $file));
}
}
示例3: testAdd
public function testAdd()
{
global $testHelpers, $mockTerms;
$testHelpers->writeAppsettings(['keepDefaultContent' => true], 'yaml');
$yaml = new Yaml();
$app = $testHelpers->getAppWithMockCli();
Bootstrap::setApplication($app);
$m = new Commands\Menus();
$cli = $app['cli'];
$cli->launch_self_return = (object) ['return_code' => 0, 'stdout' => json_encode([(object) ['term_id' => 1, 'name' => 'Main menu', 'slug' => 'main', 'locations' => ['primary', 'footer'], 'count' => 2]])];
$m->add(array('main'), array());
$settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
$this->assertTrue(isset($settings['content']['menus']));
$this->assertEquals(1, count($settings['content']['menus']));
$this->assertEquals('main', $settings['content']['menus'][0]);
file_put_contents(WPBOOT_BASEPATH . '/appsettings.yml', "foobar: true\n");
$m->add(array(1), array());
$settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
$this->assertTrue(isset($settings['content']['menus']));
$this->assertEquals(1, count($settings['content']['menus']));
$this->assertEquals('main', $settings['content']['menus'][0]);
file_put_contents(WPBOOT_BASEPATH . '/appsettings.yml', "foobar: true\n");
$m->add(array(999), array());
$settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
$this->assertFalse(isset($settings['content']['menus']));
}
示例4: import
public function import()
{
$app = Bootstrap::getApplication();
$helpers = $app['helpers'];
$baseUrl = get_option('siteurl');
$yaml = new Yaml();
$dir = WPBOOT_BASEPATH . '/bootstrap/sidebars';
foreach ($helpers->getFiles($dir) as $sidebar) {
if (!is_dir(WPBOOT_BASEPATH . "/bootstrap/sidebars/{$sidebar}")) {
continue;
}
$subdir = WPBOOT_BASEPATH . "/bootstrap/sidebars/{$sidebar}";
$manifest = WPBOOT_BASEPATH . "/bootstrap/sidebars/{$sidebar}_manifest";
$newSidebar = new \stdClass();
$newSidebar->slug = $sidebar;
$newSidebar->items = array();
$newSidebar->meta = $yaml->parse(file_get_contents($manifest));
foreach ($newSidebar->meta as $key => $widgetRef) {
$widget = new \stdClass();
$parts = explode('-', $widgetRef);
$ord = end($parts);
$type = substr($widgetRef, 0, -1 * strlen('-' . $ord));
$widget->type = $type;
$widget->ord = $ord;
$widget->meta = $yaml->parse(file_get_contents($subdir . '/' . $widgetRef));
$newSidebar->items[] = $widget;
}
$this->sidebars[] = $newSidebar;
}
$helpers->fieldSearchReplace($this->sidebars, Bootstrap::NEUTRALURL, $baseUrl);
$this->process();
}
示例5: load
/**
* {@inheritdoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
$loader->load('forms.yml');
// We instanciate a new kernel and iterate on all it's bundles to load the victoire_core configs
$kernel = new \AppKernel('prod', false);
foreach ($kernel->registerBundles() as $bundle) {
$path = $bundle->getPath();
$yamlParser = new Yaml($container, $path . '/Resources/config/config.yml');
$victoireConfig = $yamlParser->parse($path . '/Resources/config/config.yml');
if (is_array($victoireConfig) && array_key_exists('victoire_core', $victoireConfig)) {
$config['widgets'] = array_merge($config['widgets'], $victoireConfig['victoire_core']['widgets'] ?: []);
}
}
$container->setParameter('victoire_core.cache_dir', $config['cache_dir']);
$container->setParameter('victoire_core.business_entity_debug', $config['business_entity_debug']);
if (array_key_exists('templates', $config)) {
$container->setParameter('victoire_core.templates', $config['templates']);
} else {
$container->setParameter('victoire_core.templates', '');
}
$container->setParameter('victoire_core.widgets', $config['widgets']);
$container->setParameter('victoire_core.layouts', $config['layouts']);
$container->setParameter('victoire_core.slots', $config['slots']);
$container->setParameter('victoire_core.user_class', $config['user_class']);
$container->setParameter('victoire_core.base_paths', $config['base_paths']);
$container->setParameter('victoire_core.base_paths', $config['base_paths']);
$container->setParameter('victoire_core.businessTemplates', $config['businessTemplates']);
}
示例6: loadFileToBag
/**
* Loads a file configuration to a bag
*
* @param string $filename
* @param string $root
* @param BagInterface $bag
* @param boolean $recursive
* @param boolean $suppressException
*
* @return BagInterface
*
* @throws ConfigurationException
* @throws FileNotFoundException
*/
public function loadFileToBag($filename, $root, BagInterface $bag, $recursive = false, $suppressException = false)
{
// Check for the files' existence.
if (!file_exists($filename)) {
// Just return the bag if exception is suppressed.
if ($suppressException === true) {
return $bag;
}
// Throw a file not found error.
throw FileNotFoundException::configurationFileNotFoundException($filename);
}
// Parse YAML file.
$yaml = new Yaml();
$config = $yaml->parse(file_get_contents($filename));
// Check if the root exists.
if ($root !== null && !array_key_exists($root, $config)) {
// Just return the bag if exception is suppressed.
if ($suppressException === true) {
return $bag;
}
// Throw a file root not found error.
throw ConfigurationException::configurationFileRootNotFoundException($filename, $root);
}
// Point to the root.
if ($root !== null) {
$config = $config[$root];
}
// Load values to the bag and return it.
return $this->loadToBag($bag, is_array($config) ? $config : array(), $recursive);
}
示例7: testAdd
public function testAdd()
{
global $testHelpers, $mockPosts;
$testHelpers->writeAppsettings(['keepDefaultContent' => true], 'yaml');
$yaml = new Yaml();
\WP_Mock::wpFunction('get_post', ['times' => '1', 'return' => (object) $mockPosts['testpost1']]);
\WP_Mock::wpFunction('get_posts', ['times' => '1', 'return' => [(object) $mockPosts['testpost1']]]);
$app = $testHelpers->getAppWithMockCli();
Bootstrap::setApplication($app);
$cli = $app['cli'];
$p = new Commands\Posts();
$p->add(array(10), array());
$settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
$this->assertTrue(isset($settings['content']['posts']['post']));
$this->assertEquals(1, count($settings['content']['posts']['post']));
$this->assertEquals('testpost1', $settings['content']['posts']['post'][0]);
file_put_contents(WPBOOT_BASEPATH . '/appsettings.yml', "foobar: true\n");
$p->add(array('testpost1'), array());
$settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
$this->assertTrue(isset($settings['content']['posts']['post']));
$this->assertEquals(1, count($settings['content']['posts']['post']));
$this->assertEquals('testpost1', $settings['content']['posts']['post'][0]);
\WP_Mock::wpFunction('get_posts', ['times' => '1', 'return' => false]);
file_put_contents(WPBOOT_BASEPATH . '/appsettings.yml', "foobar: true\n");
$p->add(array('testpost1'), array());
$settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
$this->assertFalse(isset($settings['content']['posts']['post']));
}
示例8: import
public function import()
{
$app = Bootstrap::getApplication();
$settings = $app['settings'];
$yaml = new Yaml();
$helpers = $app['helpers'];
$baseUrl = get_option('siteurl');
if (!isset($settings['content']['menus'])) {
return;
}
foreach ($settings['content']['menus'] as $menu) {
$dir = WPBOOT_BASEPATH . "/bootstrap/menus/{$menu}";
$menuMeta = $yaml->parse(file_get_contents(WPBOOT_BASEPATH . "/bootstrap/menus/{$menu}_manifest"));
$newMenu = new \stdClass();
$newMenu->slug = $menu;
$newMenu->locations = $menuMeta['locations'];
$newMenu->items = array();
foreach ($helpers->getFiles($dir) as $file) {
$menuItem = new \stdClass();
$menuItem->done = false;
$menuItem->id = 0;
$menuItem->parentId = 0;
$menuItem->slug = $file;
//$menuItem->menu = unserialize(file_get_contents($dir.'/'.$file));
$menuItem->menu = $yaml->parse(file_get_contents("{$dir}/{$file}"));
$newMenu->items[] = $menuItem;
}
usort($newMenu->items, function ($a, $b) {
return (int) $a->menu['menu_order'] - (int) $b->menu['menu_order'];
});
$this->menus[] = $newMenu;
}
$helpers->fieldSearchReplace($this->menus, Bootstrap::NEUTRALURL, $baseUrl);
$this->process();
}
示例9: prepend
/**
* @param ContainerBuilder $container
*
* @return void
*/
public function prepend(ContainerBuilder $container)
{
// Build fos_elastica config for each widget
$elasticaConfig = [];
$kernel = new \AppKernel('prod', false);
$yamlParser = new Yaml();
foreach ($kernel->registerBundles() as $bundle) {
/* @var Bundle $bundle */
$path = $bundle->getPath();
//If bundle is a widget
if (0 === strpos($bundle->getNamespace(), 'Victoire\\Widget\\')) {
//find for a fos_elastica.yml config file
$widgetConfig = $yamlParser->parse($path . '/Resources/config/config.yml');
if (is_array($widgetConfig)) {
foreach ($widgetConfig['victoire_core']['widgets'] as $_widgetConfig) {
if (array_key_exists('fos_elastica', $widgetConfig)) {
$_config = ['indexes' => ['widgets' => ['types' => [$_widgetConfig['name'] => ['serializer' => ['groups' => ['search']], 'mappings' => [], 'persistence' => ['driver' => 'orm', 'model' => $_widgetConfig['class'], 'provider' => [], 'listener' => [], 'finder' => []]]]]]];
$_config = array_merge_recursive($widgetConfig['fos_elastica'], $_config);
$elasticaConfig = array_merge_recursive($elasticaConfig, $_config);
}
}
}
}
}
foreach ($container->getExtensions() as $name => $extension) {
switch ($name) {
case 'fos_elastica':
$container->prependExtensionConfig($name, $elasticaConfig);
break;
}
}
}
示例10: testAdd
public function testAdd()
{
global $testHelpers, $mockTerms;
$testHelpers->writeAppsettings(['keepDefaultContent' => true], 'yaml');
$yaml = new Yaml();
\WP_Mock::wpFunction('get_term_by', ['times' => '2', 'return' => (object) $mockTerms['catTerm1']]);
$app = $testHelpers->getAppWithMockCli();
Bootstrap::setApplication($app);
$t = new Commands\Taxonomies();
$t->add(array('category', 21), array());
$settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
$this->assertTrue(isset($settings['content']['taxonomies']['category']));
$this->assertEquals(1, count($settings['content']['taxonomies']['category']));
$this->assertEquals('catTerm1', $settings['content']['taxonomies']['category'][0]);
file_put_contents(WPBOOT_BASEPATH . '/appsettings.yml', "foobar: true\n");
$t->add(array('category', 'catTerm1'), array());
$settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
$this->assertTrue(isset($settings['content']['taxonomies']['category']));
$this->assertEquals(1, count($settings['content']['taxonomies']['category']));
$this->assertEquals('catTerm1', $settings['content']['taxonomies']['category'][0]);
file_put_contents(WPBOOT_BASEPATH . '/appsettings.yml', "foobar: true\n");
$t->add(array('category', '*'), array());
$settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
$this->assertTrue(isset($settings['content']['taxonomies']['category']));
$this->assertEquals(1, count($settings['content']['taxonomies']['category']));
$this->assertEquals('*', $settings['content']['taxonomies']['category'][0]);
\WP_Mock::wpFunction('get_term_by', ['times' => '1', 'return' => false]);
file_put_contents(WPBOOT_BASEPATH . '/appsettings.yml', "foobar: true\n");
$t->add(array('category', 'yadayada'), array());
$settings = $yaml->parse(WPBOOT_BASEPATH . '/appsettings.yml');
$this->assertFalse(isset($settings['content']['taxonomies']['category']));
}
示例11: __construct
/**
* @param string $file
*/
public function __construct($file)
{
$yaml = new Yaml();
$file = (array) $yaml->parse($file, true);
$this->validateFileStructure($file);
$this->file = $file;
}
示例12: setUp
protected function setUp()
{
$yaml = new Yaml();
$config = $yaml->parse(file_get_contents('tests/SimpleMailReceiver/test_config.yml'));
//tests/SimpleMailReceiver/test_config.yml
$imap_res = imap_open('{' . $config['host'] . ':' . $config['port'] . '/imap/ssl}INBOX', $config['username'], $config['password']);
$this->mailer = new Mailserver($imap_res, new \SimpleMailReceiver\Exceptions\ExceptionThrower());
}
示例13: __construct
public function __construct(GruverConfig $config)
{
$this->config = $config;
$this->options = array();
$yaml = new Yaml();
$this->options = array_merge($this->options, $yaml->parse(__DIR__ . '/../Resources/data/fixture-animals.yml'));
$this->options = array_merge($this->options, $yaml->parse(__DIR__ . '/../Resources/data/fixture-colors.yml'));
}
示例14: getProcessedConfiguration
private function getProcessedConfiguration($source)
{
$loader = new Yaml();
$data = $loader->parse($source);
$configuration = new CacheNodeBuilder();
$processor = new Processor();
return $processor->processConfiguration($configuration, $data);
}
示例15: yamlToArray
private function yamlToArray($file, Yaml $loader)
{
$data = $loader->parse($file);
if (!$data) {
$data = [];
}
return $data;
}