[DI] Remove deprecated scope concept
This commit is contained in:
parent
eca45b7624
commit
4a3e2f49cb
@ -15,7 +15,6 @@ use ProxyManager\Generator\ClassGenerator;
|
|||||||
use ProxyManager\GeneratorStrategy\BaseGeneratorStrategy;
|
use ProxyManager\GeneratorStrategy\BaseGeneratorStrategy;
|
||||||
use ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator;
|
use ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator;
|
||||||
use Symfony\Component\DependencyInjection\Container;
|
use Symfony\Component\DependencyInjection\Container;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
||||||
use Symfony\Component\DependencyInjection\Definition;
|
use Symfony\Component\DependencyInjection\Definition;
|
||||||
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface;
|
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface;
|
||||||
|
|
||||||
@ -68,10 +67,8 @@ class ProxyDumper implements DumperInterface
|
|||||||
{
|
{
|
||||||
$instantiation = 'return';
|
$instantiation = 'return';
|
||||||
|
|
||||||
if ($definition->isShared() && ContainerInterface::SCOPE_CONTAINER === $definition->getScope(false)) {
|
if ($definition->isShared()) {
|
||||||
$instantiation .= " \$this->services['$id'] =";
|
$instantiation .= " \$this->services['$id'] =";
|
||||||
} elseif ($definition->isShared() && ContainerInterface::SCOPE_PROTOTYPE !== $scope = $definition->getScope(false)) {
|
|
||||||
$instantiation .= " \$this->services['$id'] = \$this->scopedServices['$scope']['$id'] =";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$methodName = 'get'.Container::camelize($id).'Service';
|
$methodName = 'get'.Container::camelize($id).'Service';
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\DependencyInjection\Container;
|
use Symfony\Component\DependencyInjection\Container;
|
||||||
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
|
|
||||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||||
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
||||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||||
@ -23,11 +22,7 @@ class LazyServiceProjectServiceContainer extends Container
|
|||||||
*/
|
*/
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->services =
|
$this->services = array();
|
||||||
$this->scopedServices =
|
|
||||||
$this->scopeStacks = array();
|
|
||||||
$this->scopes = array();
|
|
||||||
$this->scopeChildren = array();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -43,7 +38,6 @@ class LazyServiceProjectServiceContainer extends Container
|
|||||||
public function getFooService($lazyLoad = true)
|
public function getFooService($lazyLoad = true)
|
||||||
{
|
{
|
||||||
if ($lazyLoad) {
|
if ($lazyLoad) {
|
||||||
|
|
||||||
return $this->services['foo'] = new stdClass_c1d194250ee2e2b7d2eab8b8212368a8(
|
return $this->services['foo'] = new stdClass_c1d194250ee2e2b7d2eab8b8212368a8(
|
||||||
function (&$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) {
|
function (&$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) {
|
||||||
$wrappedInstance = $this->getFooService(false);
|
$wrappedInstance = $this->getFooService(false);
|
||||||
|
@ -205,7 +205,6 @@ class JsonDescriptor extends Descriptor
|
|||||||
{
|
{
|
||||||
$data = array(
|
$data = array(
|
||||||
'class' => (string) $definition->getClass(),
|
'class' => (string) $definition->getClass(),
|
||||||
'scope' => $definition->getScope(false),
|
|
||||||
'public' => $definition->isPublic(),
|
'public' => $definition->isPublic(),
|
||||||
'synthetic' => $definition->isSynthetic(),
|
'synthetic' => $definition->isSynthetic(),
|
||||||
'lazy' => $definition->isLazy(),
|
'lazy' => $definition->isLazy(),
|
||||||
|
@ -176,7 +176,6 @@ class MarkdownDescriptor extends Descriptor
|
|||||||
protected function describeContainerDefinition(Definition $definition, array $options = array())
|
protected function describeContainerDefinition(Definition $definition, array $options = array())
|
||||||
{
|
{
|
||||||
$output = '- Class: `'.$definition->getClass().'`'
|
$output = '- Class: `'.$definition->getClass().'`'
|
||||||
."\n".'- Scope: `'.$definition->getScope(false).'`'
|
|
||||||
."\n".'- Public: '.($definition->isPublic() ? 'yes' : 'no')
|
."\n".'- Public: '.($definition->isPublic() ? 'yes' : 'no')
|
||||||
."\n".'- Synthetic: '.($definition->isSynthetic() ? 'yes' : 'no')
|
."\n".'- Synthetic: '.($definition->isSynthetic() ? 'yes' : 'no')
|
||||||
."\n".'- Lazy: '.($definition->isLazy() ? 'yes' : 'no')
|
."\n".'- Lazy: '.($definition->isLazy() ? 'yes' : 'no')
|
||||||
|
@ -256,7 +256,6 @@ class TextDescriptor extends Descriptor
|
|||||||
$description[] = '<comment>Tags</comment> -';
|
$description[] = '<comment>Tags</comment> -';
|
||||||
}
|
}
|
||||||
|
|
||||||
$description[] = sprintf('<comment>Scope</comment> %s', $definition->getScope(false));
|
|
||||||
$description[] = sprintf('<comment>Public</comment> %s', $definition->isPublic() ? 'yes' : 'no');
|
$description[] = sprintf('<comment>Public</comment> %s', $definition->isPublic() ? 'yes' : 'no');
|
||||||
$description[] = sprintf('<comment>Synthetic</comment> %s', $definition->isSynthetic() ? 'yes' : 'no');
|
$description[] = sprintf('<comment>Synthetic</comment> %s', $definition->isSynthetic() ? 'yes' : 'no');
|
||||||
$description[] = sprintf('<comment>Lazy</comment> %s', $definition->isLazy() ? 'yes' : 'no');
|
$description[] = sprintf('<comment>Lazy</comment> %s', $definition->isLazy() ? 'yes' : 'no');
|
||||||
|
@ -346,7 +346,6 @@ class XmlDescriptor extends Descriptor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$serviceXML->setAttribute('scope', $definition->getScope(false));
|
|
||||||
$serviceXML->setAttribute('public', $definition->isPublic() ? 'true' : 'false');
|
$serviceXML->setAttribute('public', $definition->isPublic() ? 'true' : 'false');
|
||||||
$serviceXML->setAttribute('synthetic', $definition->isSynthetic() ? 'true' : 'false');
|
$serviceXML->setAttribute('synthetic', $definition->isSynthetic() ? 'true' : 'false');
|
||||||
$serviceXML->setAttribute('lazy', $definition->isLazy() ? 'true' : 'false');
|
$serviceXML->setAttribute('lazy', $definition->isLazy() ? 'true' : 'false');
|
||||||
|
@ -31,7 +31,6 @@ use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SerializerPass;
|
|||||||
use Symfony\Component\Debug\ErrorHandler;
|
use Symfony\Component\Debug\ErrorHandler;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
|
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
|
||||||
use Symfony\Component\DependencyInjection\Scope;
|
|
||||||
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
|
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
|
||||||
use Symfony\Component\HttpKernel\DependencyInjection\FragmentRendererPass;
|
use Symfony\Component\HttpKernel\DependencyInjection\FragmentRendererPass;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
@ -65,10 +64,6 @@ class FrameworkBundle extends Bundle
|
|||||||
{
|
{
|
||||||
parent::build($container);
|
parent::build($container);
|
||||||
|
|
||||||
// we need to add the request scope as early as possible so that
|
|
||||||
// the compilation can find scope widening issues
|
|
||||||
$container->addScope(new Scope('request'));
|
|
||||||
|
|
||||||
$container->addCompilerPass(new RoutingResolverPass());
|
$container->addCompilerPass(new RoutingResolverPass());
|
||||||
$container->addCompilerPass(new ProfilerPass());
|
$container->addCompilerPass(new ProfilerPass());
|
||||||
// must be registered before removing private services as some might be listeners/subscribers
|
// must be registered before removing private services as some might be listeners/subscribers
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
"definitions": {
|
"definitions": {
|
||||||
"definition_1": {
|
"definition_1": {
|
||||||
"class": "Full\\Qualified\\Class1",
|
"class": "Full\\Qualified\\Class1",
|
||||||
"scope": "container",
|
|
||||||
"public": true,
|
"public": true,
|
||||||
"synthetic": false,
|
"synthetic": false,
|
||||||
"lazy": true,
|
"lazy": true,
|
||||||
|
@ -8,7 +8,6 @@ definition_1
|
|||||||
~~~~~~~~~~~~
|
~~~~~~~~~~~~
|
||||||
|
|
||||||
- Class: `Full\Qualified\Class1`
|
- Class: `Full\Qualified\Class1`
|
||||||
- Scope: `container`
|
|
||||||
- Public: yes
|
- Public: yes
|
||||||
- Synthetic: no
|
- Synthetic: no
|
||||||
- Lazy: yes
|
- Lazy: yes
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<container>
|
<container>
|
||||||
<alias id="alias_1" service="service_1" public="true"/>
|
<alias id="alias_1" service="service_1" public="true"/>
|
||||||
<alias id="alias_2" service="service_2" public="false"/>
|
<alias id="alias_2" service="service_2" public="false"/>
|
||||||
<definition id="definition_1" class="Full\Qualified\Class1" scope="container" public="true" synthetic="false" lazy="true" shared="true" abstract="true" file="">
|
<definition id="definition_1" class="Full\Qualified\Class1" public="true" synthetic="false" lazy="true" shared="true" abstract="true" file="">
|
||||||
<factory class="Full\Qualified\FactoryClass" method="get"/>
|
<factory class="Full\Qualified\FactoryClass" method="get"/>
|
||||||
</definition>
|
</definition>
|
||||||
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerBuilder"/>
|
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerBuilder"/>
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
"definitions": {
|
"definitions": {
|
||||||
"definition_1": {
|
"definition_1": {
|
||||||
"class": "Full\\Qualified\\Class1",
|
"class": "Full\\Qualified\\Class1",
|
||||||
"scope": "container",
|
|
||||||
"public": true,
|
"public": true,
|
||||||
"synthetic": false,
|
"synthetic": false,
|
||||||
"lazy": true,
|
"lazy": true,
|
||||||
@ -17,7 +16,6 @@
|
|||||||
},
|
},
|
||||||
"definition_2": {
|
"definition_2": {
|
||||||
"class": "Full\\Qualified\\Class2",
|
"class": "Full\\Qualified\\Class2",
|
||||||
"scope": "container",
|
|
||||||
"public": false,
|
"public": false,
|
||||||
"synthetic": true,
|
"synthetic": true,
|
||||||
"lazy": false,
|
"lazy": false,
|
||||||
|
@ -8,7 +8,6 @@ definition_1
|
|||||||
~~~~~~~~~~~~
|
~~~~~~~~~~~~
|
||||||
|
|
||||||
- Class: `Full\Qualified\Class1`
|
- Class: `Full\Qualified\Class1`
|
||||||
- Scope: `container`
|
|
||||||
- Public: yes
|
- Public: yes
|
||||||
- Synthetic: no
|
- Synthetic: no
|
||||||
- Lazy: yes
|
- Lazy: yes
|
||||||
@ -21,7 +20,6 @@ definition_2
|
|||||||
~~~~~~~~~~~~
|
~~~~~~~~~~~~
|
||||||
|
|
||||||
- Class: `Full\Qualified\Class2`
|
- Class: `Full\Qualified\Class2`
|
||||||
- Scope: `container`
|
|
||||||
- Public: no
|
- Public: no
|
||||||
- Synthetic: yes
|
- Synthetic: yes
|
||||||
- Lazy: no
|
- Lazy: no
|
||||||
|
@ -2,10 +2,10 @@
|
|||||||
<container>
|
<container>
|
||||||
<alias id="alias_1" service="service_1" public="true"/>
|
<alias id="alias_1" service="service_1" public="true"/>
|
||||||
<alias id="alias_2" service="service_2" public="false"/>
|
<alias id="alias_2" service="service_2" public="false"/>
|
||||||
<definition id="definition_1" class="Full\Qualified\Class1" scope="container" public="true" synthetic="false" lazy="true" shared="true" abstract="true" file="">
|
<definition id="definition_1" class="Full\Qualified\Class1" public="true" synthetic="false" lazy="true" shared="true" abstract="true" file="">
|
||||||
<factory class="Full\Qualified\FactoryClass" method="get"/>
|
<factory class="Full\Qualified\FactoryClass" method="get"/>
|
||||||
</definition>
|
</definition>
|
||||||
<definition id="definition_2" class="Full\Qualified\Class2" scope="container" public="false" synthetic="true" lazy="false" shared="true" abstract="false" file="/path/to/file">
|
<definition id="definition_2" class="Full\Qualified\Class2" public="false" synthetic="true" lazy="false" shared="true" abstract="false" file="/path/to/file">
|
||||||
<factory service="factory.service" method="get"/>
|
<factory service="factory.service" method="get"/>
|
||||||
<tags>
|
<tags>
|
||||||
<tag name="tag1">
|
<tag name="tag1">
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
"definitions": {
|
"definitions": {
|
||||||
"definition_2": {
|
"definition_2": {
|
||||||
"class": "Full\\Qualified\\Class2",
|
"class": "Full\\Qualified\\Class2",
|
||||||
"scope": "container",
|
|
||||||
"public": false,
|
"public": false,
|
||||||
"synthetic": true,
|
"synthetic": true,
|
||||||
"lazy": false,
|
"lazy": false,
|
||||||
|
@ -8,7 +8,6 @@ definition_2
|
|||||||
~~~~~~~~~~~~
|
~~~~~~~~~~~~
|
||||||
|
|
||||||
- Class: `Full\Qualified\Class2`
|
- Class: `Full\Qualified\Class2`
|
||||||
- Scope: `container`
|
|
||||||
- Public: no
|
- Public: no
|
||||||
- Synthetic: yes
|
- Synthetic: yes
|
||||||
- Lazy: no
|
- Lazy: no
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<container>
|
<container>
|
||||||
<definition id="definition_2" class="Full\Qualified\Class2" scope="container" public="false" synthetic="true" lazy="false" shared="true" abstract="false" file="/path/to/file">
|
<definition id="definition_2" class="Full\Qualified\Class2" public="false" synthetic="true" lazy="false" shared="true" abstract="false" file="/path/to/file">
|
||||||
<factory service="factory.service" method="get"/>
|
<factory service="factory.service" method="get"/>
|
||||||
<tags>
|
<tags>
|
||||||
<tag name="tag1">
|
<tag name="tag1">
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
"tag1": [
|
"tag1": [
|
||||||
{
|
{
|
||||||
"class": "Full\\Qualified\\Class2",
|
"class": "Full\\Qualified\\Class2",
|
||||||
"scope": "container",
|
|
||||||
"public": false,
|
"public": false,
|
||||||
"synthetic": true,
|
"synthetic": true,
|
||||||
"lazy": false,
|
"lazy": false,
|
||||||
@ -16,7 +15,6 @@
|
|||||||
"tag2": [
|
"tag2": [
|
||||||
{
|
{
|
||||||
"class": "Full\\Qualified\\Class2",
|
"class": "Full\\Qualified\\Class2",
|
||||||
"scope": "container",
|
|
||||||
"public": false,
|
"public": false,
|
||||||
"synthetic": true,
|
"synthetic": true,
|
||||||
"lazy": false,
|
"lazy": false,
|
||||||
|
@ -8,7 +8,6 @@ definition_2
|
|||||||
~~~~~~~~~~~~
|
~~~~~~~~~~~~
|
||||||
|
|
||||||
- Class: `Full\Qualified\Class2`
|
- Class: `Full\Qualified\Class2`
|
||||||
- Scope: `container`
|
|
||||||
- Public: no
|
- Public: no
|
||||||
- Synthetic: yes
|
- Synthetic: yes
|
||||||
- Lazy: no
|
- Lazy: no
|
||||||
@ -26,7 +25,6 @@ definition_2
|
|||||||
~~~~~~~~~~~~
|
~~~~~~~~~~~~
|
||||||
|
|
||||||
- Class: `Full\Qualified\Class2`
|
- Class: `Full\Qualified\Class2`
|
||||||
- Scope: `container`
|
|
||||||
- Public: no
|
- Public: no
|
||||||
- Synthetic: yes
|
- Synthetic: yes
|
||||||
- Lazy: no
|
- Lazy: no
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<container>
|
<container>
|
||||||
<tag name="tag1">
|
<tag name="tag1">
|
||||||
<definition id="definition_2" class="Full\Qualified\Class2" scope="container" public="false" synthetic="true" lazy="false" shared="true" abstract="false" file="/path/to/file">
|
<definition id="definition_2" class="Full\Qualified\Class2" public="false" synthetic="true" lazy="false" shared="true" abstract="false" file="/path/to/file">
|
||||||
<factory service="factory.service" method="get"/>
|
<factory service="factory.service" method="get"/>
|
||||||
</definition>
|
</definition>
|
||||||
</tag>
|
</tag>
|
||||||
<tag name="tag2">
|
<tag name="tag2">
|
||||||
<definition id="definition_2" class="Full\Qualified\Class2" scope="container" public="false" synthetic="true" lazy="false" shared="true" abstract="false" file="/path/to/file">
|
<definition id="definition_2" class="Full\Qualified\Class2" public="false" synthetic="true" lazy="false" shared="true" abstract="false" file="/path/to/file">
|
||||||
<factory service="factory.service" method="get"/>
|
<factory service="factory.service" method="get"/>
|
||||||
</definition>
|
</definition>
|
||||||
</tag>
|
</tag>
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
{
|
{
|
||||||
"class": "Full\\Qualified\\Class1",
|
"class": "Full\\Qualified\\Class1",
|
||||||
"scope": "container",
|
|
||||||
"public": true,
|
"public": true,
|
||||||
"synthetic": false,
|
"synthetic": false,
|
||||||
"lazy": true,
|
"lazy": true,
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
- Class: `Full\Qualified\Class1`
|
- Class: `Full\Qualified\Class1`
|
||||||
- Scope: `container`
|
|
||||||
- Public: yes
|
- Public: yes
|
||||||
- Synthetic: no
|
- Synthetic: no
|
||||||
- Lazy: yes
|
- Lazy: yes
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
<comment>Service Id</comment> -
|
<comment>Service Id</comment> -
|
||||||
<comment>Class</comment> Full\Qualified\Class1
|
<comment>Class</comment> Full\Qualified\Class1
|
||||||
<comment>Tags</comment> -
|
<comment>Tags</comment> -
|
||||||
<comment>Scope</comment> container
|
|
||||||
<comment>Public</comment> yes
|
<comment>Public</comment> yes
|
||||||
<comment>Synthetic</comment> no
|
<comment>Synthetic</comment> no
|
||||||
<comment>Lazy</comment> yes
|
<comment>Lazy</comment> yes
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<definition class="Full\Qualified\Class1" scope="container" public="true" synthetic="false" lazy="true" shared="true" abstract="true" file="">
|
<definition class="Full\Qualified\Class1" public="true" synthetic="false" lazy="true" shared="true" abstract="true" file="">
|
||||||
<factory class="Full\Qualified\FactoryClass" method="get"/>
|
<factory class="Full\Qualified\FactoryClass" method="get"/>
|
||||||
</definition>
|
</definition>
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
{
|
{
|
||||||
"class": "Full\\Qualified\\Class2",
|
"class": "Full\\Qualified\\Class2",
|
||||||
"scope": "container",
|
|
||||||
"public": false,
|
"public": false,
|
||||||
"synthetic": true,
|
"synthetic": true,
|
||||||
"lazy": false,
|
"lazy": false,
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
- Class: `Full\Qualified\Class2`
|
- Class: `Full\Qualified\Class2`
|
||||||
- Scope: `container`
|
|
||||||
- Public: no
|
- Public: no
|
||||||
- Synthetic: yes
|
- Synthetic: yes
|
||||||
- Lazy: no
|
- Lazy: no
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
- tag1 (<info>attr1</info>: val1, <info>attr2</info>: val2)
|
- tag1 (<info>attr1</info>: val1, <info>attr2</info>: val2)
|
||||||
- tag1 (<info>attr3</info>: val3)
|
- tag1 (<info>attr3</info>: val3)
|
||||||
- tag2 ()
|
- tag2 ()
|
||||||
<comment>Scope</comment> container
|
|
||||||
<comment>Public</comment> no
|
<comment>Public</comment> no
|
||||||
<comment>Synthetic</comment> yes
|
<comment>Synthetic</comment> yes
|
||||||
<comment>Lazy</comment> no
|
<comment>Lazy</comment> no
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<definition class="Full\Qualified\Class2" scope="container" public="false" synthetic="true" lazy="false" shared="true" abstract="false" file="/path/to/file">
|
<definition class="Full\Qualified\Class2" public="false" synthetic="true" lazy="false" shared="true" abstract="false" file="/path/to/file">
|
||||||
<factory service="factory.service" method="get"/>
|
<factory service="factory.service" method="get"/>
|
||||||
<tags>
|
<tags>
|
||||||
<tag name="tag1">
|
<tag name="tag1">
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
CHANGELOG
|
CHANGELOG
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
3.0.0
|
||||||
|
-----
|
||||||
|
|
||||||
|
* removed all deprecated codes from 2.x versions
|
||||||
|
|
||||||
2.8.0
|
2.8.0
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\DependencyInjection\Compiler;
|
namespace Symfony\Component\DependencyInjection\Compiler;
|
||||||
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||||
|
|
||||||
@ -24,8 +23,6 @@ use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
|||||||
*
|
*
|
||||||
* - non synthetic, non abstract services always have a class set
|
* - non synthetic, non abstract services always have a class set
|
||||||
* - synthetic services are always public
|
* - synthetic services are always public
|
||||||
* - synthetic services are always of non-prototype scope
|
|
||||||
* - shared services are always of non-prototype scope
|
|
||||||
*
|
*
|
||||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||||
*/
|
*/
|
||||||
@ -46,16 +43,6 @@ class CheckDefinitionValidityPass implements CompilerPassInterface
|
|||||||
throw new RuntimeException(sprintf('A synthetic service ("%s") must be public.', $id));
|
throw new RuntimeException(sprintf('A synthetic service ("%s") must be public.', $id));
|
||||||
}
|
}
|
||||||
|
|
||||||
// synthetic service has non-prototype scope
|
|
||||||
if ($definition->isSynthetic() && ContainerInterface::SCOPE_PROTOTYPE === $definition->getScope(false)) {
|
|
||||||
throw new RuntimeException(sprintf('A synthetic service ("%s") cannot be of scope "prototype".', $id));
|
|
||||||
}
|
|
||||||
|
|
||||||
// shared service has non-prototype scope
|
|
||||||
if ($definition->isShared() && ContainerInterface::SCOPE_PROTOTYPE === $definition->getScope(false)) {
|
|
||||||
throw new RuntimeException(sprintf('A shared service ("%s") cannot be of scope "prototype".', $id));
|
|
||||||
}
|
|
||||||
|
|
||||||
// non-synthetic, non-abstract service has class
|
// non-synthetic, non-abstract service has class
|
||||||
if (!$definition->isAbstract() && !$definition->isSynthetic() && !$definition->getClass()) {
|
if (!$definition->isAbstract() && !$definition->isSynthetic() && !$definition->getClass()) {
|
||||||
if ($definition->getFactory()) {
|
if ($definition->getFactory()) {
|
||||||
|
@ -12,20 +12,15 @@
|
|||||||
namespace Symfony\Component\DependencyInjection\Compiler;
|
namespace Symfony\Component\DependencyInjection\Compiler;
|
||||||
|
|
||||||
use Symfony\Component\DependencyInjection\Definition;
|
use Symfony\Component\DependencyInjection\Definition;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
|
||||||
use Symfony\Component\DependencyInjection\Reference;
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||||
use Symfony\Component\DependencyInjection\Exception\ScopeCrossingInjectionException;
|
|
||||||
use Symfony\Component\DependencyInjection\Exception\ScopeWideningInjectionException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks the validity of references.
|
* Checks the validity of references.
|
||||||
*
|
*
|
||||||
* The following checks are performed by this pass:
|
* The following checks are performed by this pass:
|
||||||
* - target definitions are not abstract
|
* - target definitions are not abstract
|
||||||
* - target definitions are of equal or wider scope
|
|
||||||
* - target definitions are in the same scope hierarchy
|
|
||||||
*
|
*
|
||||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||||
*/
|
*/
|
||||||
@ -33,9 +28,6 @@ class CheckReferenceValidityPass implements CompilerPassInterface
|
|||||||
{
|
{
|
||||||
private $container;
|
private $container;
|
||||||
private $currentId;
|
private $currentId;
|
||||||
private $currentScope;
|
|
||||||
private $currentScopeAncestors;
|
|
||||||
private $currentScopeChildren;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Processes the ContainerBuilder to validate References.
|
* Processes the ContainerBuilder to validate References.
|
||||||
@ -46,18 +38,8 @@ class CheckReferenceValidityPass implements CompilerPassInterface
|
|||||||
{
|
{
|
||||||
$this->container = $container;
|
$this->container = $container;
|
||||||
|
|
||||||
$children = $this->container->getScopeChildren(false);
|
|
||||||
$ancestors = array();
|
$ancestors = array();
|
||||||
|
|
||||||
$scopes = $this->container->getScopes(false);
|
|
||||||
foreach ($scopes as $name => $parent) {
|
|
||||||
$ancestors[$name] = array($parent);
|
|
||||||
|
|
||||||
while (isset($scopes[$parent])) {
|
|
||||||
$ancestors[$name][] = $parent = $scopes[$parent];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($container->getDefinitions() as $id => $definition) {
|
foreach ($container->getDefinitions() as $id => $definition) {
|
||||||
if ($definition->isSynthetic() || $definition->isAbstract()) {
|
if ($definition->isSynthetic() || $definition->isAbstract()) {
|
||||||
continue;
|
continue;
|
||||||
@ -65,15 +47,6 @@ class CheckReferenceValidityPass implements CompilerPassInterface
|
|||||||
|
|
||||||
$this->currentId = $id;
|
$this->currentId = $id;
|
||||||
$this->currentDefinition = $definition;
|
$this->currentDefinition = $definition;
|
||||||
$this->currentScope = $scope = $definition->getScope(false);
|
|
||||||
|
|
||||||
if (ContainerInterface::SCOPE_CONTAINER === $scope) {
|
|
||||||
$this->currentScopeChildren = array_keys($scopes);
|
|
||||||
$this->currentScopeAncestors = array();
|
|
||||||
} elseif (ContainerInterface::SCOPE_PROTOTYPE !== $scope) {
|
|
||||||
$this->currentScopeChildren = isset($children[$scope]) ? $children[$scope] : array();
|
|
||||||
$this->currentScopeAncestors = isset($ancestors[$scope]) ? $ancestors[$scope] : array();
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->validateReferences($definition->getArguments());
|
$this->validateReferences($definition->getArguments());
|
||||||
$this->validateReferences($definition->getMethodCalls());
|
$this->validateReferences($definition->getMethodCalls());
|
||||||
@ -104,50 +77,10 @@ class CheckReferenceValidityPass implements CompilerPassInterface
|
|||||||
$argument
|
$argument
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->validateScope($argument, $targetDefinition);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates the scope of a single Reference.
|
|
||||||
*
|
|
||||||
* @param Reference $reference
|
|
||||||
* @param Definition $definition
|
|
||||||
*
|
|
||||||
* @throws ScopeWideningInjectionException when the definition references a service of a narrower scope
|
|
||||||
* @throws ScopeCrossingInjectionException when the definition references a service of another scope hierarchy
|
|
||||||
*/
|
|
||||||
private function validateScope(Reference $reference, Definition $definition = null)
|
|
||||||
{
|
|
||||||
if (ContainerInterface::SCOPE_PROTOTYPE === $this->currentScope) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$reference->isStrict(false)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null === $definition) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($this->currentScope === $scope = $definition->getScope(false)) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
$id = (string) $reference;
|
|
||||||
|
|
||||||
if (in_array($scope, $this->currentScopeChildren, true)) {
|
|
||||||
throw new ScopeWideningInjectionException($this->currentId, $this->currentScope, $id, $scope);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!in_array($scope, $this->currentScopeAncestors, true)) {
|
|
||||||
throw new ScopeCrossingInjectionException($this->currentId, $this->currentScope, $id, $scope);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Definition given an id.
|
* Returns the Definition given an id.
|
||||||
*
|
*
|
||||||
|
@ -76,7 +76,7 @@ class InlineServiceDefinitionsPass implements RepeatablePassInterface
|
|||||||
if ($this->isInlineableDefinition($container, $id, $definition = $container->getDefinition($id))) {
|
if ($this->isInlineableDefinition($container, $id, $definition = $container->getDefinition($id))) {
|
||||||
$this->compiler->addLogMessage($this->formatter->formatInlineService($this, $id, $this->currentId));
|
$this->compiler->addLogMessage($this->formatter->formatInlineService($this, $id, $this->currentId));
|
||||||
|
|
||||||
if ($definition->isShared() && ContainerInterface::SCOPE_PROTOTYPE !== $definition->getScope(false)) {
|
if ($definition->isShared()) {
|
||||||
$arguments[$k] = $definition;
|
$arguments[$k] = $definition;
|
||||||
} else {
|
} else {
|
||||||
$arguments[$k] = clone $definition;
|
$arguments[$k] = clone $definition;
|
||||||
@ -109,7 +109,7 @@ class InlineServiceDefinitionsPass implements RepeatablePassInterface
|
|||||||
*/
|
*/
|
||||||
private function isInlineableDefinition(ContainerBuilder $container, $id, Definition $definition)
|
private function isInlineableDefinition(ContainerBuilder $container, $id, Definition $definition)
|
||||||
{
|
{
|
||||||
if (!$definition->isShared() || ContainerInterface::SCOPE_PROTOTYPE === $definition->getScope(false)) {
|
if (!$definition->isShared()) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -138,6 +138,6 @@ class InlineServiceDefinitionsPass implements RepeatablePassInterface
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return $container->getDefinition(reset($ids))->getScope(false) === $definition->getScope(false);
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ class ResolveDefinitionTemplatesPass implements CompilerPassInterface
|
|||||||
$def = new Definition();
|
$def = new Definition();
|
||||||
|
|
||||||
// merge in parent definition
|
// merge in parent definition
|
||||||
// purposely ignored attributes: scope, abstract, tags
|
// purposely ignored attributes: abstract, tags
|
||||||
$def->setClass($parentDef->getClass());
|
$def->setClass($parentDef->getClass());
|
||||||
$def->setArguments($parentDef->getArguments());
|
$def->setArguments($parentDef->getArguments());
|
||||||
$def->setMethodCalls($parentDef->getMethodCalls());
|
$def->setMethodCalls($parentDef->getMethodCalls());
|
||||||
@ -180,7 +180,6 @@ class ResolveDefinitionTemplatesPass implements CompilerPassInterface
|
|||||||
|
|
||||||
// these attributes are always taken from the child
|
// these attributes are always taken from the child
|
||||||
$def->setAbstract($definition->isAbstract());
|
$def->setAbstract($definition->isAbstract());
|
||||||
$def->setScope($definition->getScope(false), false);
|
|
||||||
$def->setTags($definition->getTags());
|
$def->setTags($definition->getTags());
|
||||||
|
|
||||||
return $def;
|
return $def;
|
||||||
|
@ -68,7 +68,7 @@ class ResolveReferencesToAliasesPass implements CompilerPassInterface
|
|||||||
$defId = $this->getDefinitionId($id = (string) $argument);
|
$defId = $this->getDefinitionId($id = (string) $argument);
|
||||||
|
|
||||||
if ($defId !== $id) {
|
if ($defId !== $id) {
|
||||||
$arguments[$k] = new Reference($defId, $argument->getInvalidBehavior(), $argument->isStrict(false));
|
$arguments[$k] = new Reference($defId, $argument->getInvalidBehavior());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,7 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\DependencyInjection;
|
namespace Symfony\Component\DependencyInjection;
|
||||||
|
|
||||||
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
|
|
||||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||||
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
|
||||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
|
||||||
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
|
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
|
||||||
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
|
use Symfony\Component\DependencyInjection\Exception\ServiceCircularReferenceException;
|
||||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||||
@ -71,10 +68,6 @@ class Container implements ResettableContainerInterface
|
|||||||
protected $services = array();
|
protected $services = array();
|
||||||
protected $methodMap = array();
|
protected $methodMap = array();
|
||||||
protected $aliases = array();
|
protected $aliases = array();
|
||||||
protected $scopes = array();
|
|
||||||
protected $scopeChildren = array();
|
|
||||||
protected $scopedServices = array();
|
|
||||||
protected $scopeStacks = array();
|
|
||||||
protected $loading = array();
|
protected $loading = array();
|
||||||
|
|
||||||
private $underscoreMap = array('_' => '', '.' => '_', '\\' => '_');
|
private $underscoreMap = array('_' => '', '.' => '_', '\\' => '_');
|
||||||
@ -181,48 +174,22 @@ class Container implements ResettableContainerInterface
|
|||||||
* Setting a service to null resets the service: has() returns false and get()
|
* Setting a service to null resets the service: has() returns false and get()
|
||||||
* behaves in the same way as if the service was never created.
|
* behaves in the same way as if the service was never created.
|
||||||
*
|
*
|
||||||
* Note: The $scope parameter is deprecated since version 2.8 and will be removed in 3.0.
|
|
||||||
*
|
|
||||||
* @param string $id The service identifier
|
* @param string $id The service identifier
|
||||||
* @param object $service The service instance
|
* @param object $service The service instance
|
||||||
* @param string $scope The scope of the service
|
|
||||||
*
|
|
||||||
* @throws RuntimeException When trying to set a service in an inactive scope
|
|
||||||
* @throws InvalidArgumentException When trying to set a service in the prototype scope
|
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
public function set($id, $service, $scope = self::SCOPE_CONTAINER)
|
public function set($id, $service)
|
||||||
{
|
{
|
||||||
if (!in_array($scope, array('container', 'request')) || ('request' === $scope && 'request' !== $id)) {
|
|
||||||
@trigger_error('The concept of container scopes is deprecated since version 2.8 and will be removed in 3.0. Omit the third parameter.', E_USER_DEPRECATED);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self::SCOPE_PROTOTYPE === $scope) {
|
|
||||||
throw new InvalidArgumentException(sprintf('You cannot set service "%s" of scope "prototype".', $id));
|
|
||||||
}
|
|
||||||
|
|
||||||
$id = strtolower($id);
|
$id = strtolower($id);
|
||||||
|
|
||||||
if ('service_container' === $id) {
|
if ('service_container' === $id) {
|
||||||
throw new InvalidArgumentException('You cannot set service "service_container".');
|
throw new InvalidArgumentException('You cannot set service "service_container".');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (self::SCOPE_CONTAINER !== $scope) {
|
|
||||||
if (!isset($this->scopedServices[$scope])) {
|
|
||||||
throw new RuntimeException(sprintf('You cannot set service "%s" of inactive scope.', $id));
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->scopedServices[$scope][$id] = $service;
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->services[$id] = $service;
|
$this->services[$id] = $service;
|
||||||
|
|
||||||
if (null === $service) {
|
if (null === $service) {
|
||||||
if (self::SCOPE_CONTAINER !== $scope) {
|
|
||||||
unset($this->scopedServices[$scope][$id]);
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($this->services[$id]);
|
unset($this->services[$id]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -333,10 +300,6 @@ class Container implements ResettableContainerInterface
|
|||||||
unset($this->services[$id]);
|
unset($this->services[$id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($e instanceof InactiveScopeException && self::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -373,10 +336,6 @@ class Container implements ResettableContainerInterface
|
|||||||
*/
|
*/
|
||||||
public function reset()
|
public function reset()
|
||||||
{
|
{
|
||||||
if (!empty($this->scopedServices)) {
|
|
||||||
throw new LogicException('Resetting the container is not allowed when a scope is active.');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->services = array();
|
$this->services = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -399,193 +358,6 @@ class Container implements ResettableContainerInterface
|
|||||||
return array_unique(array_merge($ids, array_keys($this->services)));
|
return array_unique(array_merge($ids, array_keys($this->services)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This is called when you enter a scope.
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
*
|
|
||||||
* @throws RuntimeException When the parent scope is inactive
|
|
||||||
* @throws InvalidArgumentException When the scope does not exist
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*
|
|
||||||
* @deprecated since version 2.8, to be removed in 3.0.
|
|
||||||
*/
|
|
||||||
public function enterScope($name)
|
|
||||||
{
|
|
||||||
if ('request' !== $name) {
|
|
||||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($this->scopes[$name])) {
|
|
||||||
throw new InvalidArgumentException(sprintf('The scope "%s" does not exist.', $name));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (self::SCOPE_CONTAINER !== $this->scopes[$name] && !isset($this->scopedServices[$this->scopes[$name]])) {
|
|
||||||
throw new RuntimeException(sprintf('The parent scope "%s" must be active when entering this scope.', $this->scopes[$name]));
|
|
||||||
}
|
|
||||||
|
|
||||||
// check if a scope of this name is already active, if so we need to
|
|
||||||
// remove all services of this scope, and those of any of its child
|
|
||||||
// scopes from the global services map
|
|
||||||
if (isset($this->scopedServices[$name])) {
|
|
||||||
$services = array($this->services, $name => $this->scopedServices[$name]);
|
|
||||||
unset($this->scopedServices[$name]);
|
|
||||||
|
|
||||||
foreach ($this->scopeChildren[$name] as $child) {
|
|
||||||
if (isset($this->scopedServices[$child])) {
|
|
||||||
$services[$child] = $this->scopedServices[$child];
|
|
||||||
unset($this->scopedServices[$child]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// update global map
|
|
||||||
$this->services = call_user_func_array('array_diff_key', $services);
|
|
||||||
array_shift($services);
|
|
||||||
|
|
||||||
// add stack entry for this scope so we can restore the removed services later
|
|
||||||
if (!isset($this->scopeStacks[$name])) {
|
|
||||||
$this->scopeStacks[$name] = new \SplStack();
|
|
||||||
}
|
|
||||||
$this->scopeStacks[$name]->push($services);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->scopedServices[$name] = array();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This is called to leave the current scope, and move back to the parent
|
|
||||||
* scope.
|
|
||||||
*
|
|
||||||
* @param string $name The name of the scope to leave
|
|
||||||
*
|
|
||||||
* @throws InvalidArgumentException if the scope is not active
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*
|
|
||||||
* @deprecated since version 2.8, to be removed in 3.0.
|
|
||||||
*/
|
|
||||||
public function leaveScope($name)
|
|
||||||
{
|
|
||||||
if ('request' !== $name) {
|
|
||||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!isset($this->scopedServices[$name])) {
|
|
||||||
throw new InvalidArgumentException(sprintf('The scope "%s" is not active.', $name));
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove all services of this scope, or any of its child scopes from
|
|
||||||
// the global service map
|
|
||||||
$services = array($this->services, $this->scopedServices[$name]);
|
|
||||||
unset($this->scopedServices[$name]);
|
|
||||||
|
|
||||||
foreach ($this->scopeChildren[$name] as $child) {
|
|
||||||
if (isset($this->scopedServices[$child])) {
|
|
||||||
$services[] = $this->scopedServices[$child];
|
|
||||||
unset($this->scopedServices[$child]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// update global map
|
|
||||||
$this->services = call_user_func_array('array_diff_key', $services);
|
|
||||||
|
|
||||||
// check if we need to restore services of a previous scope of this type
|
|
||||||
if (isset($this->scopeStacks[$name]) && count($this->scopeStacks[$name]) > 0) {
|
|
||||||
$services = $this->scopeStacks[$name]->pop();
|
|
||||||
$this->scopedServices += $services;
|
|
||||||
|
|
||||||
if ($this->scopeStacks[$name]->isEmpty()) {
|
|
||||||
unset($this->scopeStacks[$name]);
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($services as $array) {
|
|
||||||
foreach ($array as $id => $service) {
|
|
||||||
$this->set($id, $service, $name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a scope to the container.
|
|
||||||
*
|
|
||||||
* @param ScopeInterface $scope
|
|
||||||
*
|
|
||||||
* @throws InvalidArgumentException
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*
|
|
||||||
* @deprecated since version 2.8, to be removed in 3.0.
|
|
||||||
*/
|
|
||||||
public function addScope(ScopeInterface $scope)
|
|
||||||
{
|
|
||||||
$name = $scope->getName();
|
|
||||||
$parentScope = $scope->getParentName();
|
|
||||||
|
|
||||||
if ('request' !== $name) {
|
|
||||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
|
|
||||||
}
|
|
||||||
if (self::SCOPE_CONTAINER === $name || self::SCOPE_PROTOTYPE === $name) {
|
|
||||||
throw new InvalidArgumentException(sprintf('The scope "%s" is reserved.', $name));
|
|
||||||
}
|
|
||||||
if (isset($this->scopes[$name])) {
|
|
||||||
throw new InvalidArgumentException(sprintf('A scope with name "%s" already exists.', $name));
|
|
||||||
}
|
|
||||||
if (self::SCOPE_CONTAINER !== $parentScope && !isset($this->scopes[$parentScope])) {
|
|
||||||
throw new InvalidArgumentException(sprintf('The parent scope "%s" does not exist, or is invalid.', $parentScope));
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->scopes[$name] = $parentScope;
|
|
||||||
$this->scopeChildren[$name] = array();
|
|
||||||
|
|
||||||
// normalize the child relations
|
|
||||||
while ($parentScope !== self::SCOPE_CONTAINER) {
|
|
||||||
$this->scopeChildren[$parentScope][] = $name;
|
|
||||||
$parentScope = $this->scopes[$parentScope];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether this container has a certain scope.
|
|
||||||
*
|
|
||||||
* @param string $name The name of the scope
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*
|
|
||||||
* @deprecated since version 2.8, to be removed in 3.0.
|
|
||||||
*/
|
|
||||||
public function hasScope($name)
|
|
||||||
{
|
|
||||||
if ('request' !== $name) {
|
|
||||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
|
|
||||||
}
|
|
||||||
|
|
||||||
return isset($this->scopes[$name]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns whether this scope is currently active.
|
|
||||||
*
|
|
||||||
* This does not actually check if the passed scope actually exists.
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*
|
|
||||||
* @deprecated since version 2.8, to be removed in 3.0.
|
|
||||||
*/
|
|
||||||
public function isScopeActive($name)
|
|
||||||
{
|
|
||||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
|
|
||||||
|
|
||||||
return isset($this->scopedServices[$name]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Camelizes a string.
|
* Camelizes a string.
|
||||||
*
|
*
|
||||||
|
@ -15,7 +15,6 @@ use Symfony\Component\DependencyInjection\Compiler\Compiler;
|
|||||||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
|
||||||
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
|
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
|
||||||
use Symfony\Component\DependencyInjection\Exception\BadMethodCallException;
|
use Symfony\Component\DependencyInjection\Exception\BadMethodCallException;
|
||||||
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
|
|
||||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||||
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
||||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||||
@ -352,56 +351,17 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||||||
return $this->compiler;
|
return $this->compiler;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns all Scopes.
|
|
||||||
*
|
|
||||||
* @return array An array of scopes
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*
|
|
||||||
* @deprecated since version 2.8, to be removed in 3.0.
|
|
||||||
*/
|
|
||||||
public function getScopes($triggerDeprecationError = true)
|
|
||||||
{
|
|
||||||
if ($triggerDeprecationError) {
|
|
||||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->scopes;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns all Scope children.
|
|
||||||
*
|
|
||||||
* @return array An array of scope children.
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*
|
|
||||||
* @deprecated since version 2.8, to be removed in 3.0.
|
|
||||||
*/
|
|
||||||
public function getScopeChildren($triggerDeprecationError = true)
|
|
||||||
{
|
|
||||||
if ($triggerDeprecationError) {
|
|
||||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->scopeChildren;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a service.
|
* Sets a service.
|
||||||
*
|
*
|
||||||
* Note: The $scope parameter is deprecated since version 2.8 and will be removed in 3.0.
|
|
||||||
*
|
|
||||||
* @param string $id The service identifier
|
* @param string $id The service identifier
|
||||||
* @param object $service The service instance
|
* @param object $service The service instance
|
||||||
* @param string $scope The scope
|
|
||||||
*
|
*
|
||||||
* @throws BadMethodCallException When this ContainerBuilder is frozen
|
* @throws BadMethodCallException When this ContainerBuilder is frozen
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
public function set($id, $service, $scope = self::SCOPE_CONTAINER)
|
public function set($id, $service)
|
||||||
{
|
{
|
||||||
$id = strtolower($id);
|
$id = strtolower($id);
|
||||||
|
|
||||||
@ -424,7 +384,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||||||
|
|
||||||
unset($this->definitions[$id], $this->aliasDefinitions[$id]);
|
unset($this->definitions[$id], $this->aliasDefinitions[$id]);
|
||||||
|
|
||||||
parent::set($id, $service, $scope);
|
parent::set($id, $service);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -464,7 +424,6 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||||||
* @return object The associated service
|
* @return object The associated service
|
||||||
*
|
*
|
||||||
* @throws InvalidArgumentException when no definitions are available
|
* @throws InvalidArgumentException when no definitions are available
|
||||||
* @throws InactiveScopeException when the current scope is not active
|
|
||||||
* @throws LogicException when a circular dependency is detected
|
* @throws LogicException when a circular dependency is detected
|
||||||
* @throws \Exception
|
* @throws \Exception
|
||||||
*
|
*
|
||||||
@ -501,10 +460,6 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
unset($this->loading[$id]);
|
unset($this->loading[$id]);
|
||||||
|
|
||||||
if ($e instanceof InactiveScopeException && self::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -914,7 +869,6 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||||||
*
|
*
|
||||||
* @return object The service described by the service definition
|
* @return object The service described by the service definition
|
||||||
*
|
*
|
||||||
* @throws RuntimeException When the scope is inactive
|
|
||||||
* @throws RuntimeException When the factory definition is incomplete
|
* @throws RuntimeException When the factory definition is incomplete
|
||||||
* @throws RuntimeException When the service is a synthetic service
|
* @throws RuntimeException When the service is a synthetic service
|
||||||
* @throws InvalidArgumentException When configure callable is not callable
|
* @throws InvalidArgumentException When configure callable is not callable
|
||||||
@ -1135,21 +1089,11 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
|
|||||||
* @param Definition $definition
|
* @param Definition $definition
|
||||||
* @param mixed $service
|
* @param mixed $service
|
||||||
* @param string $id
|
* @param string $id
|
||||||
*
|
|
||||||
* @throws InactiveScopeException
|
|
||||||
*/
|
*/
|
||||||
private function shareService(Definition $definition, $service, $id)
|
private function shareService(Definition $definition, $service, $id)
|
||||||
{
|
{
|
||||||
if ($definition->isShared() && self::SCOPE_PROTOTYPE !== $scope = $definition->getScope(false)) {
|
if ($definition->isShared()) {
|
||||||
if (self::SCOPE_CONTAINER !== $scope && !isset($this->scopedServices[$scope])) {
|
|
||||||
throw new InactiveScopeException($id, $scope);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->services[$lowerId = strtolower($id)] = $service;
|
$this->services[$lowerId = strtolower($id)] = $service;
|
||||||
|
|
||||||
if (self::SCOPE_CONTAINER !== $scope) {
|
|
||||||
$this->scopedServices[$scope][$lowerId] = $service;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,21 +28,16 @@ interface ContainerInterface
|
|||||||
const EXCEPTION_ON_INVALID_REFERENCE = 1;
|
const EXCEPTION_ON_INVALID_REFERENCE = 1;
|
||||||
const NULL_ON_INVALID_REFERENCE = 2;
|
const NULL_ON_INVALID_REFERENCE = 2;
|
||||||
const IGNORE_ON_INVALID_REFERENCE = 3;
|
const IGNORE_ON_INVALID_REFERENCE = 3;
|
||||||
const SCOPE_CONTAINER = 'container';
|
|
||||||
const SCOPE_PROTOTYPE = 'prototype';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets a service.
|
* Sets a service.
|
||||||
*
|
*
|
||||||
* Note: The $scope parameter is deprecated since version 2.8 and will be removed in 3.0.
|
|
||||||
*
|
|
||||||
* @param string $id The service identifier
|
* @param string $id The service identifier
|
||||||
* @param object $service The service instance
|
* @param object $service The service instance
|
||||||
* @param string $scope The scope of the service
|
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
public function set($id, $service, $scope = self::SCOPE_CONTAINER);
|
public function set($id, $service);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a service.
|
* Gets a service.
|
||||||
@ -114,65 +109,4 @@ interface ContainerInterface
|
|||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
public function setParameter($name, $value);
|
public function setParameter($name, $value);
|
||||||
|
|
||||||
/**
|
|
||||||
* Enters the given scope.
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*
|
|
||||||
* @deprecated since version 2.8, to be removed in 3.0.
|
|
||||||
*/
|
|
||||||
public function enterScope($name);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Leaves the current scope, and re-enters the parent scope.
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*
|
|
||||||
* @deprecated since version 2.8, to be removed in 3.0.
|
|
||||||
*/
|
|
||||||
public function leaveScope($name);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a scope to the container.
|
|
||||||
*
|
|
||||||
* @param ScopeInterface $scope
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*
|
|
||||||
* @deprecated since version 2.8, to be removed in 3.0.
|
|
||||||
*/
|
|
||||||
public function addScope(ScopeInterface $scope);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Whether this container has the given scope.
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*
|
|
||||||
* @deprecated since version 2.8, to be removed in 3.0.
|
|
||||||
*/
|
|
||||||
public function hasScope($name);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Determines whether the given scope is currently active.
|
|
||||||
*
|
|
||||||
* It does however not check if the scope actually exists.
|
|
||||||
*
|
|
||||||
* @param string $name
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*
|
|
||||||
* @deprecated since version 2.8, to be removed in 3.0.
|
|
||||||
*/
|
|
||||||
public function isScopeActive($name);
|
|
||||||
}
|
}
|
||||||
|
@ -27,7 +27,6 @@ class Definition
|
|||||||
private $file;
|
private $file;
|
||||||
private $factory;
|
private $factory;
|
||||||
private $shared = true;
|
private $shared = true;
|
||||||
private $scope = ContainerInterface::SCOPE_CONTAINER;
|
|
||||||
private $properties = array();
|
private $properties = array();
|
||||||
private $calls = array();
|
private $calls = array();
|
||||||
private $configurator;
|
private $configurator;
|
||||||
@ -514,50 +513,6 @@ class Definition
|
|||||||
return $this->shared;
|
return $this->shared;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the scope of the service.
|
|
||||||
*
|
|
||||||
* @param string $scope Whether the service must be shared or not
|
|
||||||
*
|
|
||||||
* @return Definition The current instance
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*
|
|
||||||
* @deprecated since version 2.8, to be removed in 3.0.
|
|
||||||
*/
|
|
||||||
public function setScope($scope, $triggerDeprecationError = true)
|
|
||||||
{
|
|
||||||
if ($triggerDeprecationError) {
|
|
||||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ContainerInterface::SCOPE_PROTOTYPE === $scope) {
|
|
||||||
$this->setShared(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->scope = $scope;
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns the scope of the service.
|
|
||||||
*
|
|
||||||
* @return string
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*
|
|
||||||
* @deprecated since version 2.8, to be removed in 3.0.
|
|
||||||
*/
|
|
||||||
public function getScope($triggerDeprecationError = true)
|
|
||||||
{
|
|
||||||
if ($triggerDeprecationError) {
|
|
||||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->scope;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the visibility of this service.
|
* Sets the visibility of this service.
|
||||||
*
|
*
|
||||||
|
@ -18,7 +18,6 @@ use Symfony\Component\DependencyInjection\Parameter;
|
|||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||||
use Symfony\Component\DependencyInjection\Scope;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GraphvizDumper dumps a service container as a graphviz file.
|
* GraphvizDumper dumps a service container as a graphviz file.
|
||||||
@ -177,7 +176,7 @@ class GraphvizDumper extends Dumper
|
|||||||
} catch (ParameterNotFoundException $e) {
|
} catch (ParameterNotFoundException $e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
$nodes[$id] = array('class' => str_replace('\\', '\\\\', $class), 'attributes' => array_merge($this->options['node.definition'], array('style' => $definition->isShared() && ContainerInterface::SCOPE_PROTOTYPE !== $definition->getScope(false) ? 'filled' : 'dotted')));
|
$nodes[$id] = array('class' => str_replace('\\', '\\\\', $class), 'attributes' => array_merge($this->options['node.definition'], array('style' => $definition->isShared() ? 'filled' : 'dotted')));
|
||||||
$container->setDefinition($id, new Definition('stdClass'));
|
$container->setDefinition($id, new Definition('stdClass'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -205,9 +204,6 @@ class GraphvizDumper extends Dumper
|
|||||||
$container->setDefinitions($this->container->getDefinitions());
|
$container->setDefinitions($this->container->getDefinitions());
|
||||||
$container->setAliases($this->container->getAliases());
|
$container->setAliases($this->container->getAliases());
|
||||||
$container->setResources($this->container->getResources());
|
$container->setResources($this->container->getResources());
|
||||||
foreach ($this->container->getScopes(false) as $scope => $parentScope) {
|
|
||||||
$container->addScope(new Scope($scope, $parentScope));
|
|
||||||
}
|
|
||||||
foreach ($this->container->getExtensions() as $extension) {
|
foreach ($this->container->getExtensions() as $extension) {
|
||||||
$container->registerExtension($extension);
|
$container->registerExtension($extension);
|
||||||
}
|
}
|
||||||
|
@ -382,10 +382,8 @@ class PhpDumper extends Dumper
|
|||||||
$isProxyCandidate = $this->getProxyDumper()->isProxyCandidate($definition);
|
$isProxyCandidate = $this->getProxyDumper()->isProxyCandidate($definition);
|
||||||
$instantiation = '';
|
$instantiation = '';
|
||||||
|
|
||||||
if (!$isProxyCandidate && $definition->isShared() && ContainerInterface::SCOPE_CONTAINER === $definition->getScope(false)) {
|
if (!$isProxyCandidate && $definition->isShared()) {
|
||||||
$instantiation = "\$this->services['$id'] = ".($simple ? '' : '$instance');
|
$instantiation = "\$this->services['$id'] = ".($simple ? '' : '$instance');
|
||||||
} elseif (!$isProxyCandidate && $definition->isShared() && ContainerInterface::SCOPE_PROTOTYPE !== $scope = $definition->getScope(false)) {
|
|
||||||
$instantiation = "\$this->services['$id'] = \$this->scopedServices['$scope']['$id'] = ".($simple ? '' : '$instance');
|
|
||||||
} elseif (!$simple) {
|
} elseif (!$simple) {
|
||||||
$instantiation = '$instance';
|
$instantiation = '$instance';
|
||||||
}
|
}
|
||||||
@ -574,18 +572,10 @@ class PhpDumper extends Dumper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$scope = $definition->getScope(false);
|
|
||||||
if (!in_array($scope, array(ContainerInterface::SCOPE_CONTAINER, ContainerInterface::SCOPE_PROTOTYPE))) {
|
|
||||||
if ($return && 0 === strpos($return[count($return) - 1], '@return')) {
|
|
||||||
$return[] = '';
|
|
||||||
}
|
|
||||||
$return[] = sprintf("@throws InactiveScopeException when the '%s' service is requested while the '%s' scope is not active", $id, $scope);
|
|
||||||
}
|
|
||||||
|
|
||||||
$return = implode("\n * ", $return);
|
$return = implode("\n * ", $return);
|
||||||
|
|
||||||
$doc = '';
|
$doc = '';
|
||||||
if ($definition->isShared() && ContainerInterface::SCOPE_PROTOTYPE !== $scope) {
|
if ($definition->isShared()) {
|
||||||
$doc .= <<<EOF
|
$doc .= <<<EOF
|
||||||
|
|
||||||
*
|
*
|
||||||
@ -629,16 +619,6 @@ EOF;
|
|||||||
|
|
||||||
$code .= $isProxyCandidate ? $this->getProxyDumper()->getProxyFactoryCode($definition, $id) : '';
|
$code .= $isProxyCandidate ? $this->getProxyDumper()->getProxyFactoryCode($definition, $id) : '';
|
||||||
|
|
||||||
if (!in_array($scope, array(ContainerInterface::SCOPE_CONTAINER, ContainerInterface::SCOPE_PROTOTYPE))) {
|
|
||||||
$code .= <<<EOF
|
|
||||||
if (!isset(\$this->scopedServices['$scope'])) {
|
|
||||||
throw new InactiveScopeException('$id', '$scope');
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
EOF;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($definition->isSynthetic()) {
|
if ($definition->isSynthetic()) {
|
||||||
$code .= sprintf(" throw new RuntimeException('You have requested a synthetic service (\"%s\"). The DIC does not know how to construct this service.');\n }\n", $id);
|
$code .= sprintf(" throw new RuntimeException('You have requested a synthetic service (\"%s\"). The DIC does not know how to construct this service.');\n }\n", $id);
|
||||||
} else {
|
} else {
|
||||||
@ -737,7 +717,6 @@ EOF;
|
|||||||
$namespaceLine
|
$namespaceLine
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\DependencyInjection\Container;
|
use Symfony\Component\DependencyInjection\Container;
|
||||||
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
|
|
||||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||||
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
||||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||||
@ -778,12 +757,6 @@ EOF;
|
|||||||
|
|
||||||
EOF;
|
EOF;
|
||||||
|
|
||||||
if (count($scopes = $this->container->getScopes(false)) > 0) {
|
|
||||||
$code .= "\n";
|
|
||||||
$code .= ' $this->scopes = '.$this->dumpValue($scopes).";\n";
|
|
||||||
$code .= ' $this->scopeChildren = '.$this->dumpValue($this->container->getScopeChildren(false)).";\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
$code .= $this->addMethodMap();
|
$code .= $this->addMethodMap();
|
||||||
$code .= $this->addAliases();
|
$code .= $this->addAliases();
|
||||||
|
|
||||||
@ -817,22 +790,7 @@ EOF;
|
|||||||
$code .= "\n \$this->parameters = \$this->getDefaultParameters();\n";
|
$code .= "\n \$this->parameters = \$this->getDefaultParameters();\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$code .= <<<EOF
|
$code .= "\n \$this->services = array();\n";
|
||||||
|
|
||||||
\$this->services =
|
|
||||||
\$this->scopedServices =
|
|
||||||
\$this->scopeStacks = array();
|
|
||||||
EOF;
|
|
||||||
|
|
||||||
$code .= "\n";
|
|
||||||
if (count($scopes = $this->container->getScopes(false)) > 0) {
|
|
||||||
$code .= ' $this->scopes = '.$this->dumpValue($scopes).";\n";
|
|
||||||
$code .= ' $this->scopeChildren = '.$this->dumpValue($this->container->getScopeChildren(false)).";\n";
|
|
||||||
} else {
|
|
||||||
$code .= " \$this->scopes = array();\n";
|
|
||||||
$code .= " \$this->scopeChildren = array();\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
$code .= $this->addMethodMap();
|
$code .= $this->addMethodMap();
|
||||||
$code .= $this->addAliases();
|
$code .= $this->addAliases();
|
||||||
|
|
||||||
|
@ -124,9 +124,6 @@ class XmlDumper extends Dumper
|
|||||||
if (!$definition->isShared()) {
|
if (!$definition->isShared()) {
|
||||||
$service->setAttribute('shared', 'false');
|
$service->setAttribute('shared', 'false');
|
||||||
}
|
}
|
||||||
if (ContainerInterface::SCOPE_CONTAINER !== $scope = $definition->getScope(false)) {
|
|
||||||
$service->setAttribute('scope', $scope);
|
|
||||||
}
|
|
||||||
if (!$definition->isPublic()) {
|
if (!$definition->isPublic()) {
|
||||||
$service->setAttribute('public', 'false');
|
$service->setAttribute('public', 'false');
|
||||||
}
|
}
|
||||||
@ -281,9 +278,6 @@ class XmlDumper extends Dumper
|
|||||||
} elseif ($behaviour == ContainerInterface::IGNORE_ON_INVALID_REFERENCE) {
|
} elseif ($behaviour == ContainerInterface::IGNORE_ON_INVALID_REFERENCE) {
|
||||||
$element->setAttribute('on-invalid', 'ignore');
|
$element->setAttribute('on-invalid', 'ignore');
|
||||||
}
|
}
|
||||||
if (!$value->isStrict(false)) {
|
|
||||||
$element->setAttribute('strict', 'false');
|
|
||||||
}
|
|
||||||
} elseif ($value instanceof Definition) {
|
} elseif ($value instanceof Definition) {
|
||||||
$element->setAttribute('type', 'service');
|
$element->setAttribute('type', 'service');
|
||||||
$this->addService($value, null, $element);
|
$this->addService($value, null, $element);
|
||||||
|
@ -120,10 +120,6 @@ class YamlDumper extends Dumper
|
|||||||
$code .= " shared: false\n";
|
$code .= " shared: false\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ContainerInterface::SCOPE_CONTAINER !== $scope = $definition->getScope(false)) {
|
|
||||||
$code .= sprintf(" scope: %s\n", $scope);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (null !== $decorated = $definition->getDecoratedService()) {
|
if (null !== $decorated = $definition->getDecoratedService()) {
|
||||||
list($decorated, $renamedId, $priority) = $decorated;
|
list($decorated, $renamedId, $priority) = $decorated;
|
||||||
$code .= sprintf(" decorates: %s\n", $decorated);
|
$code .= sprintf(" decorates: %s\n", $decorated);
|
||||||
|
@ -1,41 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Symfony package.
|
|
||||||
*
|
|
||||||
* (c) Fabien Potencier <fabien@symfony.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Symfony\Component\DependencyInjection\Exception;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This exception is thrown when you try to create a service of an inactive scope.
|
|
||||||
*
|
|
||||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
|
||||||
*/
|
|
||||||
class InactiveScopeException extends RuntimeException
|
|
||||||
{
|
|
||||||
private $serviceId;
|
|
||||||
private $scope;
|
|
||||||
|
|
||||||
public function __construct($serviceId, $scope, \Exception $previous = null)
|
|
||||||
{
|
|
||||||
parent::__construct(sprintf('You cannot create a service ("%s") of an inactive scope ("%s").', $serviceId, $scope), 0, $previous);
|
|
||||||
|
|
||||||
$this->serviceId = $serviceId;
|
|
||||||
$this->scope = $scope;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getServiceId()
|
|
||||||
{
|
|
||||||
return $this->serviceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getScope()
|
|
||||||
{
|
|
||||||
return $this->scope;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,65 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Symfony package.
|
|
||||||
*
|
|
||||||
* (c) Fabien Potencier <fabien@symfony.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Symfony\Component\DependencyInjection\Exception;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This exception is thrown when the a scope crossing injection is detected.
|
|
||||||
*
|
|
||||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
|
||||||
*/
|
|
||||||
class ScopeCrossingInjectionException extends RuntimeException
|
|
||||||
{
|
|
||||||
private $sourceServiceId;
|
|
||||||
private $sourceScope;
|
|
||||||
private $destServiceId;
|
|
||||||
private $destScope;
|
|
||||||
|
|
||||||
public function __construct($sourceServiceId, $sourceScope, $destServiceId, $destScope, \Exception $previous = null)
|
|
||||||
{
|
|
||||||
parent::__construct(sprintf(
|
|
||||||
'Scope Crossing Injection detected: The definition "%s" references the service "%s" which belongs to another scope hierarchy. '
|
|
||||||
.'This service might not be available consistently. Generally, it is safer to either move the definition "%s" to scope "%s", or '
|
|
||||||
.'declare "%s" as a child scope of "%s". If you can be sure that the other scope is always active, you can set the reference to strict=false to get rid of this error.',
|
|
||||||
$sourceServiceId,
|
|
||||||
$destServiceId,
|
|
||||||
$sourceServiceId,
|
|
||||||
$destScope,
|
|
||||||
$sourceScope,
|
|
||||||
$destScope
|
|
||||||
), 0, $previous);
|
|
||||||
|
|
||||||
$this->sourceServiceId = $sourceServiceId;
|
|
||||||
$this->sourceScope = $sourceScope;
|
|
||||||
$this->destServiceId = $destServiceId;
|
|
||||||
$this->destScope = $destScope;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getSourceServiceId()
|
|
||||||
{
|
|
||||||
return $this->sourceServiceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getSourceScope()
|
|
||||||
{
|
|
||||||
return $this->sourceScope;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDestServiceId()
|
|
||||||
{
|
|
||||||
return $this->destServiceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDestScope()
|
|
||||||
{
|
|
||||||
return $this->destScope;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,64 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Symfony package.
|
|
||||||
*
|
|
||||||
* (c) Fabien Potencier <fabien@symfony.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Symfony\Component\DependencyInjection\Exception;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Thrown when a scope widening injection is detected.
|
|
||||||
*
|
|
||||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
|
||||||
*/
|
|
||||||
class ScopeWideningInjectionException extends RuntimeException
|
|
||||||
{
|
|
||||||
private $sourceServiceId;
|
|
||||||
private $sourceScope;
|
|
||||||
private $destServiceId;
|
|
||||||
private $destScope;
|
|
||||||
|
|
||||||
public function __construct($sourceServiceId, $sourceScope, $destServiceId, $destScope, \Exception $previous = null)
|
|
||||||
{
|
|
||||||
parent::__construct(sprintf(
|
|
||||||
'Scope Widening Injection detected: The definition "%s" references the service "%s" which belongs to a narrower scope. '
|
|
||||||
.'Generally, it is safer to either move "%s" to scope "%s" or alternatively rely on the provider pattern by injecting the container itself, and requesting the service "%s" each time it is needed. '
|
|
||||||
.'In rare, special cases however that might not be necessary, then you can set the reference to strict=false to get rid of this error.',
|
|
||||||
$sourceServiceId,
|
|
||||||
$destServiceId,
|
|
||||||
$sourceServiceId,
|
|
||||||
$destScope,
|
|
||||||
$destServiceId
|
|
||||||
), 0, $previous);
|
|
||||||
|
|
||||||
$this->sourceServiceId = $sourceServiceId;
|
|
||||||
$this->sourceScope = $sourceScope;
|
|
||||||
$this->destServiceId = $destServiceId;
|
|
||||||
$this->destScope = $destScope;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getSourceServiceId()
|
|
||||||
{
|
|
||||||
return $this->sourceServiceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getSourceScope()
|
|
||||||
{
|
|
||||||
return $this->sourceScope;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDestServiceId()
|
|
||||||
{
|
|
||||||
return $this->destServiceId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDestScope()
|
|
||||||
{
|
|
||||||
return $this->destScope;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,25 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Symfony package.
|
|
||||||
*
|
|
||||||
* (c) Fabien Potencier <fabien@symfony.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Symfony\Component\DependencyInjection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* IntrospectableContainerInterface defines additional introspection functionality
|
|
||||||
* for containers, allowing logic to be implemented based on a Container's state.
|
|
||||||
*
|
|
||||||
* @author Evan Villemez <evillemez@gmail.com>
|
|
||||||
*
|
|
||||||
* @deprecated Since version 3.0, to be removed in 4.0. Use ContainerInterface
|
|
||||||
* instead.
|
|
||||||
*/
|
|
||||||
interface IntrospectableContainerInterface extends ContainerInterface
|
|
||||||
{
|
|
||||||
}
|
|
@ -167,13 +167,6 @@ class YamlFileLoader extends FileLoader
|
|||||||
$definition->setShared($service['shared']);
|
$definition->setShared($service['shared']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isset($service['scope'])) {
|
|
||||||
if ('request' !== $id) {
|
|
||||||
@trigger_error(sprintf('The "scope" key of service "%s" in file "%s" is deprecated since version 2.8 and will be removed in 3.0.', $id, $file), E_USER_DEPRECATED);
|
|
||||||
}
|
|
||||||
$definition->setScope($service['scope'], false);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isset($service['synthetic'])) {
|
if (isset($service['synthetic'])) {
|
||||||
$definition->setSynthetic($service['synthetic']);
|
$definition->setSynthetic($service['synthetic']);
|
||||||
}
|
}
|
||||||
|
@ -88,7 +88,6 @@
|
|||||||
<xsd:attribute name="id" type="xsd:string" />
|
<xsd:attribute name="id" type="xsd:string" />
|
||||||
<xsd:attribute name="class" type="xsd:string" />
|
<xsd:attribute name="class" type="xsd:string" />
|
||||||
<xsd:attribute name="shared" type="boolean" />
|
<xsd:attribute name="shared" type="boolean" />
|
||||||
<xsd:attribute name="scope" type="xsd:string" />
|
|
||||||
<xsd:attribute name="public" type="boolean" />
|
<xsd:attribute name="public" type="boolean" />
|
||||||
<xsd:attribute name="synthetic" type="boolean" />
|
<xsd:attribute name="synthetic" type="boolean" />
|
||||||
<xsd:attribute name="lazy" type="boolean" />
|
<xsd:attribute name="lazy" type="boolean" />
|
||||||
|
@ -22,24 +22,19 @@ class Reference
|
|||||||
{
|
{
|
||||||
private $id;
|
private $id;
|
||||||
private $invalidBehavior;
|
private $invalidBehavior;
|
||||||
private $strict;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*
|
*
|
||||||
* Note: The $strict parameter is deprecated since version 2.8 and will be removed in 3.0.
|
|
||||||
*
|
|
||||||
* @param string $id The service identifier
|
* @param string $id The service identifier
|
||||||
* @param int $invalidBehavior The behavior when the service does not exist
|
* @param int $invalidBehavior The behavior when the service does not exist
|
||||||
* @param bool $strict Sets how this reference is validated
|
|
||||||
*
|
*
|
||||||
* @see Container
|
* @see Container
|
||||||
*/
|
*/
|
||||||
public function __construct($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, $strict = true)
|
public function __construct($id, $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE)
|
||||||
{
|
{
|
||||||
$this->id = strtolower($id);
|
$this->id = strtolower($id);
|
||||||
$this->invalidBehavior = $invalidBehavior;
|
$this->invalidBehavior = $invalidBehavior;
|
||||||
$this->strict = $strict;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -61,20 +56,4 @@ class Reference
|
|||||||
{
|
{
|
||||||
return $this->invalidBehavior;
|
return $this->invalidBehavior;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns true when this Reference is strict.
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*
|
|
||||||
* @deprecated since version 2.8, to be removed in 3.0.
|
|
||||||
*/
|
|
||||||
public function isStrict($triggerDeprecationError = true)
|
|
||||||
{
|
|
||||||
if ($triggerDeprecationError) {
|
|
||||||
@trigger_error('The '.__METHOD__.' method is deprecated since version 2.8 and will be removed in 3.0.', E_USER_DEPRECATED);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->strict;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -1,52 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Symfony package.
|
|
||||||
*
|
|
||||||
* (c) Fabien Potencier <fabien@symfony.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Symfony\Component\DependencyInjection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Scope class.
|
|
||||||
*
|
|
||||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*
|
|
||||||
* @deprecated since version 2.8, to be removed in 3.0.
|
|
||||||
*/
|
|
||||||
class Scope implements ScopeInterface
|
|
||||||
{
|
|
||||||
private $name;
|
|
||||||
private $parentName;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
public function __construct($name, $parentName = ContainerInterface::SCOPE_CONTAINER)
|
|
||||||
{
|
|
||||||
$this->name = $name;
|
|
||||||
$this->parentName = $parentName;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
public function getName()
|
|
||||||
{
|
|
||||||
return $this->name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
public function getParentName()
|
|
||||||
{
|
|
||||||
return $this->parentName;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file is part of the Symfony package.
|
|
||||||
*
|
|
||||||
* (c) Fabien Potencier <fabien@symfony.com>
|
|
||||||
*
|
|
||||||
* For the full copyright and license information, please view the LICENSE
|
|
||||||
* file that was distributed with this source code.
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Symfony\Component\DependencyInjection;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Scope Interface.
|
|
||||||
*
|
|
||||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
|
||||||
*
|
|
||||||
* @api
|
|
||||||
*
|
|
||||||
* @deprecated since version 2.8, to be removed in 3.0.
|
|
||||||
*/
|
|
||||||
interface ScopeInterface
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
public function getName();
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @api
|
|
||||||
*/
|
|
||||||
public function getParentName();
|
|
||||||
}
|
|
@ -28,30 +28,6 @@ class CheckDefinitionValidityPassTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->process($container);
|
$this->process($container);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testProcessDetectsSyntheticPrototypeDefinitions()
|
|
||||||
{
|
|
||||||
$container = new ContainerBuilder();
|
|
||||||
$container->register('a')->setSynthetic(true)->setScope(ContainerInterface::SCOPE_PROTOTYPE);
|
|
||||||
|
|
||||||
$this->process($container);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testProcessDetectsSharedPrototypeDefinitions()
|
|
||||||
{
|
|
||||||
$container = new ContainerBuilder();
|
|
||||||
$container->register('a')->setShared(true)->setScope(ContainerInterface::SCOPE_PROTOTYPE);
|
|
||||||
|
|
||||||
$this->process($container);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
* @expectedException \Symfony\Component\DependencyInjection\Exception\RuntimeException
|
||||||
*/
|
*/
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||||
|
|
||||||
use Symfony\Component\DependencyInjection\Scope;
|
|
||||||
use Symfony\Component\DependencyInjection\Compiler\CheckReferenceValidityPass;
|
use Symfony\Component\DependencyInjection\Compiler\CheckReferenceValidityPass;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\DependencyInjection\Reference;
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
@ -19,62 +18,6 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|||||||
|
|
||||||
class CheckReferenceValidityPassTest extends \PHPUnit_Framework_TestCase
|
class CheckReferenceValidityPassTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testProcessIgnoresScopeWideningIfNonStrictReference()
|
|
||||||
{
|
|
||||||
$container = new ContainerBuilder();
|
|
||||||
$container->register('a')->addArgument(new Reference('b', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false));
|
|
||||||
$container->register('b')->setScope('prototype');
|
|
||||||
|
|
||||||
$this->process($container);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \RuntimeException
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testProcessDetectsScopeWidening()
|
|
||||||
{
|
|
||||||
$container = new ContainerBuilder();
|
|
||||||
$container->register('a')->addArgument(new Reference('b'));
|
|
||||||
$container->register('b')->setScope('prototype');
|
|
||||||
|
|
||||||
$this->process($container);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testProcessIgnoresCrossScopeHierarchyReferenceIfNotStrict()
|
|
||||||
{
|
|
||||||
$container = new ContainerBuilder();
|
|
||||||
$container->addScope(new Scope('a'));
|
|
||||||
$container->addScope(new Scope('b'));
|
|
||||||
|
|
||||||
$container->register('a')->setScope('a')->addArgument(new Reference('b', ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE, false));
|
|
||||||
$container->register('b')->setScope('b');
|
|
||||||
|
|
||||||
$this->process($container);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \RuntimeException
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testProcessDetectsCrossScopeHierarchyReference()
|
|
||||||
{
|
|
||||||
$container = new ContainerBuilder();
|
|
||||||
$container->addScope(new Scope('a'));
|
|
||||||
$container->addScope(new Scope('b'));
|
|
||||||
|
|
||||||
$container->register('a')->setScope('a')->addArgument(new Reference('b'));
|
|
||||||
$container->register('b')->setScope('b');
|
|
||||||
|
|
||||||
$this->process($container);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException \RuntimeException
|
* @expectedException \RuntimeException
|
||||||
*/
|
*/
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
|
||||||
|
|
||||||
use Symfony\Component\DependencyInjection\Scope;
|
|
||||||
use Symfony\Component\DependencyInjection\Definition;
|
use Symfony\Component\DependencyInjection\Definition;
|
||||||
use Symfony\Component\DependencyInjection\Compiler\AnalyzeServiceReferencesPass;
|
use Symfony\Component\DependencyInjection\Compiler\AnalyzeServiceReferencesPass;
|
||||||
use Symfony\Component\DependencyInjection\Compiler\RepeatedPass;
|
use Symfony\Component\DependencyInjection\Compiler\RepeatedPass;
|
||||||
@ -61,29 +60,6 @@ class InlineServiceDefinitionsPassTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertSame($ref, $arguments[0]);
|
$this->assertSame($ref, $arguments[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testProcessDoesNotInlineWhenAliasedServiceIsNotOfPrototypeScope()
|
|
||||||
{
|
|
||||||
$container = new ContainerBuilder();
|
|
||||||
$container
|
|
||||||
->register('foo')
|
|
||||||
->setPublic(false)
|
|
||||||
;
|
|
||||||
$container->setAlias('moo', 'foo');
|
|
||||||
|
|
||||||
$container
|
|
||||||
->register('service')
|
|
||||||
->setArguments(array($ref = new Reference('foo')))
|
|
||||||
;
|
|
||||||
|
|
||||||
$this->process($container);
|
|
||||||
|
|
||||||
$arguments = $container->getDefinition('service')->getArguments();
|
|
||||||
$this->assertSame($ref, $arguments[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testProcessDoesInlineNonSharedService()
|
public function testProcessDoesInlineNonSharedService()
|
||||||
{
|
{
|
||||||
$container = new ContainerBuilder();
|
$container = new ContainerBuilder();
|
||||||
@ -113,38 +89,6 @@ class InlineServiceDefinitionsPassTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertNotSame($container->getDefinition('bar'), $arguments[2]);
|
$this->assertNotSame($container->getDefinition('bar'), $arguments[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testProcessDoesInlineServiceOfPrototypeScope()
|
|
||||||
{
|
|
||||||
$container = new ContainerBuilder();
|
|
||||||
$container
|
|
||||||
->register('foo')
|
|
||||||
->setScope('prototype')
|
|
||||||
;
|
|
||||||
$container
|
|
||||||
->register('bar')
|
|
||||||
->setPublic(false)
|
|
||||||
->setScope('prototype')
|
|
||||||
;
|
|
||||||
$container->setAlias('moo', 'bar');
|
|
||||||
|
|
||||||
$container
|
|
||||||
->register('service')
|
|
||||||
->setArguments(array(new Reference('foo'), $ref = new Reference('moo'), new Reference('bar')))
|
|
||||||
;
|
|
||||||
|
|
||||||
$this->process($container);
|
|
||||||
|
|
||||||
$arguments = $container->getDefinition('service')->getArguments();
|
|
||||||
$this->assertEquals($container->getDefinition('foo'), $arguments[0]);
|
|
||||||
$this->assertNotSame($container->getDefinition('foo'), $arguments[0]);
|
|
||||||
$this->assertSame($ref, $arguments[1]);
|
|
||||||
$this->assertEquals($container->getDefinition('bar'), $arguments[2]);
|
|
||||||
$this->assertNotSame($container->getDefinition('bar'), $arguments[2]);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testProcessInlinesIfMultipleReferencesButAllFromTheSameDefinition()
|
public function testProcessInlinesIfMultipleReferencesButAllFromTheSameDefinition()
|
||||||
{
|
{
|
||||||
$container = new ContainerBuilder();
|
$container = new ContainerBuilder();
|
||||||
@ -243,23 +187,6 @@ class InlineServiceDefinitionsPassTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertSame($ref, $args[0]);
|
$this->assertSame($ref, $args[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testProcessInlinesOnlyIfSameScope()
|
|
||||||
{
|
|
||||||
$container = new ContainerBuilder();
|
|
||||||
|
|
||||||
$container->addScope(new Scope('foo'));
|
|
||||||
$a = $container->register('a')->setPublic(false)->setScope('foo');
|
|
||||||
$b = $container->register('b')->addArgument(new Reference('a'));
|
|
||||||
|
|
||||||
$this->process($container);
|
|
||||||
$arguments = $b->getArguments();
|
|
||||||
$this->assertEquals(new Reference('a'), $arguments[0]);
|
|
||||||
$this->assertTrue($container->hasDefinition('a'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testProcessDoesNotInlineWhenServiceIsPrivateButLazy()
|
public function testProcessDoesNotInlineWhenServiceIsPrivateButLazy()
|
||||||
{
|
{
|
||||||
$container = new ContainerBuilder();
|
$container = new ContainerBuilder();
|
||||||
|
@ -79,28 +79,6 @@ class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertFalse($def->isAbstract());
|
$this->assertFalse($def->isAbstract());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testProcessDoesNotCopyScope()
|
|
||||||
{
|
|
||||||
$container = new ContainerBuilder();
|
|
||||||
|
|
||||||
$container
|
|
||||||
->register('parent')
|
|
||||||
->setScope('foo')
|
|
||||||
;
|
|
||||||
|
|
||||||
$container
|
|
||||||
->setDefinition('child', new DefinitionDecorator('parent'))
|
|
||||||
;
|
|
||||||
|
|
||||||
$this->process($container);
|
|
||||||
|
|
||||||
$def = $container->getDefinition('child');
|
|
||||||
$this->assertEquals(ContainerInterface::SCOPE_CONTAINER, $def->getScope());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testProcessDoesNotCopyTags()
|
public function testProcessDoesNotCopyTags()
|
||||||
{
|
{
|
||||||
$container = new ContainerBuilder();
|
$container = new ContainerBuilder();
|
||||||
|
@ -61,23 +61,6 @@ class ResolveInvalidReferencesPassTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertEquals(array(), $def->getProperties());
|
$this->assertEquals(array(), $def->getProperties());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testStrictFlagIsPreserved()
|
|
||||||
{
|
|
||||||
$container = new ContainerBuilder();
|
|
||||||
$container->register('bar');
|
|
||||||
$def = $container
|
|
||||||
->register('foo')
|
|
||||||
->addArgument(new Reference('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE, false))
|
|
||||||
;
|
|
||||||
|
|
||||||
$this->process($container);
|
|
||||||
|
|
||||||
$this->assertFalse($def->getArgument(0)->isStrict());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function process(ContainerBuilder $container)
|
protected function process(ContainerBuilder $container)
|
||||||
{
|
{
|
||||||
$pass = new ResolveInvalidReferencesPass();
|
$pass = new ResolveInvalidReferencesPass();
|
||||||
|
@ -20,11 +20,9 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\DependencyInjection\Definition;
|
use Symfony\Component\DependencyInjection\Definition;
|
||||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||||
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
|
|
||||||
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
|
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
|
||||||
use Symfony\Component\DependencyInjection\Reference;
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||||
use Symfony\Component\DependencyInjection\Scope;
|
|
||||||
use Symfony\Component\Config\Resource\FileResource;
|
use Symfony\Component\Config\Resource\FileResource;
|
||||||
use Symfony\Component\ExpressionLanguage\Expression;
|
use Symfony\Component\ExpressionLanguage\Expression;
|
||||||
|
|
||||||
@ -152,29 +150,6 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
|
|||||||
$builder->get('foo');
|
$builder->get('foo');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::get
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testGetReturnsNullOnInactiveScope()
|
|
||||||
{
|
|
||||||
$builder = new ContainerBuilder();
|
|
||||||
$builder->register('foo', 'stdClass')->setScope('request');
|
|
||||||
|
|
||||||
$this->assertNull($builder->get('foo', ContainerInterface::NULL_ON_INVALID_REFERENCE));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::get
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testGetReturnsNullOnInactiveScopeWhenServiceIsCreatedByAMethod()
|
|
||||||
{
|
|
||||||
$builder = new ProjectContainer();
|
|
||||||
|
|
||||||
$this->assertNull($builder->get('foobaz', ContainerInterface::NULL_ON_INVALID_REFERENCE));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::getServiceIds
|
* @covers Symfony\Component\DependencyInjection\ContainerBuilder::getServiceIds
|
||||||
*/
|
*/
|
||||||
@ -777,11 +752,3 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
|
|||||||
class FooClass
|
class FooClass
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
class ProjectContainer extends ContainerBuilder
|
|
||||||
{
|
|
||||||
public function getFoobazService()
|
|
||||||
{
|
|
||||||
throw new InactiveScopeException('foo', 'request');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -11,11 +11,9 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\DependencyInjection\Tests;
|
namespace Symfony\Component\DependencyInjection\Tests;
|
||||||
|
|
||||||
use Symfony\Component\DependencyInjection\Scope;
|
|
||||||
use Symfony\Component\DependencyInjection\Container;
|
use Symfony\Component\DependencyInjection\Container;
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
|
||||||
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
|
|
||||||
|
|
||||||
class ContainerTest extends \PHPUnit_Framework_TestCase
|
class ContainerTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
@ -146,7 +144,7 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$sc = new ProjectServiceContainer();
|
$sc = new ProjectServiceContainer();
|
||||||
$sc->set('foo', $obj = new \stdClass());
|
$sc->set('foo', $obj = new \stdClass());
|
||||||
$this->assertEquals(array('scoped', 'scoped_foo', 'inactive', 'bar', 'foo_bar', 'foo.baz', 'circular', 'throw_exception', 'throws_exception_on_service_configuration', 'service_container', 'foo'), $sc->getServiceIds(), '->getServiceIds() returns defined service ids by getXXXService() methods, followed by service ids defined by set()');
|
$this->assertEquals(array('bar', 'foo_bar', 'foo.baz', 'circular', 'throw_exception', 'throws_exception_on_service_configuration', 'service_container', 'foo'), $sc->getServiceIds(), '->getServiceIds() returns defined service ids by getXXXService() methods, followed by service ids defined by set()');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -169,42 +167,6 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertFalse($sc->has('foo'), '->set() with null service resets the service');
|
$this->assertFalse($sc->has('foo'), '->set() with null service resets the service');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \InvalidArgumentException
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testSetDoesNotAllowPrototypeScope()
|
|
||||||
{
|
|
||||||
$c = new Container();
|
|
||||||
$c->set('foo', new \stdClass(), Container::SCOPE_PROTOTYPE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \RuntimeException
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testSetDoesNotAllowInactiveScope()
|
|
||||||
{
|
|
||||||
$c = new Container();
|
|
||||||
$c->addScope(new Scope('foo'));
|
|
||||||
$c->set('foo', new \stdClass(), 'foo');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testSetAlsoSetsScopedService()
|
|
||||||
{
|
|
||||||
$c = new Container();
|
|
||||||
$c->addScope(new Scope('foo'));
|
|
||||||
$c->enterScope('foo');
|
|
||||||
$c->set('foo', $foo = new \stdClass(), 'foo');
|
|
||||||
|
|
||||||
$scoped = $this->getField($c, 'scopedServices');
|
|
||||||
$this->assertTrue(isset($scoped['foo']['foo']), '->set() sets a scoped service');
|
|
||||||
$this->assertSame($foo, $scoped['foo']['foo'], '->set() sets a scoped service');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Component\DependencyInjection\Container::get
|
* @covers Symfony\Component\DependencyInjection\Container::get
|
||||||
*/
|
*/
|
||||||
@ -267,16 +229,6 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers Symfony\Component\DependencyInjection\Container::get
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testGetReturnsNullOnInactiveScope()
|
|
||||||
{
|
|
||||||
$sc = new ProjectServiceContainer();
|
|
||||||
$this->assertNull($sc->get('inactive', ContainerInterface::NULL_ON_INVALID_REFERENCE));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Component\DependencyInjection\Container::has
|
* @covers Symfony\Component\DependencyInjection\Container::has
|
||||||
*/
|
*/
|
||||||
@ -318,292 +270,6 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertNull($c->get('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE));
|
$this->assertNull($c->get('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\LogicException
|
|
||||||
* @expectedExceptionMessage Resetting the container is not allowed when a scope is active.
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testCannotResetInActiveScope()
|
|
||||||
{
|
|
||||||
$c = new Container();
|
|
||||||
$c->addScope(new Scope('foo'));
|
|
||||||
$c->set('bar', new \stdClass());
|
|
||||||
|
|
||||||
$c->enterScope('foo');
|
|
||||||
|
|
||||||
$c->reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testResetAfterLeavingScope()
|
|
||||||
{
|
|
||||||
$c = new Container();
|
|
||||||
$c->addScope(new Scope('foo'));
|
|
||||||
$c->set('bar', new \stdClass());
|
|
||||||
|
|
||||||
$c->enterScope('foo');
|
|
||||||
$c->leaveScope('foo');
|
|
||||||
|
|
||||||
$c->reset();
|
|
||||||
|
|
||||||
$this->assertNull($c->get('bar', ContainerInterface::NULL_ON_INVALID_REFERENCE));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testEnterLeaveCurrentScope()
|
|
||||||
{
|
|
||||||
$container = new ProjectServiceContainer();
|
|
||||||
$container->addScope(new Scope('foo'));
|
|
||||||
|
|
||||||
$container->enterScope('foo');
|
|
||||||
$scoped1 = $container->get('scoped');
|
|
||||||
$scopedFoo1 = $container->get('scoped_foo');
|
|
||||||
|
|
||||||
$container->enterScope('foo');
|
|
||||||
$scoped2 = $container->get('scoped');
|
|
||||||
$scoped3 = $container->get('SCOPED');
|
|
||||||
$scopedFoo2 = $container->get('scoped_foo');
|
|
||||||
|
|
||||||
$container->leaveScope('foo');
|
|
||||||
$scoped4 = $container->get('scoped');
|
|
||||||
$scopedFoo3 = $container->get('scoped_foo');
|
|
||||||
|
|
||||||
$this->assertNotSame($scoped1, $scoped2);
|
|
||||||
$this->assertSame($scoped2, $scoped3);
|
|
||||||
$this->assertSame($scoped1, $scoped4);
|
|
||||||
$this->assertNotSame($scopedFoo1, $scopedFoo2);
|
|
||||||
$this->assertSame($scopedFoo1, $scopedFoo3);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testEnterLeaveScopeWithChildScopes()
|
|
||||||
{
|
|
||||||
$container = new Container();
|
|
||||||
$container->addScope(new Scope('foo'));
|
|
||||||
$container->addScope(new Scope('bar', 'foo'));
|
|
||||||
|
|
||||||
$this->assertFalse($container->isScopeActive('foo'));
|
|
||||||
|
|
||||||
$container->enterScope('foo');
|
|
||||||
$container->enterScope('bar');
|
|
||||||
|
|
||||||
$this->assertTrue($container->isScopeActive('foo'));
|
|
||||||
$this->assertFalse($container->has('a'));
|
|
||||||
|
|
||||||
$a = new \stdClass();
|
|
||||||
$container->set('a', $a, 'bar');
|
|
||||||
|
|
||||||
$scoped = $this->getField($container, 'scopedServices');
|
|
||||||
$this->assertTrue(isset($scoped['bar']['a']));
|
|
||||||
$this->assertSame($a, $scoped['bar']['a']);
|
|
||||||
$this->assertTrue($container->has('a'));
|
|
||||||
|
|
||||||
$container->leaveScope('foo');
|
|
||||||
|
|
||||||
$scoped = $this->getField($container, 'scopedServices');
|
|
||||||
$this->assertFalse(isset($scoped['bar']));
|
|
||||||
$this->assertFalse($container->isScopeActive('foo'));
|
|
||||||
$this->assertFalse($container->has('a'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testEnterScopeRecursivelyWithInactiveChildScopes()
|
|
||||||
{
|
|
||||||
$container = new Container();
|
|
||||||
$container->addScope(new Scope('foo'));
|
|
||||||
$container->addScope(new Scope('bar', 'foo'));
|
|
||||||
|
|
||||||
$this->assertFalse($container->isScopeActive('foo'));
|
|
||||||
|
|
||||||
$container->enterScope('foo');
|
|
||||||
|
|
||||||
$this->assertTrue($container->isScopeActive('foo'));
|
|
||||||
$this->assertFalse($container->isScopeActive('bar'));
|
|
||||||
$this->assertFalse($container->has('a'));
|
|
||||||
|
|
||||||
$a = new \stdClass();
|
|
||||||
$container->set('a', $a, 'foo');
|
|
||||||
|
|
||||||
$scoped = $this->getField($container, 'scopedServices');
|
|
||||||
$this->assertTrue(isset($scoped['foo']['a']));
|
|
||||||
$this->assertSame($a, $scoped['foo']['a']);
|
|
||||||
$this->assertTrue($container->has('a'));
|
|
||||||
|
|
||||||
$container->enterScope('foo');
|
|
||||||
|
|
||||||
$scoped = $this->getField($container, 'scopedServices');
|
|
||||||
$this->assertFalse(isset($scoped['a']));
|
|
||||||
$this->assertTrue($container->isScopeActive('foo'));
|
|
||||||
$this->assertFalse($container->isScopeActive('bar'));
|
|
||||||
$this->assertFalse($container->has('a'));
|
|
||||||
|
|
||||||
$container->enterScope('bar');
|
|
||||||
|
|
||||||
$this->assertTrue($container->isScopeActive('bar'));
|
|
||||||
|
|
||||||
$container->leaveScope('foo');
|
|
||||||
|
|
||||||
$this->assertTrue($container->isScopeActive('foo'));
|
|
||||||
$this->assertFalse($container->isScopeActive('bar'));
|
|
||||||
$this->assertTrue($container->has('a'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testEnterChildScopeRecursively()
|
|
||||||
{
|
|
||||||
$container = new Container();
|
|
||||||
$container->addScope(new Scope('foo'));
|
|
||||||
$container->addScope(new Scope('bar', 'foo'));
|
|
||||||
|
|
||||||
$container->enterScope('foo');
|
|
||||||
$container->enterScope('bar');
|
|
||||||
|
|
||||||
$this->assertTrue($container->isScopeActive('bar'));
|
|
||||||
$this->assertFalse($container->has('a'));
|
|
||||||
|
|
||||||
$a = new \stdClass();
|
|
||||||
$container->set('a', $a, 'bar');
|
|
||||||
|
|
||||||
$scoped = $this->getField($container, 'scopedServices');
|
|
||||||
$this->assertTrue(isset($scoped['bar']['a']));
|
|
||||||
$this->assertSame($a, $scoped['bar']['a']);
|
|
||||||
$this->assertTrue($container->has('a'));
|
|
||||||
|
|
||||||
$container->enterScope('bar');
|
|
||||||
|
|
||||||
$scoped = $this->getField($container, 'scopedServices');
|
|
||||||
$this->assertFalse(isset($scoped['a']));
|
|
||||||
$this->assertTrue($container->isScopeActive('foo'));
|
|
||||||
$this->assertTrue($container->isScopeActive('bar'));
|
|
||||||
$this->assertFalse($container->has('a'));
|
|
||||||
|
|
||||||
$container->leaveScope('bar');
|
|
||||||
|
|
||||||
$this->assertTrue($container->isScopeActive('foo'));
|
|
||||||
$this->assertTrue($container->isScopeActive('bar'));
|
|
||||||
$this->assertTrue($container->has('a'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \InvalidArgumentException
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testEnterScopeNotAdded()
|
|
||||||
{
|
|
||||||
$container = new Container();
|
|
||||||
$container->enterScope('foo');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \RuntimeException
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testEnterScopeDoesNotAllowInactiveParentScope()
|
|
||||||
{
|
|
||||||
$container = new Container();
|
|
||||||
$container->addScope(new Scope('foo'));
|
|
||||||
$container->addScope(new Scope('bar', 'foo'));
|
|
||||||
$container->enterScope('bar');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testLeaveScopeNotActive()
|
|
||||||
{
|
|
||||||
$container = new Container();
|
|
||||||
$container->addScope(new Scope('foo'));
|
|
||||||
|
|
||||||
try {
|
|
||||||
$container->leaveScope('foo');
|
|
||||||
$this->fail('->leaveScope() throws a \LogicException if the scope is not active yet');
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$this->assertInstanceOf('\LogicException', $e, '->leaveScope() throws a \LogicException if the scope is not active yet');
|
|
||||||
$this->assertEquals('The scope "foo" is not active.', $e->getMessage(), '->leaveScope() throws a \LogicException if the scope is not active yet');
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$container->leaveScope('bar');
|
|
||||||
$this->fail('->leaveScope() throws a \LogicException if the scope does not exist');
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
$this->assertInstanceOf('\LogicException', $e, '->leaveScope() throws a \LogicException if the scope does not exist');
|
|
||||||
$this->assertEquals('The scope "bar" is not active.', $e->getMessage(), '->leaveScope() throws a \LogicException if the scope does not exist');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \InvalidArgumentException
|
|
||||||
* @dataProvider getLegacyBuiltInScopes
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testAddScopeDoesNotAllowBuiltInScopes($scope)
|
|
||||||
{
|
|
||||||
$container = new Container();
|
|
||||||
$container->addScope(new Scope($scope));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \InvalidArgumentException
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testAddScopeDoesNotAllowExistingScope()
|
|
||||||
{
|
|
||||||
$container = new Container();
|
|
||||||
$container->addScope(new Scope('foo'));
|
|
||||||
$container->addScope(new Scope('foo'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \InvalidArgumentException
|
|
||||||
* @dataProvider getLegacyInvalidParentScopes
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testAddScopeDoesNotAllowInvalidParentScope($scope)
|
|
||||||
{
|
|
||||||
$c = new Container();
|
|
||||||
$c->addScope(new Scope('foo', $scope));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testAddScope()
|
|
||||||
{
|
|
||||||
$c = new Container();
|
|
||||||
$c->addScope(new Scope('foo'));
|
|
||||||
$c->addScope(new Scope('bar', 'foo'));
|
|
||||||
|
|
||||||
$this->assertSame(array('foo' => 'container', 'bar' => 'foo'), $this->getField($c, 'scopes'));
|
|
||||||
$this->assertSame(array('foo' => array('bar'), 'bar' => array()), $this->getField($c, 'scopeChildren'));
|
|
||||||
|
|
||||||
$c->addScope(new Scope('baz', 'bar'));
|
|
||||||
|
|
||||||
$this->assertSame(array('foo' => 'container', 'bar' => 'foo', 'baz' => 'bar'), $this->getField($c, 'scopes'));
|
|
||||||
$this->assertSame(array('foo' => array('bar', 'baz'), 'bar' => array('baz'), 'baz' => array()), $this->getField($c, 'scopeChildren'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testHasScope()
|
|
||||||
{
|
|
||||||
$c = new Container();
|
|
||||||
|
|
||||||
$this->assertFalse($c->hasScope('foo'));
|
|
||||||
$c->addScope(new Scope('foo'));
|
|
||||||
$this->assertTrue($c->hasScope('foo'));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @expectedException Exception
|
* @expectedException Exception
|
||||||
* @expectedExceptionMessage Something went terribly wrong!
|
* @expectedExceptionMessage Something went terribly wrong!
|
||||||
@ -643,41 +309,6 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertFalse($c->initialized('throws_exception_on_service_configuration'));
|
$this->assertFalse($c->initialized('throws_exception_on_service_configuration'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testIsScopeActive()
|
|
||||||
{
|
|
||||||
$c = new Container();
|
|
||||||
|
|
||||||
$this->assertFalse($c->isScopeActive('foo'));
|
|
||||||
$c->addScope(new Scope('foo'));
|
|
||||||
|
|
||||||
$this->assertFalse($c->isScopeActive('foo'));
|
|
||||||
$c->enterScope('foo');
|
|
||||||
|
|
||||||
$this->assertTrue($c->isScopeActive('foo'));
|
|
||||||
$c->leaveScope('foo');
|
|
||||||
|
|
||||||
$this->assertFalse($c->isScopeActive('foo'));
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getLegacyInvalidParentScopes()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
array(ContainerInterface::SCOPE_PROTOTYPE),
|
|
||||||
array('bar'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getLegacyBuiltInScopes()
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
array(ContainerInterface::SCOPE_CONTAINER),
|
|
||||||
array(ContainerInterface::SCOPE_PROTOTYPE),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getField($obj, $field)
|
protected function getField($obj, $field)
|
||||||
{
|
{
|
||||||
$reflection = new \ReflectionProperty($obj, $field);
|
$reflection = new \ReflectionProperty($obj, $field);
|
||||||
@ -717,29 +348,6 @@ class ProjectServiceContainer extends Container
|
|||||||
$this->aliases = array('alias' => 'bar');
|
$this->aliases = array('alias' => 'bar');
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getScopedService()
|
|
||||||
{
|
|
||||||
if (!$this->isScopeActive('foo')) {
|
|
||||||
throw new \RuntimeException('Invalid call');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->services['scoped'] = $this->scopedServices['foo']['scoped'] = new \stdClass();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getScopedFooService()
|
|
||||||
{
|
|
||||||
if (!$this->isScopeActive('foo')) {
|
|
||||||
throw new \RuntimeException('invalid call');
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->services['scoped_foo'] = $this->scopedServices['foo']['scoped_foo'] = new \stdClass();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getInactiveService()
|
|
||||||
{
|
|
||||||
throw new InactiveScopeException('request', 'request');
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getBarService()
|
protected function getBarService()
|
||||||
{
|
{
|
||||||
return $this->__bar;
|
return $this->__bar;
|
||||||
|
@ -147,31 +147,6 @@ class DefinitionTest extends \PHPUnit_Framework_TestCase
|
|||||||
$this->assertFalse($def->isShared(), '->isShared() returns false if the instance must not be shared');
|
$this->assertFalse($def->isShared(), '->isShared() returns false if the instance must not be shared');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testPrototypeScopedDefinitionAreNotShared()
|
|
||||||
{
|
|
||||||
$def = new Definition('stdClass');
|
|
||||||
$def->setScope(ContainerInterface::SCOPE_PROTOTYPE);
|
|
||||||
|
|
||||||
$this->assertFalse($def->isShared());
|
|
||||||
$this->assertEquals(ContainerInterface::SCOPE_PROTOTYPE, $def->getScope());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers Symfony\Component\DependencyInjection\Definition::setScope
|
|
||||||
* @covers Symfony\Component\DependencyInjection\Definition::getScope
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testSetGetScope()
|
|
||||||
{
|
|
||||||
$def = new Definition('stdClass');
|
|
||||||
$this->assertEquals('container', $def->getScope());
|
|
||||||
$this->assertSame($def, $def->setScope('foo'));
|
|
||||||
$this->assertEquals('foo', $def->getScope());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers Symfony\Component\DependencyInjection\Definition::setPublic
|
* @covers Symfony\Component\DependencyInjection\Definition::setPublic
|
||||||
* @covers Symfony\Component\DependencyInjection\Definition::isPublic
|
* @covers Symfony\Component\DependencyInjection\Definition::isPublic
|
||||||
|
@ -70,14 +70,4 @@ class GraphvizDumperTest extends \PHPUnit_Framework_TestCase
|
|||||||
|
|
||||||
$this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services17.dot')), $dumper->dump(), '->dump() dumps services');
|
$this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services17.dot')), $dumper->dump(), '->dump() dumps services');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testDumpWithScopes()
|
|
||||||
{
|
|
||||||
$container = include self::$fixturesPath.'/containers/legacy-container18.php';
|
|
||||||
$dumper = new GraphvizDumper($container);
|
|
||||||
$this->assertEquals(str_replace('%path%', __DIR__, file_get_contents(self::$fixturesPath.'/graphviz/services18.dot')), $dumper->dump(), '->dump() dumps services');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ namespace Container14;
|
|||||||
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* This file is included in Tests\Dumper\GraphvizDumperTest::testDumpWithFrozenCustomClassContainer
|
* This file is included in Tests\Dumper\GraphvizDumperTest::testDumpWithFrozenCustomClassContainer
|
||||||
* and Tests\Dumper\XmlDumperTest::testCompiledContainerCanBeDumped.
|
* and Tests\Dumper\XmlDumperTest::testCompiledContainerCanBeDumped.
|
||||||
*/
|
*/
|
||||||
|
@ -1,14 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
|
||||||
use Symfony\Component\DependencyInjection\Scope;
|
|
||||||
|
|
||||||
$container = new ContainerBuilder();
|
|
||||||
$container->addScope(new Scope('request'));
|
|
||||||
$container->
|
|
||||||
register('foo', 'FooClass')->
|
|
||||||
setScope('request')
|
|
||||||
;
|
|
||||||
$container->compile();
|
|
||||||
|
|
||||||
return $container;
|
|
@ -3,7 +3,6 @@ namespace Symfony\Component\DependencyInjection\Dump;
|
|||||||
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\DependencyInjection\Container;
|
use Symfony\Component\DependencyInjection\Container;
|
||||||
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
|
|
||||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||||
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
||||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\DependencyInjection\Container;
|
use Symfony\Component\DependencyInjection\Container;
|
||||||
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
|
|
||||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||||
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
||||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\DependencyInjection\Container;
|
use Symfony\Component\DependencyInjection\Container;
|
||||||
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
|
|
||||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||||
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
||||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||||
@ -26,11 +25,7 @@ class ProjectServiceContainer extends Container
|
|||||||
{
|
{
|
||||||
$this->parameters = $this->getDefaultParameters();
|
$this->parameters = $this->getDefaultParameters();
|
||||||
|
|
||||||
$this->services =
|
$this->services = array();
|
||||||
$this->scopedServices =
|
|
||||||
$this->scopeStacks = array();
|
|
||||||
$this->scopes = array();
|
|
||||||
$this->scopeChildren = array();
|
|
||||||
$this->methodMap = array(
|
$this->methodMap = array(
|
||||||
'test' => 'getTestService',
|
'test' => 'getTestService',
|
||||||
);
|
);
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\DependencyInjection\Container;
|
use Symfony\Component\DependencyInjection\Container;
|
||||||
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
|
|
||||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||||
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
||||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||||
@ -30,11 +29,7 @@ class ProjectServiceContainer extends Container
|
|||||||
}
|
}
|
||||||
$this->parameters = $this->getDefaultParameters();
|
$this->parameters = $this->getDefaultParameters();
|
||||||
|
|
||||||
$this->services =
|
$this->services = array();
|
||||||
$this->scopedServices =
|
|
||||||
$this->scopeStacks = array();
|
|
||||||
$this->scopes = array();
|
|
||||||
$this->scopeChildren = array();
|
|
||||||
$this->methodMap = array(
|
$this->methodMap = array(
|
||||||
'test' => 'getTestService',
|
'test' => 'getTestService',
|
||||||
);
|
);
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\DependencyInjection\Container;
|
use Symfony\Component\DependencyInjection\Container;
|
||||||
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
|
|
||||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||||
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
||||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\DependencyInjection\Container;
|
use Symfony\Component\DependencyInjection\Container;
|
||||||
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
|
|
||||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||||
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
||||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\DependencyInjection\Container;
|
use Symfony\Component\DependencyInjection\Container;
|
||||||
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
|
|
||||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||||
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
||||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
use Symfony\Component\DependencyInjection\ContainerInterface;
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
use Symfony\Component\DependencyInjection\Container;
|
use Symfony\Component\DependencyInjection\Container;
|
||||||
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
|
|
||||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||||
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
use Symfony\Component\DependencyInjection\Exception\LogicException;
|
||||||
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
|
||||||
@ -26,11 +25,7 @@ class ProjectServiceContainer extends Container
|
|||||||
{
|
{
|
||||||
$this->parameters = $this->getDefaultParameters();
|
$this->parameters = $this->getDefaultParameters();
|
||||||
|
|
||||||
$this->services =
|
$this->services = array();
|
||||||
$this->scopedServices =
|
|
||||||
$this->scopeStacks = array();
|
|
||||||
$this->scopes = array();
|
|
||||||
$this->scopeChildren = array();
|
|
||||||
$this->methodMap = array(
|
$this->methodMap = array(
|
||||||
'bar' => 'getBarService',
|
'bar' => 'getBarService',
|
||||||
'baz' => 'getBazService',
|
'baz' => 'getBazService',
|
||||||
|
@ -12,7 +12,6 @@
|
|||||||
namespace Symfony\Component\EventDispatcher\Tests;
|
namespace Symfony\Component\EventDispatcher\Tests;
|
||||||
|
|
||||||
use Symfony\Component\DependencyInjection\Container;
|
use Symfony\Component\DependencyInjection\Container;
|
||||||
use Symfony\Component\DependencyInjection\Scope;
|
|
||||||
use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher;
|
use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher;
|
||||||
use Symfony\Component\EventDispatcher\Event;
|
use Symfony\Component\EventDispatcher\Event;
|
||||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||||
@ -90,72 +89,6 @@ class ContainerAwareEventDispatcherTest extends AbstractEventDispatcherTest
|
|||||||
$dispatcher->dispatch('onEvent', $event);
|
$dispatcher->dispatch('onEvent', $event);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @expectedException \InvalidArgumentException
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testTriggerAListenerServiceOutOfScope()
|
|
||||||
{
|
|
||||||
$service = $this->getMock('Symfony\Component\EventDispatcher\Tests\Service');
|
|
||||||
|
|
||||||
$scope = new Scope('scope');
|
|
||||||
$container = new Container();
|
|
||||||
$container->addScope($scope);
|
|
||||||
$container->enterScope('scope');
|
|
||||||
|
|
||||||
$container->set('service.listener', $service, 'scope');
|
|
||||||
|
|
||||||
$dispatcher = new ContainerAwareEventDispatcher($container);
|
|
||||||
$dispatcher->addListenerService('onEvent', array('service.listener', 'onEvent'));
|
|
||||||
|
|
||||||
$container->leaveScope('scope');
|
|
||||||
$dispatcher->dispatch('onEvent');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @group legacy
|
|
||||||
*/
|
|
||||||
public function testReEnteringAScope()
|
|
||||||
{
|
|
||||||
$event = new Event();
|
|
||||||
|
|
||||||
$service1 = $this->getMock('Symfony\Component\EventDispatcher\Tests\Service');
|
|
||||||
|
|
||||||
$service1
|
|
||||||
->expects($this->exactly(2))
|
|
||||||
->method('onEvent')
|
|
||||||
->with($event)
|
|
||||||
;
|
|
||||||
|
|
||||||
$scope = new Scope('scope');
|
|
||||||
$container = new Container();
|
|
||||||
$container->addScope($scope);
|
|
||||||
$container->enterScope('scope');
|
|
||||||
|
|
||||||
$container->set('service.listener', $service1, 'scope');
|
|
||||||
|
|
||||||
$dispatcher = new ContainerAwareEventDispatcher($container);
|
|
||||||
$dispatcher->addListenerService('onEvent', array('service.listener', 'onEvent'));
|
|
||||||
$dispatcher->dispatch('onEvent', $event);
|
|
||||||
|
|
||||||
$service2 = $this->getMock('Symfony\Component\EventDispatcher\Tests\Service');
|
|
||||||
|
|
||||||
$service2
|
|
||||||
->expects($this->once())
|
|
||||||
->method('onEvent')
|
|
||||||
->with($event)
|
|
||||||
;
|
|
||||||
|
|
||||||
$container->enterScope('scope');
|
|
||||||
$container->set('service.listener', $service2, 'scope');
|
|
||||||
|
|
||||||
$dispatcher->dispatch('onEvent', $event);
|
|
||||||
|
|
||||||
$container->leaveScope('scope');
|
|
||||||
|
|
||||||
$dispatcher->dispatch('onEvent');
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testHasListenersOnLazyLoad()
|
public function testHasListenersOnLazyLoad()
|
||||||
{
|
{
|
||||||
$event = new Event();
|
$event = new Event();
|
||||||
|
Reference in New Issue
Block a user