/** * 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(); }