public function setUp() { $kernel = static::createKernel(); $kernel->boot(); if ($kernel->getContainer()->getParameter('database_driver') == 'pdo_sqlite') { $this->markTestSkipped("The SQLite does not support joins."); } $this->em = $kernel->getContainer()->get('knp_bundles.entity_manager'); $fileLocator = new FileLocator(__DIR__ . '/fixtures/'); $path = $fileLocator->locate('trending-bundles.yml'); $data = Yaml::parse($path); $developer = new Developer(); $developer->setName('someName'); $developer->setScore(0); $this->em->persist($developer); foreach ($data['bundles'] as $bundleName => $bundleData) { $bundle = new Bundle('vendor/' . $bundleName); $bundle->setDescription('some description'); $bundle->setScore(100); $bundle->setOwner($developer); foreach ($bundleData['scores'] as $scoreData) { $bundle->setDescription(md5(time() . serialize($scoreData))); $score = new Score(); $score->setDate(new \DateTime($scoreData['date'])); $score->setBundle($bundle); $score->setValue($scoreData['value']); $this->em->persist($score); } $this->em->persist($bundle); } $this->em->flush(); }
/** * Loads the config */ private function loadConfig() { $directories = [BASE_DIR . '/config', '/etc/blackhole-bot/']; $locator = new FileLocator($directories); $loader = new YamlConfigLoader($locator); $this->container->set('config', (new Processor())->processConfiguration($this, $loader->load($locator->locate('blackhole.yml')))); }
/** * @return DatabaseBackupStrategyModel[] */ public function collectDatabasesStrategies() { $fileLocator = new FileLocator(__DIR__ . '/../../../app/config'); try { $fileStrategies = $fileLocator->locate('strategies.yml'); } catch (InvalidArgumentException $ex) { /* No strategies file detected? No strategies then. :=) */ return []; } $strategies = file_get_contents($fileStrategies); $config = Yaml::parse($strategies); $config = $config['easy_backups']; $processor = new Processor(); $configuration = new DatabaseStrategyConfiguration(); $validatedConfig = $processor->processConfiguration($configuration, [$config]); $strategies = []; if (isset($validatedConfig['strategies'])) { foreach ($validatedConfig['strategies'] as $strategyConfig) { $strategy = new DatabaseBackupStrategyModel($strategyConfig['identifier'], $strategyConfig['compressor_strategy'], $strategyConfig['saver_strategy'], $strategyConfig['dump_settings']['type'], new DatabaseSettings($strategyConfig['dump_settings']['options']['host'], $strategyConfig['dump_settings']['options']['user'], $strategyConfig['dump_settings']['options']['pass'], $strategyConfig['dump_settings']['options']['name'], $strategyConfig['dump_settings']['options']['port'], $strategyConfig['dump_settings']['options']['ignore_tables'], $strategyConfig['dump_settings']['options']['one_dump_per_table'])); $strategy->setDescription($strategyConfig['description']); $strategies[] = $strategy; } } return $strategies; }
/** * @return array */ private static function getParameters() { $locator = new FileLocator(__DIR__ . '/../../../../'); $configLoc = $locator->locate('config.yml'); $config = Yaml::parse($configLoc); return $config['parameters']; }
/** * Initialize the service container (and extensions), and load the config file * * @param \Symfony\Component\Console\Input\InputInterface $input * @param \Symfony\Component\Console\Output\OutputInterface $output * * @throws \Exception if user-provided configuration file causes an error */ protected function initialize(InputInterface $input, OutputInterface $output) { $root = $input->getArgument('root'); // Setup container $containerBuilder = new ContainerBuilder(); $extension = new BrancherExtension(); $containerBuilder->registerExtension($extension); $containerBuilder->addCompilerPass(new ExtensionCompilerPass()); $containerBuilder->addCompilerPass(new RegisterListenersPass('event_dispatcher', 'brancher.event_listener', 'brancher.event_subscriber')); // Try and load config file $locator = new FileLocator([getcwd(), $input->getArgument('root'), __DIR__ . '/../']); /** @var \Symfony\Component\DependencyInjection\Loader\FileLoader $loader */ $loader = new DelegatingLoader(new LoaderResolver([new YamlFileLoader($containerBuilder, $locator), new XmlFileLoader($containerBuilder, $locator), new PhpFileLoader($containerBuilder, $locator), new IniFileLoader($containerBuilder, $locator)])); $config = null; try { $config = $locator->locate($input->getOption('config')); $loader->load($input->getOption('config')); } catch (\Exception $ex) { // Only rethrow if the issue was with the user-provided value if ($input->getOption('config') !== '_config.yml') { throw $ex; } } // Add in final config from command line options $containerBuilder->setParameter('castlepointanime.brancher.build.config', $config); $containerBuilder->loadFromExtension($extension->getAlias(), ['build' => array_filter(['config' => dirname($config) ?: $root, 'root' => $root, 'special' => $input->getOption('special'), 'output' => $input->getArgument('output'), 'templates' => array_filter(array_map('realpath', $input->getOption('template-dir')), 'is_dir'), 'data' => $input->getOption('data-dir'), 'exclude' => $input->getOption('exclude')])]); $containerBuilder->compile(); $this->setContainer($containerBuilder); }
protected function setConnection() { $fileLocator = new FileLocator(getcwd()); $configFile = $fileLocator->locate('rentgen.yml'); $config = Yaml::parse($configFile); $this->connection = new Connection(new ConnectionConfig($config['connection'])); }
/** * @param string $file * @return array */ public function loadConfig($file = self::DEFAULT_CONFIG) { $configDirectories = ['./']; $locator = new FileLocator($configDirectories); $file = $locator->locate($file); return json_decode(file_get_contents($file), true); }
/** * @expectedException \InvalidArgumentException */ public function testFileNotFound() { $configDirectories = array(FIXTURES_PATH); $locator = new FileLocator($configDirectories); $PhpLoader = new PhpLoader($locator); $PhpLoader->load($locator->locate('notFound.php')); }
/** * Loads the configuration file data. */ public function load($workingDir) { $locator = new FileLocator($this->getPotentialDirectories($workingDir)); $loader = new YamlLoader($locator); // Config validation. $processor = new Processor(); $schema = new BuddySchema(); $files = $locator->locate(static::FILENAME, NULL, FALSE); foreach ($files as $file) { // After loading the raw data from the yaml file, we validate given // configuration. $raw = $loader->load($file); $conf = $processor->processConfiguration($schema, array('buddy' => $raw)); if (isset($conf['commands'])) { foreach ($conf['commands'] as $command => $specs) { if (!isset($this->commands[$command])) { $this->commands[$command] = array('options' => $specs, 'file' => $file); } } } // In the case 'root' is set, we do not process any parent buddy files. if (!empty($values['root'])) { break; } } return $this; }
/** * {@inheritDoc} */ public function getStructureMetadata($type, $structureType = null) { $cacheKey = $type . $structureType; if (isset($this->cache[$cacheKey])) { return $this->cache[$cacheKey]; } $this->assertExists($type); if (!$structureType) { $structureType = $this->getDefaultStructureType($type); } if (!is_string($structureType)) { throw new \InvalidArgumentException(sprintf('Expected string for structureType, got: %s', is_object($structureType) ? get_class($structureType) : gettype($structureType))); } $cachePath = sprintf('%s/%s%s', $this->cachePath, Inflector::camelize($type), Inflector::camelize($structureType)); $cache = new ConfigCache($cachePath, $this->debug); if ($this->debug || !$cache->isFresh()) { $paths = $this->getPaths($type); // reverse paths, so that the last path overrides previous ones $fileLocator = new FileLocator(array_reverse($paths)); try { $filePath = $fileLocator->locate(sprintf('%s.xml', $structureType)); } catch (\InvalidArgumentException $e) { throw new Exception\StructureTypeNotFoundException(sprintf('Could not load structure type "%s" for document type "%s", looked in "%s"', $structureType, $type, implode('", "', $paths)), null, $e); } $metadata = $this->loader->load($filePath, $type); $resources = [new FileResource($filePath)]; $cache->write(sprintf('<?php $metadata = \'%s\';', serialize($metadata)), $resources); } require $cachePath; $structure = unserialize($metadata); $this->cache[$cacheKey] = $structure; return $structure; }
/** * {@inheritdoc} * @SuppressWarnings(PHPMD.StaticAccess) */ public function load() { $locator = new FileLocator($this->paths); $configFile = $locator->locate('pgca.yml'); $fileContents = Yaml::parse(file_get_contents($configFile), true); $this->config = new Data($fileContents); }
public function __construct($configFile) { $locator = new FileLocator(array(dirname($configFile))); $loader = new YamlLoader($locator); $processor = new Processor(); $this->configuration = $processor->processConfiguration(new Definition(), $loader->load($locator->locate(basename($configFile)))); }
/** * {@inheritdoc} */ public function execute(ImageInterface $image, $parameters) { $maskPath = isset($parameters['image']) ? $this->fileLocator->locate($parameters['image']) : null; if (!$maskPath) { return $image; } $originalWidth = $image->getSize()->getWidth(); $originalHeight = $image->getSize()->getHeight(); $top = isset($parameters['top']) ? $parameters['top'] : 0; $left = isset($parameters['left']) ? $parameters['left'] : 0; $width = isset($parameters['width']) ? $parameters['width'] : $originalWidth; $height = isset($parameters['height']) ? $parameters['height'] : $originalHeight; // imagine will error when mask is bigger then the given image // this could happen in forceRatio true mode so we need also scale the mask if ($width > $originalWidth) { $width = $originalWidth; $height = (int) ($height / $width * $originalWidth); } if ($height > $originalHeight) { $height = $originalHeight; $width = (int) ($width / $height * $originalHeight); } // create mask $mask = $this->createMask($maskPath, $width, $height); // add mask to image $image->paste($mask, new Point($top, $left)); return $image; }
/** * * @param string $configDirectories * @param string $configFiles * @param string $cachePath * @param bool $debug */ public function __construct($configDirectories, $configFiles, $cachePath, $debug = false) { $this->configDirectories = (array) $configDirectories; $this->configFiles = (array) $configFiles; $this->cachePath = $cachePath . '/faker_config.php'; $configCache = new ConfigCache($this->cachePath, $debug); if (!$configCache->isFresh()) { $locator = new FileLocator($this->configDirectories); $loaderResolver = new LoaderResolver([new YamlLoader($locator)]); $delegatingLoader = new DelegatingLoader($loaderResolver); $resources = []; $config = []; foreach ($this->configFiles as $configFile) { $path = $locator->locate($configFile); $config = array_merge($config, $delegatingLoader->load($path)); $resources[] = new FileResource($path); } $exportConfig = var_export($this->parseRawConfig(isset($config['faker']) ? $config['faker'] : []), true); $code = <<<PHP <?php return {$exportConfig}; PHP; $configCache->write($code, $resources); } if (file_exists($this->cachePath)) { $this->config = (include $this->cachePath); } }
/** * @param string $path the working directory for filesystem operations * * @throws \InvalidArgumentException * @throws IOException */ public function setWorkingDirectory($path) { $directory = preg_replace('#/+#', '/', $path); // remove multiple slashes try { $directory = $this->locator->locate($directory); if (false === is_string($directory)) { $directory = strval(reset($directory)); $this->logger->alert(sprintf('Ambiguous filename %s, choosing %s', $path, $directory)); } } catch (\InvalidArgumentException $exception) { // continue to check if dir exists even if locator doesn't locate } $exists = $this->filesystem->exists($directory); if (!$exists) { try { $this->filesystem->mkdir($directory); $this->logger->notice("Working directory created at " . $directory); } catch (IOException $exception) { $this->logger->error("An error occurred while creating directory at " . $exception->getPath(), $exception->getTrace()); throw $exception; } } $this->directory = $directory; }
/** * @expectedException \Symfony\Component\Yaml\Exception\ParseException */ public function testInvalid() { $configDirectories = array(FIXTURES_PATH); $locator = new FileLocator($configDirectories); $YamlLoader = new YamlLoader($locator); $YamlLoader->load($locator->locate('invalid.yml')); }
/** {@inheritdoc} */ public function prepend(ContainerBuilder $container) { $configs = Yaml::parse($this->fileLocator->locate('redis.yml')); foreach ($configs as $name => $config) { $container->prependExtensionConfig($name, $config); } }
/** * {@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'); } }
public function load(array $configs, ContainerBuilder $container) { foreach ($configs as $config) { if ($this->isConnectionConfig($config)) { $connectionConfig = $config; } } if ($container->hasParameter('connection_config')) { $connectionConfig = $container->getParameter('connection_config'); } $this->defineParameters($container); $definition = new Definition('Symfony\\Component\\EventDispatcher\\ContainerAwareEventDispatcher'); $definition->setArguments(array(new Reference('service_container'))); $container->setDefinition('event_dispatcher', $definition); $definition = new Definition('Rentgen\\Schema\\Manipulation'); $definition->setArguments(array(new Reference('service_container'))); $container->setDefinition('rentgen.schema.manipulation', $definition); $definition = new Definition('Rentgen\\Schema\\Info'); $definition->setArguments(array(new Reference('service_container'))); $container->setDefinition('rentgen.schema.info', $definition); if (!isset($connectionConfig)) { $fileLocator = new FileLocator(getcwd()); try { $configFile = $fileLocator->locate('rentgen.yml'); $content = file_get_contents('rentgen.yml'); $config = Yaml::parse($content); $connectionConfig = $config; } catch (\InvalidArgumentException $e) { $connectionConfig['environments']['dev'] = array('adapter' => 'pgsql', 'host' => 'localhost', 'database' => null, 'username' => 'postgres', 'password' => '', 'port' => 5432); } } $definition = new Definition('Rentgen\\Database\\Connection\\ConnectionConfig'); $definition->setArguments(array($connectionConfig['environments'])); $container->setDefinition('connection_config', $definition); $definition = new Definition('Rentgen\\Database\\Connection\\Connection'); $definition->setArguments(array(new Reference('connection_config'))); $container->setDefinition('connection', $definition); $this->connection = $container->getDefinition('connection'); $this->eventDispatcher = $container->getDefinition('event_dispatcher'); $this->setDefinition('rentgen.create_table', 'rentgen.command.manipulation.create_table.class', $container); $this->setDefinition('rentgen.drop_table', 'rentgen.command.manipulation.drop_table.class', $container); $this->setDefinition('rentgen.add_column', 'rentgen.command.manipulation.add_column.class', $container); $this->setDefinition('rentgen.drop_column', 'rentgen.command.manipulation.drop_column.class', $container); $this->setDefinition('rentgen.add_constraint', 'rentgen.command.manipulation.add_constraint.class', $container); $this->setDefinition('rentgen.drop_constraint', 'rentgen.command.manipulation.drop_constraint.class', $container); $this->setDefinition('rentgen.create_index', 'rentgen.command.manipulation.create_index.class', $container); $this->setDefinition('rentgen.create_schema', 'rentgen.command.manipulation.create_schema.class', $container); $this->setDefinition('rentgen.drop_schema', 'rentgen.command.manipulation.drop_schema.class', $container); $this->setDefinition('rentgen.drop_index', 'rentgen.command.manipulation.drop_index.class', $container); $this->setDefinition('rentgen.table_exists', 'rentgen.command.info.table_exists.class', $container); $this->setDefinition('rentgen.get_table', 'rentgen.command.info.get_table.class', $container); $this->setDefinition('rentgen.get_tables', 'rentgen.command.info.get_tables.class', $container); $this->setDefinition('rentgen.get_schemas', 'rentgen.command.info.get_schemas.class', $container); $this->setDefinition('rentgen.schema_exists', 'rentgen.command.info.schema_exists.class', $container); $definition = new Definition($container->getParameter('rentgen.command.manipulation.clear_database.class'), array(new Reference('rentgen.get_schemas'))); $definition->addMethodCall('setConnection', array(new Reference('connection'))); $definition->addMethodCall('setEventDispatcher', array(new Reference('event_dispatcher'))); $container->setDefinition('rentgen.clear_database', $definition); }
/** * Constructor * * @param string $configFileName * @param array $configDirectories */ public function __construct($configFileName, array $configDirectories = array('.')) { $this->configFileName = $configFileName; $this->configDirectories = $configDirectories; $locator = new FileLocator($this->configDirectories); $this->configFilePath = $locator->locate($this->configFileName); $this->parseAndValidateConfig(); }
function getConfig($yml) { $m = new FileLocator(PATH_CONFIG); $yaml = new Parser(); $file = $m->locate($yml); $parameters = $yaml->parse(file_get_contents($file)); return $parameters; }
public static function setUpBeforeClass() { $yamlParser = new YamlParser(); $file = new FileLocator(__DIR__ . '/../../Resources/config'); self::$iso3166 = $yamlParser->parse(file_get_contents($file->locate('iso3166-1-alpha-2.yml'))); self::$iso639 = array_merge($yamlParser->parse(file_get_contents($file->locate('iso639-1.yml'))), $yamlParser->parse(file_get_contents($file->locate('iso639-2.yml')))); self::$script = $yamlParser->parse(file_get_contents($file->locate('locale_script.yml'))); }
private static function prepareConfig() { $configDirectories = array(dirname(__FILE__) . '/../../config'); $locator = new FileLocator($configDirectories); $loaderResolver = new LoaderResolver(array(new \App\ConfigLoader($locator))); $ymlConfig = $locator->locate(dirname(__FILE__) . '/../../config/config.yml', null, false); return $loaderResolver->resolve($ymlConfig)->load($ymlConfig); }
public function testWarmUpEmpty() { $this->templateFinder->expects($this->once())->method('findAllTemplates')->will($this->returnValue(array())); $this->fileLocator->expects($this->never())->method('locate'); $warmer = new TemplatePathsCacheWarmer($this->templateFinder, $this->templateLocator); $warmer->warmUp($this->tmpDir); $this->assertFileExists($this->tmpDir . '/templates.php'); $this->assertSame(file_get_contents(__DIR__ . '/../Fixtures/TemplatePathsCache/templates-empty.php'), file_get_contents($this->tmpDir . '/templates.php')); }
public function __construct() { $locator = new FileLocator(array(__DIR__ . '/ServiceDescription')); $jsonLoader = new JsonLoader($locator); $description = $jsonLoader->load($locator->locate('services.json')); $headers = ['X-Mashape-Key' => 'dwOm8WpRxamshUJeTSKCuZJ9lWLkp1JPxzijsnejSHNGN7sz25', 'Accept' => 'text/plain']; $httpClient = new Client(['defaults' => ['headers' => $headers]]); $this->client = new GuzzleClient($httpClient, new Description($description)); }
/** * @param $configFile string * @param $paths string|array * * @return $this */ public function loadConfig($configFile, $paths) { $paths = (array) $paths; $fileLocator = new FileLocator($paths); $configLoader = $this->getConfigLoader(); $configLoader->parseFile($fileLocator->locate($configFile)); $configLoader->loadModules(); return $this; }
/** * @param string $filename * @return array|string */ protected function findBootstrapFile($filename) { if (null === $filename) { $filename = 'phpmig.php'; } $cwd = getcwd(); $locator = new FileLocator(array($cwd . DIRECTORY_SEPARATOR . 'config', $cwd)); return $locator->locate($filename); }
/** * Validates the received data with the given json schema * * @param Schema $annotation * @param array $data * * @throws JsonSchemaException */ public function validate(Schema $annotation, $data) { $schemaUrl = $this->fileLocator->locate($annotation->getPathToSchema()); $schema = json_decode(file_get_contents($schemaUrl)); $data = json_decode(json_encode($data)); if (!$this->validator->isValid($data, $schema)) { throw new JsonSchemaException($this->validator->getErrors()); } }
/** * Initialize the static object * * This function will initialize the configuration values in the static * object, if they have not yet been initialized. */ private static function init() { if (is_null(self::$configValues)) { self::$configDir = realpath(__DIR__ . '/config'); $locator = new FileLocator(self::$configDir); $yamlConfigFiles = $locator->locate('config.yml', null, false); self::$configValues = Yaml::parse(file_get_contents($yamlConfigFiles[0])); } }
public function configure($directory) { $locator = new FileLocator($directory); // Load services.yml into di-container $loader = new YamlFileLoader($this->container, $locator); $loader->load('services.yml'); // Load config.yml into variable $this->config = Yaml::parse(file_get_contents($locator->locate('config.yml'))); }