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
Show file tree
Hide file tree
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
allow for synthetic services while loading extensions - part 2
  • Loading branch information
ro0NL committed Aug 13, 2016
commit 9b118aa617be63a10fca1d84367d71ad3b3813a1
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,8 @@ public function process(ContainerBuilder $container)
$tmpContainer->addExpressionLanguageProvider($provider);
}

foreach ($container->getDefinitions() as $id => $definition) {
if ($definition instanceof ServiceAwareDefinition) {
// definitions are not transferred by design
$tmpContainer->set($id, $definition->getService());
}
// @TODO allow for available synthetic services to be transferred?
foreach ($container->getSynthetics() as $id => $service) {
$tmpContainer->set($id, $service);
}

$extension->load($config, $tmpContainer);
Expand Down
54 changes: 42 additions & 12 deletions src/Symfony/Component/DependencyInjection/ContainerBuilder.php
8000
Original file line number Diff line number Diff line change
Expand Up @@ -419,16 +419,6 @@ public function has($id)
*/
public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
{
$definition = $this->hasDefinition($id) ? $this->getDefinition($id) : null;
if (null !== $definition && $definition instanceof ServiceAwareDefinition) {
return $definition->getService();
}
// @TODO allow for available synthetic services?

if (!$this->compiled) {
@trigger_error(sprintf('Calling %s() before compiling the container is deprecated since version 3.2 and will throw an exception in 4.0.', __METHOD__), E_USER_DEPRECATED);
}

$id = strtolower($id);

if ($service = parent::get($id, ContainerInterface::NULL_ON_INVALID_REFERENCE)) {
Expand All @@ -439,10 +429,27 @@ public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INV
return $this->get($this->aliasDefinitions[$id]);
}

if (null === $definition && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
try {
$definition = $this->getDefinition($id);
if ($definition instanceof ServiceAwareDefinition) {
return $definition->getService();
}
} catch (ServiceNotFoundException $e) {
if ($this->compiled && ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) {
Copy link
Contributor Author
@ro0NL ro0NL Aug 13, 2016

Choose a reason for hiding this comment

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

For BC, however i tend to debug unknown id's before state. Just throwing here would be fine by me.

throw $e;
}
$definition = null;
}
if (!$this->compiled) {
@trigger_error(sprintf('Calling %s() before compiling the container is deprecated for non-synthetic services since version 3.2 and will throw an exception in 4.0.', __METHOD__), E_USER_DEPRECATED);
Copy link
Contributor Author
@ro0NL ro0NL Aug 13, 2016

Choose a reason for hiding this comment

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

Updated to be specific about non-synthetic services, besides that it will be triggered only once now whe 8000 n aliases kick in.

}
if (null === $definition) {
if (ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE === $invalidBehavior) {
throw new ServiceNotFoundException($id);
}

return;
}
$definition = $this->getDefinition($id);

$this->loading[$id] = true;

Expand All @@ -455,6 +462,29 @@ public function get($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INV
return $service;
}

/**
* Get synthetic services.
*
* @return object[]
*/
public function getSynthetics()
{
$synthetics = array();
foreach ($this->definitions as $id => $definition) {
if ($definition instanceof ServiceAwareDefinition) {
$synthetics[$id] = $definition->getService();
}
}
foreach (parent::getServiceIds() as $id) {
if ('service_container' === $id) {
continue;
}
$synthetics[$id] = parent::get($id);
}

return $synthetics;
}

/**
* Merges a ContainerBuilder with the current ContainerBuilder configuration.
*
Expand Down
0