[DI] Remove deprecated scope concept

This commit is contained in:
Nicolas Grekas 2015-09-04 21:54:37 +02:00
parent eca45b7624
commit 4a3e2f49cb
70 changed files with 35 additions and 1662 deletions

View File

@ -15,7 +15,6 @@ use ProxyManager\Generator\ClassGenerator;
use ProxyManager\GeneratorStrategy\BaseGeneratorStrategy;
use ProxyManager\ProxyGenerator\LazyLoadingValueHolderGenerator;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\LazyProxy\PhpDumper\DumperInterface;
@ -68,10 +67,8 @@ class ProxyDumper implements DumperInterface
{
$instantiation = 'return';
if ($definition->isShared() && ContainerInterface::SCOPE_CONTAINER === $definition->getScope(false)) {
if ($definition->isShared()) {
$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';

View File

@ -2,7 +2,6 @@
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
@ -23,11 +22,7 @@ class LazyServiceProjectServiceContainer extends Container
*/
public function __construct()
{
$this->services =
$this->scopedServices =
$this->scopeStacks = array();
$this->scopes = array();
$this->scopeChildren = array();
$this->services = array();
}
/**
@ -43,7 +38,6 @@ class LazyServiceProjectServiceContainer extends Container
public function getFooService($lazyLoad = true)
{
if ($lazyLoad) {
return $this->services['foo'] = new stdClass_c1d194250ee2e2b7d2eab8b8212368a8(
function (&$wrappedInstance, \ProxyManager\Proxy\LazyLoadingInterface $proxy) {
$wrappedInstance = $this->getFooService(false);

View File

@ -205,7 +205,6 @@ class JsonDescriptor extends Descriptor
{
$data = array(
'class' => (string) $definition->getClass(),
'scope' => $definition->getScope(false),
'public' => $definition->isPublic(),
'synthetic' => $definition->isSynthetic(),
'lazy' => $definition->isLazy(),

View File

@ -176,7 +176,6 @@ class MarkdownDescriptor extends Descriptor
protected function describeContainerDefinition(Definition $definition, array $options = array())
{
$output = '- Class: `'.$definition->getClass().'`'
."\n".'- Scope: `'.$definition->getScope(false).'`'
."\n".'- Public: '.($definition->isPublic() ? 'yes' : 'no')
."\n".'- Synthetic: '.($definition->isSynthetic() ? 'yes' : 'no')
."\n".'- Lazy: '.($definition->isLazy() ? 'yes' : 'no')

View File

@ -256,7 +256,6 @@ class TextDescriptor extends Descriptor
$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>Synthetic</comment> %s', $definition->isSynthetic() ? 'yes' : 'no');
$description[] = sprintf('<comment>Lazy</comment> %s', $definition->isLazy() ? 'yes' : 'no');

View File

@ -346,7 +346,6 @@ class XmlDescriptor extends Descriptor
}
}
$serviceXML->setAttribute('scope', $definition->getScope(false));
$serviceXML->setAttribute('public', $definition->isPublic() ? 'true' : 'false');
$serviceXML->setAttribute('synthetic', $definition->isSynthetic() ? 'true' : 'false');
$serviceXML->setAttribute('lazy', $definition->isLazy() ? 'true' : 'false');

View File

@ -31,7 +31,6 @@ use Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SerializerPass;
use Symfony\Component\Debug\ErrorHandler;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\Scope;
use Symfony\Component\EventDispatcher\DependencyInjection\RegisterListenersPass;
use Symfony\Component\HttpKernel\DependencyInjection\FragmentRendererPass;
use Symfony\Component\HttpFoundation\Request;
@ -65,10 +64,6 @@ class FrameworkBundle extends Bundle
{
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 ProfilerPass());
// must be registered before removing private services as some might be listeners/subscribers

View File

@ -2,7 +2,6 @@
"definitions": {
"definition_1": {
"class": "Full\\Qualified\\Class1",
"scope": "container",
"public": true,
"synthetic": false,
"lazy": true,

View File

@ -8,7 +8,6 @@ definition_1
~~~~~~~~~~~~
- Class: `Full\Qualified\Class1`
- Scope: `container`
- Public: yes
- Synthetic: no
- Lazy: yes

View File

@ -2,7 +2,7 @@
<container>
<alias id="alias_1" service="service_1" public="true"/>
<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"/>
</definition>
<service id="service_container" class="Symfony\Component\DependencyInjection\ContainerBuilder"/>

View File

@ -2,7 +2,6 @@
"definitions": {
"definition_1": {
"class": "Full\\Qualified\\Class1",
"scope": "container",
"public": true,
"synthetic": false,
"lazy": true,
@ -17,7 +16,6 @@
},
"definition_2": {
"class": "Full\\Qualified\\Class2",
"scope": "container",
"public": false,
"synthetic": true,
"lazy": false,

View File

@ -8,7 +8,6 @@ definition_1
~~~~~~~~~~~~
- Class: `Full\Qualified\Class1`
- Scope: `container`
- Public: yes
- Synthetic: no
- Lazy: yes
@ -21,7 +20,6 @@ definition_2
~~~~~~~~~~~~
- Class: `Full\Qualified\Class2`
- Scope: `container`
- Public: no
- Synthetic: yes
- Lazy: no

View File

@ -2,10 +2,10 @@
<container>
<alias id="alias_1" service="service_1" public="true"/>
<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"/>
</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"/>
<tags>
<tag name="tag1">

View File

@ -2,7 +2,6 @@
"definitions": {
"definition_2": {
"class": "Full\\Qualified\\Class2",
"scope": "container",
"public": false,
"synthetic": true,
"lazy": false,

View File

@ -8,7 +8,6 @@ definition_2
~~~~~~~~~~~~
- Class: `Full\Qualified\Class2`
- Scope: `container`
- Public: no
- Synthetic: yes
- Lazy: no

View File

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<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"/>
<tags>
<tag name="tag1">

View File

@ -2,7 +2,6 @@
"tag1": [
{
"class": "Full\\Qualified\\Class2",
"scope": "container",
"public": false,
"synthetic": true,
"lazy": false,
@ -16,7 +15,6 @@
"tag2": [
{
"class": "Full\\Qualified\\Class2",
"scope": "container",
"public": false,
"synthetic": true,
"lazy": false,

View File

@ -8,7 +8,6 @@ definition_2
~~~~~~~~~~~~
- Class: `Full\Qualified\Class2`
- Scope: `container`
- Public: no
- Synthetic: yes
- Lazy: no
@ -26,7 +25,6 @@ definition_2
~~~~~~~~~~~~
- Class: `Full\Qualified\Class2`
- Scope: `container`
- Public: no
- Synthetic: yes
- Lazy: no

View File

@ -1,12 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<container>
<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"/>
</definition>
</tag>
<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"/>
</definition>
</tag>

View File

@ -1,6 +1,5 @@
{
"class": "Full\\Qualified\\Class1",
"scope": "container",
"public": true,
"synthetic": false,
"lazy": true,

View File

@ -1,5 +1,4 @@
- Class: `Full\Qualified\Class1`
- Scope: `container`
- Public: yes
- Synthetic: no
- Lazy: yes

View File

@ -1,7 +1,6 @@
<comment>Service Id</comment> -
<comment>Class</comment> Full\Qualified\Class1
<comment>Tags</comment> -
<comment>Scope</comment> container
<comment>Public</comment> yes
<comment>Synthetic</comment> no
<comment>Lazy</comment> yes

View File

@ -1,4 +1,4 @@
<?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"/>
</definition>

View File

@ -1,6 +1,5 @@
{
"class": "Full\\Qualified\\Class2",
"scope": "container",
"public": false,
"synthetic": true,
"lazy": false,

View File

@ -1,5 +1,4 @@
- Class: `Full\Qualified\Class2`
- Scope: `container`
- Public: no
- Synthetic: yes
- Lazy: no

View File

@ -4,7 +4,6 @@
- tag1 (<info>attr1</info>: val1, <info>attr2</info>: val2)
- tag1 (<info>attr3</info>: val3)
- tag2 ()
<comment>Scope</comment> container
<comment>Public</comment> no
<comment>Synthetic</comment> yes
<comment>Lazy</comment> no

View File

@ -1,5 +1,5 @@
<?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"/>
<tags>
<tag name="tag1">

View File

@ -1,6 +1,11 @@
CHANGELOG
=========
3.0.0
-----
* removed all deprecated codes from 2.x versions
2.8.0
-----

View File

@ -11,7 +11,6 @@
namespace Symfony\Component\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
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
* - 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>
*/
@ -46,16 +43,6 @@ class CheckDefinitionValidityPass implements CompilerPassInterface
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
if (!$definition->isAbstract() && !$definition->isSynthetic() && !$definition->getClass()) {
if ($definition->getFactory()) {

View File

@ -12,20 +12,15 @@
namespace Symfony\Component\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\Exception\ScopeCrossingInjectionException;
use Symfony\Component\DependencyInjection\Exception\ScopeWideningInjectionException;
/**
* Checks the validity of references.
*
* The following checks are performed by this pass:
* - 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>
*/
@ -33,9 +28,6 @@ class CheckReferenceValidityPass implements CompilerPassInterface
{
private $container;
private $currentId;
private $currentScope;
private $currentScopeAncestors;
private $currentScopeChildren;
/**
* Processes the ContainerBuilder to validate References.
@ -46,18 +38,8 @@ class CheckReferenceValidityPass implements CompilerPassInterface
{
$this->container = $container;
$children = $this->container->getScopeChildren(false);
$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) {
if ($definition->isSynthetic() || $definition->isAbstract()) {
continue;
@ -65,15 +47,6 @@ class CheckReferenceValidityPass implements CompilerPassInterface
$this->currentId = $id;
$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->getMethodCalls());
@ -104,50 +77,10 @@ class CheckReferenceValidityPass implements CompilerPassInterface
$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.
*

View File

@ -76,7 +76,7 @@ class InlineServiceDefinitionsPass implements RepeatablePassInterface
if ($this->isInlineableDefinition($container, $id, $definition = $container->getDefinition($id))) {
$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;
} else {
$arguments[$k] = clone $definition;
@ -109,7 +109,7 @@ class InlineServiceDefinitionsPass implements RepeatablePassInterface
*/
private function isInlineableDefinition(ContainerBuilder $container, $id, Definition $definition)
{
if (!$definition->isShared() || ContainerInterface::SCOPE_PROTOTYPE === $definition->getScope(false)) {
if (!$definition->isShared()) {
return true;
}
@ -138,6 +138,6 @@ class InlineServiceDefinitionsPass implements RepeatablePassInterface
return false;
}
return $container->getDefinition(reset($ids))->getScope(false) === $definition->getScope(false);
return true;
}
}

View File

@ -113,7 +113,7 @@ class ResolveDefinitionTemplatesPass implements CompilerPassInterface
$def = new Definition();
// merge in parent definition
// purposely ignored attributes: scope, abstract, tags
// purposely ignored attributes: abstract, tags
$def->setClass($parentDef->getClass());
$def->setArguments($parentDef->getArguments());
$def->setMethodCalls($parentDef->getMethodCalls());
@ -180,7 +180,6 @@ class ResolveDefinitionTemplatesPass implements CompilerPassInterface
// these attributes are always taken from the child
$def->setAbstract($definition->isAbstract());
$def->setScope($definition->getScope(false), false);
$def->setTags($definition->getTags());
return $def;

View File

@ -68,7 +68,7 @@ class ResolveReferencesToAliasesPass implements CompilerPassInterface
$defId = $this->getDefinitionId($id = (string) $argument);
if ($defId !== $id) {
$arguments[$k] = new Reference($defId, $argument->getInvalidBehavior(), $argument->isStrict(false));
$arguments[$k] = new Reference($defId, $argument->getInvalidBehavior());
}
}
}

View File

@ -11,10 +11,7 @@
namespace Symfony\Component\DependencyInjection;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
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\ServiceCircularReferenceException;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
@ -71,10 +68,6 @@ class Container implements ResettableContainerInterface
protected $services = array();
protected $methodMap = array();
protected $aliases = array();
protected $scopes = array();
protected $scopeChildren = array();
protected $scopedServices = array();
protected $scopeStacks = array();
protected $loading = 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()
* 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 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
*/
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);
if ('service_container' === $id) {
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;
if (null === $service) {
if (self::SCOPE_CONTAINER !== $scope) {
unset($this->scopedServices[$scope][$id]);
}
unset($this->services[$id]);
}
}
@ -333,10 +300,6 @@ class Container implements ResettableContainerInterface
unset($this->services[$id]);
}
if ($e instanceof InactiveScopeException && self::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
return;
}
throw $e;
}
@ -373,10 +336,6 @@ class Container implements ResettableContainerInterface
*/
public function reset()
{
if (!empty($this->scopedServices)) {
throw new LogicException('Resetting the container is not allowed when a scope is active.');
}
$this->services = array();
}
@ -399,193 +358,6 @@ class Container implements ResettableContainerInterface
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.
*

View File

@ -15,7 +15,6 @@ use Symfony\Component\DependencyInjection\Compiler\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\Exception\BadMethodCallException;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
@ -352,56 +351,17 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
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.
*
* Note: The $scope parameter is deprecated since version 2.8 and will be removed in 3.0.
*
* @param string $id The service identifier
* @param object $service The service instance
* @param string $scope The scope
*
* @throws BadMethodCallException When this ContainerBuilder is frozen
*
* @api
*/
public function set($id, $service, $scope = self::SCOPE_CONTAINER)
public function set($id, $service)
{
$id = strtolower($id);
@ -424,7 +384,7 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
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
*
* @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 \Exception
*
@ -501,10 +460,6 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
} catch (\Exception $e) {
unset($this->loading[$id]);
if ($e instanceof InactiveScopeException && self::EXCEPTION_ON_INVALID_REFERENCE !== $invalidBehavior) {
return;
}
throw $e;
}
@ -914,7 +869,6 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
*
* @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 service is a synthetic service
* @throws InvalidArgumentException When configure callable is not callable
@ -1135,21 +1089,11 @@ class ContainerBuilder extends Container implements TaggedContainerInterface
* @param Definition $definition
* @param mixed $service
* @param string $id
*
* @throws InactiveScopeException
*/
private function shareService(Definition $definition, $service, $id)
{
if ($definition->isShared() && self::SCOPE_PROTOTYPE !== $scope = $definition->getScope(false)) {
if (self::SCOPE_CONTAINER !== $scope && !isset($this->scopedServices[$scope])) {
throw new InactiveScopeException($id, $scope);
}
if ($definition->isShared()) {
$this->services[$lowerId = strtolower($id)] = $service;
if (self::SCOPE_CONTAINER !== $scope) {
$this->scopedServices[$scope][$lowerId] = $service;
}
}
}

View File

@ -28,21 +28,16 @@ interface ContainerInterface
const EXCEPTION_ON_INVALID_REFERENCE = 1;
const NULL_ON_INVALID_REFERENCE = 2;
const IGNORE_ON_INVALID_REFERENCE = 3;
const SCOPE_CONTAINER = 'container';
const SCOPE_PROTOTYPE = 'prototype';
/**
* 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 object $service The service instance
* @param string $scope The scope of the service
*
* @api
*/
public function set($id, $service, $scope = self::SCOPE_CONTAINER);
public function set($id, $service);
/**
* Gets a service.
@ -114,65 +109,4 @@ interface ContainerInterface
* @api
*/
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);
}

View File

@ -27,7 +27,6 @@ class Definition
private $file;
private $factory;
private $shared = true;
private $scope = ContainerInterface::SCOPE_CONTAINER;
private $properties = array();
private $calls = array();
private $configurator;
@ -514,50 +513,6 @@ class Definition
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.
*

View File

@ -18,7 +18,6 @@ use Symfony\Component\DependencyInjection\Parameter;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\DependencyInjection\Scope;
/**
* GraphvizDumper dumps a service container as a graphviz file.
@ -177,7 +176,7 @@ class GraphvizDumper extends Dumper
} 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'));
}
@ -205,9 +204,6 @@ class GraphvizDumper extends Dumper
$container->setDefinitions($this->container->getDefinitions());
$container->setAliases($this->container->getAliases());
$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) {
$container->registerExtension($extension);
}

View File

@ -382,10 +382,8 @@ class PhpDumper extends Dumper
$isProxyCandidate = $this->getProxyDumper()->isProxyCandidate($definition);
$instantiation = '';
if (!$isProxyCandidate && $definition->isShared() && ContainerInterface::SCOPE_CONTAINER === $definition->getScope(false)) {
if (!$isProxyCandidate && $definition->isShared()) {
$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) {
$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);
$doc = '';
if ($definition->isShared() && ContainerInterface::SCOPE_PROTOTYPE !== $scope) {
if ($definition->isShared()) {
$doc .= <<<EOF
*
@ -629,16 +619,6 @@ EOF;
$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()) {
$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 {
@ -737,7 +717,6 @@ EOF;
$namespaceLine
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
@ -778,12 +757,6 @@ 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->addAliases();
@ -817,22 +790,7 @@ EOF;
$code .= "\n \$this->parameters = \$this->getDefaultParameters();\n";
}
$code .= <<<EOF
\$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 .= "\n \$this->services = array();\n";
$code .= $this->addMethodMap();
$code .= $this->addAliases();

View File

@ -124,9 +124,6 @@ class XmlDumper extends Dumper
if (!$definition->isShared()) {
$service->setAttribute('shared', 'false');
}
if (ContainerInterface::SCOPE_CONTAINER !== $scope = $definition->getScope(false)) {
$service->setAttribute('scope', $scope);
}
if (!$definition->isPublic()) {
$service->setAttribute('public', 'false');
}
@ -281,9 +278,6 @@ class XmlDumper extends Dumper
} elseif ($behaviour == ContainerInterface::IGNORE_ON_INVALID_REFERENCE) {
$element->setAttribute('on-invalid', 'ignore');
}
if (!$value->isStrict(false)) {
$element->setAttribute('strict', 'false');
}
} elseif ($value instanceof Definition) {
$element->setAttribute('type', 'service');
$this->addService($value, null, $element);

View File

@ -120,10 +120,6 @@ class YamlDumper extends Dumper
$code .= " shared: false\n";
}
if (ContainerInterface::SCOPE_CONTAINER !== $scope = $definition->getScope(false)) {
$code .= sprintf(" scope: %s\n", $scope);
}
if (null !== $decorated = $definition->getDecoratedService()) {
list($decorated, $renamedId, $priority) = $decorated;
$code .= sprintf(" decorates: %s\n", $decorated);

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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
{
}

View File

@ -167,13 +167,6 @@ class YamlFileLoader extends FileLoader
$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'])) {
$definition->setSynthetic($service['synthetic']);
}

View File

@ -88,7 +88,6 @@
<xsd:attribute name="id" type="xsd:string" />
<xsd:attribute name="class" type="xsd:string" />
<xsd:attribute name="shared" type="boolean" />
<xsd:attribute name="scope" type="xsd:string" />
<xsd:attribute name="public" type="boolean" />
<xsd:attribute name="synthetic" type="boolean" />
<xsd:attribute name="lazy" type="boolean" />

View File

@ -22,24 +22,19 @@ class Reference
{
private $id;
private $invalidBehavior;
private $strict;
/**
* 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 int $invalidBehavior The behavior when the service does not exist
* @param bool $strict Sets how this reference is validated
*
* @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->invalidBehavior = $invalidBehavior;
$this->strict = $strict;
}
/**
@ -61,20 +56,4 @@ class Reference
{
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;
}
}

View File

@ -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;
}
}

View File

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

View File

@ -28,30 +28,6 @@ class CheckDefinitionValidityPassTest extends \PHPUnit_Framework_TestCase
$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
*/

View File

@ -11,7 +11,6 @@
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
use Symfony\Component\DependencyInjection\Scope;
use Symfony\Component\DependencyInjection\Compiler\CheckReferenceValidityPass;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Reference;
@ -19,62 +18,6 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
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
*/

View File

@ -11,7 +11,6 @@
namespace Symfony\Component\DependencyInjection\Tests\Compiler;
use Symfony\Component\DependencyInjection\Scope;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Compiler\AnalyzeServiceReferencesPass;
use Symfony\Component\DependencyInjection\Compiler\RepeatedPass;
@ -61,29 +60,6 @@ class InlineServiceDefinitionsPassTest extends \PHPUnit_Framework_TestCase
$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()
{
$container = new ContainerBuilder();
@ -113,38 +89,6 @@ class InlineServiceDefinitionsPassTest extends \PHPUnit_Framework_TestCase
$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()
{
$container = new ContainerBuilder();
@ -243,23 +187,6 @@ class InlineServiceDefinitionsPassTest extends \PHPUnit_Framework_TestCase
$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()
{
$container = new ContainerBuilder();

View File

@ -79,28 +79,6 @@ class ResolveDefinitionTemplatesPassTest extends \PHPUnit_Framework_TestCase
$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()
{
$container = new ContainerBuilder();

View File

@ -61,23 +61,6 @@ class ResolveInvalidReferencesPassTest extends \PHPUnit_Framework_TestCase
$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)
{
$pass = new ResolveInvalidReferencesPass();

View File

@ -20,11 +20,9 @@ use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Loader\ClosureLoader;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\DependencyInjection\Scope;
use Symfony\Component\Config\Resource\FileResource;
use Symfony\Component\ExpressionLanguage\Expression;
@ -152,29 +150,6 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
$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
*/
@ -777,11 +752,3 @@ class ContainerBuilderTest extends \PHPUnit_Framework_TestCase
class FooClass
{
}
class ProjectContainer extends ContainerBuilder
{
public function getFoobazService()
{
throw new InactiveScopeException('foo', 'request');
}
}

View File

@ -11,11 +11,9 @@
namespace Symfony\Component\DependencyInjection\Tests;
use Symfony\Component\DependencyInjection\Scope;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBag;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
class ContainerTest extends \PHPUnit_Framework_TestCase
{
@ -146,7 +144,7 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
$sc = new ProjectServiceContainer();
$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');
}
/**
* @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
*/
@ -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
*/
@ -318,292 +270,6 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
$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
* @expectedExceptionMessage Something went terribly wrong!
@ -643,41 +309,6 @@ class ContainerTest extends \PHPUnit_Framework_TestCase
$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)
{
$reflection = new \ReflectionProperty($obj, $field);
@ -717,29 +348,6 @@ class ProjectServiceContainer extends Container
$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()
{
return $this->__bar;

View File

@ -147,31 +147,6 @@ class DefinitionTest extends \PHPUnit_Framework_TestCase
$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::isPublic

View File

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

View File

@ -4,7 +4,7 @@ namespace Container14;
use Symfony\Component\DependencyInjection\ContainerBuilder;
/**
/*
* This file is included in Tests\Dumper\GraphvizDumperTest::testDumpWithFrozenCustomClassContainer
* and Tests\Dumper\XmlDumperTest::testCompiledContainerCanBeDumped.
*/

View File

@ -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;

View File

@ -3,7 +3,6 @@ namespace Symfony\Component\DependencyInjection\Dump;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;

View File

@ -2,7 +2,6 @@
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;

View File

@ -2,7 +2,6 @@
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
@ -26,11 +25,7 @@ class ProjectServiceContainer extends Container
{
$this->parameters = $this->getDefaultParameters();
$this->services =
$this->scopedServices =
$this->scopeStacks = array();
$this->scopes = array();
$this->scopeChildren = array();
$this->services = array();
$this->methodMap = array(
'test' => 'getTestService',
);

View File

@ -2,7 +2,6 @@
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
@ -30,11 +29,7 @@ class ProjectServiceContainer extends Container
}
$this->parameters = $this->getDefaultParameters();
$this->services =
$this->scopedServices =
$this->scopeStacks = array();
$this->scopes = array();
$this->scopeChildren = array();
$this->services = array();
$this->methodMap = array(
'test' => 'getTestService',
);

View File

@ -2,7 +2,6 @@
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;

View File

@ -2,7 +2,6 @@
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;

View File

@ -2,7 +2,6 @@
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;

View File

@ -2,7 +2,6 @@
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Exception\InactiveScopeException;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\DependencyInjection\Exception\LogicException;
use Symfony\Component\DependencyInjection\Exception\RuntimeException;
@ -26,11 +25,7 @@ class ProjectServiceContainer extends Container
{
$this->parameters = $this->getDefaultParameters();
$this->services =
$this->scopedServices =
$this->scopeStacks = array();
$this->scopes = array();
$this->scopeChildren = array();
$this->services = array();
$this->methodMap = array(
'bar' => 'getBarService',
'baz' => 'getBazService',

View File

@ -12,7 +12,6 @@
namespace Symfony\Component\EventDispatcher\Tests;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\Scope;
use Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher;
use Symfony\Component\EventDispatcher\Event;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
@ -90,72 +89,6 @@ class ContainerAwareEventDispatcherTest extends AbstractEventDispatcherTest
$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()
{
$event = new Event();