protected DrupalKernel::compileContainer()
Compiles a new service container.
Return value
ContainerBuilder The compiled service container
File
- core/lib/Drupal/Core/DrupalKernel.php, line 1166
Class
- DrupalKernel
- The DrupalKernel class is the core of Drupal itself.
Namespace
Drupal\Core
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 | protected function compileContainer() { // We are forcing a container build so it is reasonable to assume that the // calling method knows something about the system has changed requiring the // container to be dumped to the filesystem. if ( $this ->allowDumping) { $this ->containerNeedsDumping = TRUE; } $this ->initializeServiceProviders(); $container = $this ->getContainerBuilder(); $container ->set( 'kernel' , $this ); $container ->setParameter( 'container.modules' , $this ->getModulesParameter()); // Get a list of namespaces and put it onto the container. $namespaces = $this ->getModuleNamespacesPsr4( $this ->getModuleFileNames()); // Add all components in \Drupal\Core and \Drupal\Component that have one of // the following directories: // - Element // - Entity // - Plugin foreach ( array ( 'Core' , 'Component' ) as $parent_directory ) { $path = 'core/lib/Drupal/' . $parent_directory ; $parent_namespace = 'Drupal\\' . $parent_directory ; foreach ( new \DirectoryIterator( $this ->root . '/' . $path ) as $component ) { /** @var $component \DirectoryIterator */ $pathname = $component ->getPathname(); if (! $component ->isDot() && $component ->isDir() && ( is_dir ( $pathname . '/Plugin' ) || is_dir ( $pathname . '/Entity' ) || is_dir ( $pathname . '/Element' ) )) { $namespaces [ $parent_namespace . '\\' . $component ->getFilename()] = $path . '/' . $component ->getFilename(); } } } $container ->setParameter( 'container.namespaces' , $namespaces ); // Store the default language values on the container. This is so that the // default language can be configured using the configuration factory. This // avoids the circular dependencies that would created by // \Drupal\language\LanguageServiceProvider::alter() and allows the default // language to not be English in the installer. $default_language_values = Language:: $defaultValues ; if ( $system = $this ->getConfigStorage()->read( 'system.site' )) { if ( $default_language_values [ 'id' ] != $system [ 'langcode' ]) { $default_language_values = array ( 'id' => $system [ 'langcode' ]); } } $container ->setParameter( 'language.default_values' , $default_language_values ); // Register synthetic services. $container ->register( 'class_loader' )->setSynthetic(TRUE); $container ->register( 'kernel' , 'Symfony\Component\HttpKernel\KernelInterface' )->setSynthetic(TRUE); $container ->register( 'service_container' , 'Symfony\Component\DependencyInjection\ContainerInterface' )->setSynthetic(TRUE); // Register application services. $yaml_loader = new YamlFileLoader( $container ); foreach ( $this ->serviceYamls[ 'app' ] as $filename ) { $yaml_loader ->load( $filename ); } foreach ( $this ->serviceProviders[ 'app' ] as $provider ) { if ( $provider instanceof ServiceProviderInterface) { $provider ->register( $container ); } } // Register site-specific service overrides. foreach ( $this ->serviceYamls[ 'site' ] as $filename ) { $yaml_loader ->load( $filename ); } foreach ( $this ->serviceProviders[ 'site' ] as $provider ) { if ( $provider instanceof ServiceProviderInterface) { $provider ->register( $container ); } } // Identify all services whose instances should be persisted when rebuilding // the container during the lifetime of the kernel (e.g., during a kernel // reboot). Include synthetic services, because by definition, they cannot // be automatically reinstantiated. Also include services tagged to persist. $persist_ids = array (); foreach ( $container ->getDefinitions() as $id => $definition ) { // It does not make sense to persist the container itself, exclude it. if ( $id !== 'service_container' && ( $definition ->isSynthetic() || $definition ->getTag( 'persist' ))) { $persist_ids [] = $id ; } } $container ->setParameter( 'persist_ids' , $persist_ids ); $container ->compile(); return $container ; } |
Please login to continue.