/** * setup the environment for test. */ public function setUp() { $servicesYmlArray = ['parameters' => ['service.class' => 'BackBee\\DependencyInjection\\Tests\\RandomService', 'size_one' => 300, 'size_two' => 8000, 'size_three' => 44719], 'services' => ['service_one' => ['class' => '%service.class%', 'arguments' => ['%size_two%']], 'service_two' => ['class' => '%service.class%', 'calls' => [['setSize', ['%size_three%']]], 'tags' => [['name' => 'dumpable']]], 'service_three' => ['class' => '%service.class%', 'calls' => [['setClassProxy', ['']]], 'tags' => [['name' => 'dumpable']]], 'service_four' => ['class' => '%service.class%', 'tags' => [['name' => 'foo'], ['name' => 'bar']]], 'service_five' => ['synthetic' => true], 'service_six' => ['class' => '%service.class%', 'public' => false], 'service_seven' => ['class' => '%service.class%', 'scope' => 'prototype', 'file' => '/foo/bar', 'configurator' => ['@service_six', 'getSize']], 'service_eight' => ['class' => '%service.class%', 'factory' => ['\\DateTime', 'getLastErrors']], 'service_nine' => ['class' => '%service.class%', 'factory' => ['@service_zero', 'get']], 'service_ten' => ['abstract' => true, 'calls' => [['setSize', [8]]]], 'service_eleven' => ['class' => '%service.class%', 'parent' => 'service_ten']]]; $this->container = new Container(); vfsStream::setup('directory', 0777, ['services.yml' => Yaml::dump($servicesYmlArray)]); ServiceLoader::loadServicesFromYamlFile($this->container, vfsStream::url('directory')); $this->container->get('service_two')->setSize(self::RANDOM_SERVICE_NEW_SIZE_VALUE); }
/** * setup the environment for test. */ public function setUp() { $this->container = new Container(); $this->dumper = new PhpArrayDumper($this->container); $configTestDir = realpath(__DIR__ . '/PhpArrayDumperTest_Resources'); if (!is_dir($configTestDir)) { throw new \Exception(sprintf('Unable to find test Config directory (%s)', $configTestDir)); } $servicesFilepath = $configTestDir . DIRECTORY_SEPARATOR . 'services.yml'; if (!is_file($servicesFilepath) || !is_readable($servicesFilepath)) { throw new \Exception(sprintf('Unable to find or read services.yml (%s)', $servicesFilepath)); } $this->rawServices = Yaml::parse(file_get_contents($servicesFilepath)); ServiceLoader::loadServicesFromYamlFile($this->container, $configTestDir); $this->dump = unserialize($this->dumper->dump()); }
/** * Loads bundle services into application's dependency injection container. * * @param Config $config * @param callable|null $recipe */ private function loadServices(Config $config, callable $recipe = null) { if (false === $this->runRecipe($config, $recipe)) { $directories = BundleConfigDirectory::getDirectories($this->application->getBaseRepository(), $this->application->getContext(), $this->application->getEnvironment(), basename(dirname($config->getBaseDir()))); array_unshift($directories, $this->getConfigDirByBundleBaseDir(dirname($config->getBaseDir()))); foreach ($directories as $directory) { $filepath = $directory . DIRECTORY_SEPARATOR . 'services.xml'; if (is_file($filepath) && is_readable($filepath)) { try { ServiceLoader::loadServicesFromXmlFile($this->container, $directory); } catch (\Exception $e) { // nothing to do } } $filepath = $directory . DIRECTORY_SEPARATOR . 'services.yml'; if (is_file($filepath) && is_readable($filepath)) { try { ServiceLoader::loadServicesFromYamlFile($this->container, $directory); } catch (\Exception $e) { // nothing to do } } } } }
/** * Load and override services into container; the load order is from the most global to the most specific * depends on context and environment. */ private function loadApplicationServices() { // setting default services $this->container->set('bbapp', $this->application); $this->container->set('container.builder', $this); $services_directory = $this->application->getBBDir() . '/Config/services'; foreach (scandir($services_directory) as $file) { if (1 === preg_match('#(\\w+)\\.(yml|xml)$#', $file, $matches)) { if ('yml' === $matches[2]) { ServiceLoader::loadServicesFromYamlFile($this->container, $services_directory, $matches[1]); } else { ServiceLoader::loadServicesFromXmlFile($this->container, $services_directory, $matches[1]); } } } // define in which directory we have to looking for services yml or xml $directories = ConfigDirectory::getDirectories(null, $this->repository_directory, $this->context, $this->environment); // Loop into every directory where we can potentially found a services.yml or services.xml foreach ($directories as $directory) { if (true === is_readable($directory . DIRECTORY_SEPARATOR . self::SERVICE_FILENAME . '.yml')) { ServiceLoader::loadServicesFromYamlFile($this->container, $directory); } if (true === is_readable($directory . DIRECTORY_SEPARATOR . self::SERVICE_FILENAME . '.xml')) { ServiceLoader::loadServicesFromXmlFile($this->container, $directory); } } $this->loadLoggerDefinition(); }