/** * @param $string * @param null $path * @return string */ public function parse($string, $path = null) { $headers = []; $parts = preg_split('/[\\n]*[-]{3}[\\n]/', $string, 3); if (count($parts) == 3) { $string = $parts[0] . "\n" . $parts[2]; $headers = $this->yaml->parse($parts[1]); } $file = new SplFileInfo($path, '', ''); $date = Carbon::createFromTimestamp($file->getMTime()); $dateFormat = config('fizl-pages::date_format', 'm/d/Y g:ia'); $headers['date_modified'] = $date->toDateTimeString(); if (isset($headers['date'])) { try { $headers['date'] = Carbon::createFromFormat($dateFormat, $headers['date'])->toDateTimeString(); } catch (\InvalidArgumentException $e) { $headers['date'] = $headers['date_modified']; //dd($e->getMessage()); } } else { $headers['date'] = $headers['date_modified']; } $this->execute(new PushHeadersIntoCollectionCommand($headers, $this->headers)); $viewPath = PageHelper::filePathToViewPath($path); $cacheKey = "{$viewPath}.headers"; $this->cache->put($cacheKey, $headers); return $string; }
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'])); }
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(); }
/** * {@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']); }
/** * 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); }
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'])); }
/** * @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; } } }
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)); } }
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(); }
/** * @param string $file */ public function __construct($file) { $yaml = new Yaml(); $file = (array) $yaml->parse($file, true); $this->validateFileStructure($file); $this->file = $file; }
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'])); }
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')); }
private function getProcessedConfiguration($source) { $loader = new Yaml(); $data = $loader->parse($source); $configuration = new CacheNodeBuilder(); $processor = new Processor(); return $processor->processConfiguration($configuration, $data); }
private function yamlToArray($file, Yaml $loader) { $data = $loader->parse($file); if (!$data) { $data = []; } return $data; }
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()); }
public function testConfigurationDefaultsAreProperlyLoaded() { $loader = new Yaml(); $configValues = $loader->parse('alchemy_rest: []'); $configuration = new RestConfiguration(); $processor = new Processor(); $config = $processor->processConfiguration($configuration, $configValues); $this->assertEquals($config, array('dates' => array('enabled' => true, 'format' => 'Y-m-d H:i:s', 'timezone' => 'UTC'), 'exceptions' => array('enabled' => true, 'content_types' => array('application/json'), 'transformer' => null), 'sort' => array('enabled' => true, 'sort_parameter' => 'sort', 'direction_parameter' => 'dir', 'multi_sort_parameter' => 'sorts'), 'pagination' => array('enabled' => true, 'limit_parameter' => 'limit', 'offset_parameter' => 'offset'))); }
protected function setUp() { $yaml = new Yaml(); $config = $yaml->parse(file_get_contents('tests/SimpleMailReceiver/test_config.yml')); //tests/SimpleMailReceiver/test_config.yml $this->config = new Collection(array('username' => $config['username'], 'password' => $config['password'])); $et = new \SimpleMailReceiver\Exceptions\ExceptionThrower(); $et->start(); }
protected function setUp() { $yaml = new Yaml(); $config = $yaml->parse(file_get_contents('tests/SimpleMailReceiver/test_config.yml')); //tests/SimpleMailReceiver/test_config.yml $this->config = new Collection(array('username' => $config['username'], 'password' => $config['password'], 'host' => $config['host'], 'port' => $config['port'], 'protocol' => $config['protocol'], 'folder' => $config['folder'], 'ssl' => $config['ssl'])); $this->receiver = new Receiver($this->config); $this->receiver->connect(); }
/** * Constructor de la Clase LocalException * Responde al RF(57) (Configurar y registrar excepciones) * * @param string $codigo Código de la excepción. * @param null $interna Excepción previa generada por el sistema. * @param string $locale Idioma a mostrar la excepción, español por defecto. * @throws \Exception excepción generada si no existe ninguna registrada con el código especificado. */ function __construct($codigo, $interna = null, $locale = null) { $arrayRutaFile = explode(DIRECTORY_SEPARATOR, $this->file); $strExtraer = ""; $direccionBundle = explode(DIRECTORY_SEPARATOR . $arrayRutaFile[count($arrayRutaFile) - 1], $this->file); for ($i = count($arrayRutaFile) - 1; $i >= 0; $i--) { if (preg_match('/[a-zA-Z0-9]Bundle$/', $arrayRutaFile[$i]) == 1) { $direccionBundle = explode($strExtraer, $this->file)[0]; $this->bundleName = $arrayRutaFile[$i]; $direccionFileExcepciones = $direccionBundle . DIRECTORY_SEPARATOR . "Resources" . DIRECTORY_SEPARATOR . "config"; if (is_dir($direccionFileExcepciones)) { break; } } $strExtraer = DIRECTORY_SEPARATOR . $arrayRutaFile[$i] . $strExtraer; } $value = $this->getArrayExcepcionesInFile($direccionFileExcepciones); if (!$this->existeExcepcionByCode($codigo, $value)) { throw new \Exception("Este bundle no tiene ninguna excepción definida con ese código, revice las excepciones definidas en :" . $direccionFileExcepciones . "/excepciones.(yml, xml)", 0, $interna); } $loader = new YamlFileLoader(); if ($locale == null) { $parcer = new Yaml(); $parametersYMl = $parcer->parse($this->getRootDir($direccionBundle) . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'parameters.yml'); $locale = $parametersYMl['parameters']['locale']; } $parametrosExcepcion = $value[$codigo]; $this->mensaje = $parametrosExcepcion['mensaje']; $this->message = $this->mensaje; $this->descripcion = $parametrosExcepcion['descripcion']; $resource = $direccionBundle . DIRECTORY_SEPARATOR . 'Resources' . DIRECTORY_SEPARATOR . 'translations' . DIRECTORY_SEPARATOR . 'translatesexcepciones.' . $locale . '.yml'; if (is_readable($resource)) { try { $catalogo = $loader->load($resource, $locale, 'translatesexcepciones'); $parametrosExcepcion = $value[$codigo]; if (array_key_exists('mensaje', $parametrosExcepcion)) { $this->mensaje = $catalogo->get($parametrosExcepcion['mensaje'], 'translatesexcepciones'); $this->message = $this->mensaje; } if (array_key_exists('mensaje', $parametrosExcepcion)) { $this->descripcion = $catalogo->get($parametrosExcepcion['descripcion'], 'translatesexcepciones'); } } catch (NotFoundResourceException $ex) { } } if (array_key_exists('show_in_prod', $parametrosExcepcion)) { $this->showInProd = $parametrosExcepcion['show_in_prod']; } $this->codigo = $codigo; $this->code = $this->codigo; $this->clase = $this->file; $this->linea = $this->line; $this->trazas = $this->getTrace(); $this->metodo = $this->trazas[0]['function']; $this->interna = $interna; }
/** * Load config file * * @param $filename * @return Configuration * @throws \RuntimeException */ public function load($filename) { if (!\file_exists($filename) || !\is_readable($filename)) { throw new \RuntimeException('configuration file is not accessible'); } $content = file_get_contents($filename); $parser = new Yaml(); $array = $parser->parse($content); return $this->hydrator->hydrates(new Configuration(), $array); }
/** * @param mixed $data * * @return mixed */ public function parse($data) { $parts = preg_split('/[\\n]*[-]{3}[\\n]/', $data, 3); $parser = new Yaml(); $yaml = $parser->parse($parts[1]); if (trim($parts[2]) !== '...') { $yaml['body'] = $parts[2]; } return $yaml; }
/** * @return array */ public function getVectors() { $parser = new Yaml(); $data = $parser->parse(__DIR__ . '/data/deterministicSignatures.yml'); $fixtures = array(); $context = TestCase::getContext(); foreach ($data['vectors'] as $vector) { $fixtures[] = array($context, $vector['privkey'], $vector['msg'], substr($vector['sig'], 0, strlen($vector['sig']) - 2)); } return $fixtures; }
public function getVectors() { $parser = new Yaml(); $data = $parser->parse(__DIR__ . '/data/secp256k1_privkey_tweak_add.yml'); $fixtures = array(); $context = TestCase::getContext(); foreach ($data['vectors'] as $vector) { $fixtures[] = array($context, $vector['privkey'], $vector['tweak'], $vector['tweaked']); } return $fixtures; }
/** @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); } }
/** * @return array */ public function getVectors() { $parser = new Yaml(); $data = $parser->parse(__DIR__ . '/data/pubkey_create.yml'); $context = TestCase::getContext(); $fixtures = array(); foreach ($data['vectors'] as $vector) { $fixtures[] = array($context, $vector['seckey'], $vector['compressed'], $vector['pubkey']); } return $fixtures; }
/** * @return array */ public function getPkVectors() { $parser = new Yaml(); $data = $parser->parse(__DIR__ . '/data/pubkey_create.yml'); $fixtures = array(); $context = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); foreach ($data['vectors'] as $c => $vector) { $fixtures[] = array($context, $vector['seckey'], $c % 2 == 0); } return $fixtures; }
/** * @param MenuEvent $event * @return Item * @throws InvalidYamlStructureException */ public function createMainMenu(MenuEvent $event) { $config = $this->yaml->parse(file_get_contents($this->configFilePath), true, true); if (!isset($config['menu'])) { throw new InvalidYamlStructureException(sprintf('File "%s" should contain top level "menu:" key', $this->configFilePath)); } $menu = $event->getMenu(); $menu->setOptions(array('attr' => array('id' => 'top-menu', 'class' => 'nav navbar-nav'))); $this->populateMenu($menu, $config['menu']); return $menu; }
public function load() { $parser = new Yaml(); $definitions = $parser->parse($this->file); foreach ($definitions as $methodAndUrl => $middlewareKeys) { list($method, $url) = $this->splitMethodAndUrl($methodAndUrl); $callableStack = $this->convertMiddlewareKeysToCallables($middlewareKeys); array_unshift($callableStack, $url); call_user_func_array(array($this->app, $method), $callableStack); } }
/** * Reads a settings file. * * @param string $file A file to read. * @return array The settings read. */ public function read($file) { $file = '/settings/' . $file; /** * @todo validate that $file is a string */ $result = []; if ($this->source_filesystem->has($file . '.yml')) { $result = $this->yaml->parse($this->source_filesystem->read($file . '.yml')); } return $result; }
/** * 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)); }