8000 [RFC][DependencyInjection][HttpKernel] Kernel as a service by ro0NL · Pull Request #19606 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[RFC][DependencyInjection][HttpKernel] Kernel as a service #19606

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
the kernel as a service
  • Loading branch information
ro0NL committed Aug 12, 2016
commit a10d5638270a17565bccffc23f4fc70c7ba3ba2e
25 changes: 25 additions & 0 deletions src/Symfony/Component/HttpKernel/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Symfony\Component\DependencyInjection\Loader\PhpFileLoader;
use Symfony\Component\DependencyInjection\Loader\DirectoryLoader;
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
use Symfony\Component\DependencyInjection\ServiceAwareDefinition;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
Expand Down Expand Up @@ -447,6 +448,16 @@ protected function initializeBundles()
}
}

/**
* Gets the kernel service class.
*
* @return string The service class
*/
protected function getServiceClass()
{
return __NAMESPACE__.'\\Service\\Kernel';
}

/**
* Gets the container class.
*
Expand Down Expand Up @@ -481,7 +492,21 @@ protected function initializeContainer()
$cache = new ConfigCache($this->getCacheDir().'/'.$class.'.php', $this->debug);
$fresh = true;
if (!$cache->isFresh()) {
$serviceClass = $this->getServiceClass();
$bundles = array();
foreach ($this->bundles as $name => $bundle) {
$bundles[$name] = array(
'service_class' => method_exists($bundle, 'getServiceClass') ? $bundle->getServiceClass() : __NAMESPACE__.'\\Service\Bundle',
'class' => get_class($bundle),
'namespace' => $bundle->getNamespace(),
'parent' => $bundle->getParent(),
'path' => $bundle->getPath(),
);
}
$serviceDefinition = new ServiceAwareDefinition($serviceClass, array($this->environment, $this->debug, $bundles));
$serviceDefinition->setService(new $serviceClass($this->environment, $this->debug, $bundles));
$container = $this->buildContainer();
$container->setDefinition('kernel_as_a_service', $serviceDefinition);
Copy link
Contributor
@ogizanagi ogizanagi Aug 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

edit: Btw.. it becomes real quirky in MergeExtensionConfigurationPass (see my first attempt) where synthetic services are vanished anyway during extension loading ;-)
#19606 (comment)

If you want to use this service in an extension, you'll still have to do quirky things in MergeExtensionConfigurationPass as in your first attempt to make it available in the $tmpContainer passed to the ExtensionInterface::load method, right ?
Or perhaps you're only targeting compiler passes now ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working on it ;-)... however there are some design choices to be made.

$container->compile();
$this->dumpContainer($cache, $container, $class, $this->getContainerBaseClass());

Expand Down
0