[DI] Fix missing use + minor tweaks
This commit is contained in:
parent
f56f28b0f3
commit
0a7e5b0d09
@ -22,6 +22,9 @@ abstract class AbstractConfigurator
|
||||
{
|
||||
const FACTORY = 'unknown';
|
||||
|
||||
/** @internal */
|
||||
protected $definition;
|
||||
|
||||
public function __call($method, $args)
|
||||
{
|
||||
if (method_exists($this, 'set'.$method)) {
|
||||
@ -37,7 +40,7 @@ abstract class AbstractConfigurator
|
||||
* @param mixed $value
|
||||
* @param bool $allowServices whether Definition and Reference are allowed; by default, only scalars and arrays are
|
||||
*
|
||||
* @return mixed the value, optionaly cast to a Definition/Reference
|
||||
* @return mixed the value, optionally cast to a Definition/Reference
|
||||
*/
|
||||
public static function processValue($value, $allowServices = false)
|
||||
{
|
||||
@ -50,32 +53,14 @@ abstract class AbstractConfigurator
|
||||
}
|
||||
|
||||
if ($value instanceof ReferenceConfigurator) {
|
||||
static $refCast;
|
||||
|
||||
if (!$refCast) {
|
||||
$refCast = \Closure::bind(function ($value) {
|
||||
return new Reference($value->id, $value->invalidBehavior);
|
||||
}, null, $value);
|
||||
}
|
||||
|
||||
// cast ReferenceConfigurator to Reference
|
||||
return $refCast($value);
|
||||
return new Reference($value->id, $value->invalidBehavior);
|
||||
}
|
||||
|
||||
if ($value instanceof InlineServiceConfigurator) {
|
||||
static $defCast;
|
||||
$def = $value->definition;
|
||||
$value->definition = null;
|
||||
|
||||
if (!$defCast) {
|
||||
$defCast = \Closure::bind(function ($value) {
|
||||
$def = $value->definition;
|
||||
$value->definition = null;
|
||||
|
||||
return $def;
|
||||
}, null, $value);
|
||||
}
|
||||
|
||||
// cast InlineServiceConfigurator to Definition
|
||||
return $defCast($value);
|
||||
return $def;
|
||||
}
|
||||
|
||||
if ($value instanceof self) {
|
||||
|
@ -17,9 +17,8 @@ use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
|
||||
abstract class AbstractServiceConfigurator extends AbstractConfigurator
|
||||
{
|
||||
protected $parent;
|
||||
protected $definition;
|
||||
protected $id;
|
||||
protected $defaultTags = array();
|
||||
private $defaultTags = array();
|
||||
|
||||
public function __construct(ServicesConfigurator $parent, Definition $definition, $id = null, array $defaultTags = array())
|
||||
{
|
||||
@ -59,7 +58,7 @@ abstract class AbstractServiceConfigurator extends AbstractConfigurator
|
||||
* Creates an alias.
|
||||
*
|
||||
* @param string $id
|
||||
* @param string $ref
|
||||
* @param string $referencedId
|
||||
*
|
||||
* @return AliasConfigurator
|
||||
*/
|
||||
|
@ -16,10 +16,13 @@ use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||
/**
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*/
|
||||
class ReferenceConfigurator
|
||||
class ReferenceConfigurator extends AbstractConfigurator
|
||||
{
|
||||
private $id;
|
||||
private $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
|
||||
/** @internal */
|
||||
protected $id;
|
||||
|
||||
/** @internal */
|
||||
protected $invalidBehavior = ContainerInterface::EXCEPTION_ON_INVALID_REFERENCE;
|
||||
|
||||
public function __construct($id)
|
||||
{
|
||||
|
@ -11,8 +11,6 @@
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Loader\Configurator\Traits;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
|
||||
/**
|
||||
* @method $this abstract(bool $abstract = true)
|
||||
*/
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Loader\Configurator\Traits;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ChildDefinition;
|
||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||
|
||||
trait AutoconfigureTrait
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Loader\Configurator\Traits;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||
|
||||
trait DeprecateTrait
|
||||
|
@ -11,7 +11,6 @@
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Loader\Configurator\Traits;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
|
||||
|
||||
trait TagTrait
|
||||
|
@ -0,0 +1,9 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\DependencyInjection\Loader\Configurator;
|
||||
|
||||
return function (ContainerConfigurator $c) {
|
||||
$c->services()
|
||||
->set('parent_service', \stdClass::class)
|
||||
->set('child_service')->parent('parent_service')->autoconfigure(true);
|
||||
};
|
@ -76,4 +76,17 @@ class PhpFileLoaderTest extends TestCase
|
||||
yield array('php7');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
|
||||
* @expectedExceptionMessage The service "child_service" cannot have a "parent" and also have "autoconfigure". Try disabling autoconfiguration for the service.
|
||||
*/
|
||||
public function testAutoConfigureAndChildDefinitionNotAllowed()
|
||||
{
|
||||
$fixtures = realpath(__DIR__.'/../Fixtures');
|
||||
$container = new ContainerBuilder();
|
||||
$loader = new PhpFileLoader($container, new FileLocator());
|
||||
$loader->load($fixtures.'/config/services_autoconfigure_with_parent.php');
|
||||
$container->compile();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user