作者:eriktorsne
项目:wp-bootstra
/**
* 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));
}
作者:amstaffi
项目:extjs-bundl
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));
}
}
作者:eriktorsne
项目:wp-bootstrap-tes
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']));
}
作者:eriktorsne
项目:wp-bootstra
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();
}
作者:victoir
项目:victoir
/**
* {@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']);
}
作者:ebidtec
项目:console-applicatio
/**
* 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);
}
作者:eriktorsne
项目:wp-bootstrap-tes
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']));
}
作者:eriktorsne
项目:wp-bootstra
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();
}
作者:Charlie-Luca
项目:WidgetSearchBundl
/**
* @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;
}
}
}
作者:eriktorsne
项目:wp-bootstrap-tes
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']));
}
作者:nilportugue
项目:php-todo-finde
/**
* @param string $file
*/
public function __construct($file)
{
$yaml = new Yaml();
$file = (array) $yaml->parse($file, true);
$this->validateFileStructure($file);
$this->file = $file;
}
作者:kanusoftwar
项目:php-simplemail-receive
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());
}
作者:mindgruv
项目:gruve
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'));
}
作者:aztech-de
项目:phraseanet-bundl
private function getProcessedConfiguration($source)
{
$loader = new Yaml();
$data = $loader->parse($source);
$configuration = new CacheNodeBuilder();
$processor = new Processor();
return $processor->processConfiguration($configuration, $data);
}
作者:francodacost
项目:caparic
private function yamlToArray($file, Yaml $loader)
{
$data = $loader->parse($file);
if (!$data) {
$data = [];
}
return $data;
}
作者:bburnicho
项目:rest-bundl
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')));
}
作者:kanusoftwar
项目:php-simplemail-receive
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();
}
作者:kanusoftwar
项目:php-simplemail-receive
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();
}
作者:bosonsymfon
项目:excepciones-bundl
/**
* 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;
}
作者:aik09
项目:PhpMetric
/**
* 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);
}