10000 [DI] Rework config hierarchy: defaults > instanceof > service config by nicolas-grekas · Pull Request #22356 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[DI] Rework config hierarchy: defaults > instanceof > service config #22356

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 11, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
125 changes: 8 additions & 117 deletions src/Symfony/Component/DependencyInjection/ChildDefinition.php
10000
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,12 @@ class ChildDefinition extends Definition
{
private $parent;
private $inheritTags = false;
private $changes = array();

/**
* @param string $parent The id of Definition instance to decorate
*/
public function __construct($parent)
{
parent::__construct();

$this->parent = $parent;
}

Expand All @@ -46,13 +43,17 @@ public function getParent()
}

/**
* Returns all changes tracked for the Definition object.
* Sets the Definition being decorated.
*
* @param string $parent
*
* @return array An array of changes for this Definition
* @return $this
*/
public function getChanges()
public function setParent($parent)
{
return $this->changes;
$this->parent = $parent;

return $this;
}

/**
Expand All @@ -79,116 +80,6 @@ public function getInheritTags()
return $this->inheritTags;
}

/**
* {@inheritdoc}
*/
public function setClass($class)
{
$this->changes['class'] = true;

return parent::setClass($class);
}

/**
* {@inheritdoc}
*/
public function setFactory($callable)
{
$this->changes['factory'] = true;

return parent::setFactory($callable);
}

/**
* {@inheritdoc}
*/
public function setConfigurator($callable)
{
$this->changes['configurator'] = true;

return parent::setConfigurator($callable);
}

/**
* {@inheritdoc}
*/
public function setFile($file)
{
$this->changes['file'] = true;

return parent::setFile($file);
}

/**
* {@inheritdoc}
*/
public function setShared($boolean)
{
$this->changes['shared'] = true;

return parent::setShared($boolean);
}

/**
* {@inheritdoc}
*/
public function setPublic($boolean)
{
$this->changes['public'] = true;

return parent::setPublic($boolean);
}

/**
* {@inheritdoc}
*/
public function setLazy($boolean)
{
$this->changes['lazy'] = true;

return parent::setLazy($boolean);
}

/**
* {@inheritdoc}
*/
public function setAbstract($boolean)
{
$this->changes['abstract'] = true;

return parent::setAbstract($boolean);
}

/**
* {@inheritdoc}
*/
public function setDecoratedService($id, $renamedId = null, $priority = 0)
{
$this->changes['decorated_service'] = true;

return parent::setDecoratedService($id, $renamedId, $priority);
}

/**
* {@inheritdoc}
*/
public function setDeprecated($boolean = true, $template = null)
{
$this->changes['deprecated'] = true;

return parent::setDeprecated($boolean, $template);
}

/**
* {@inheritdoc}
*/
public function setAutowired($autowired)
{
$this->changes['autowired'] = true;

return parent::setAutowired($autowired);
}

/**
* Gets an argument to pass to the service constructor/factory method.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ protected function processValue($value, $isRoot = false)
$value->setProperties($this->processValue($value->getProperties()));
$value->setMethodCalls($this->processValue($value->getMethodCalls()));

if ($v = $value->getFactory()) {
$value->setFactory($this->processValue($v));
$changes = $value->getChanges();
if (isset($changes['factory'])) {
$value->setFactory($this->processValue($value->getFactory()));
}
if ($v = $value->getConfigurator()) {
$value->setConfigurator($this->processValue($v));
if (isset($changes['configurator'])) {
$value->setConfigurator($this->processValue($value->getConfigurator()));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public function __construct()
$this->beforeOptimizationPasses = array(
100 => array(
$resolveClassPass = new ResolveClassPass(),
new ResolveDefinitionInheritancePass(),
new ResolveInstanceofConditionalsPass(),
new ResolveTagsInheritancePass(),
),
);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private function doResolveDefinition(ChildDefinition $definition)
$def = new Definition();

// merge in parent definition
// purposely ignored attributes: abstract, tags
// purposely ignored attributes: abstract, shared, tags
$def->setClass($parentDef->getClass());
$def->setArguments($parentDef->getArguments());
$def->setMethodCalls($parentDef->getMethodCalls());
Expand All @@ -101,27 +101,8 @@ private function doResolveDefinition(ChildDefinition $definition)
$def->setPublic($parentDef->isPublic());
$def->setLazy($parentDef->isLazy());
$def->setAutowired($parentDef->isAutowired());
$def->setChanges($parentDef->getChanges());

self::mergeDefinition($def, $definition);

// merge autowiring types
foreach ($definition->getAutowiringTypes(false) as $autowiringType) {
$def->addAutowiringType($autowiringType);
}

// these attributes are always taken from the child
$def->setAbstract($definition->isAbstract());
$def->setShared($definition->isShared());
$def->setTags($definition->getTags());

return $def;
}

/**
* @internal
*/
public static function mergeDefinition(Definition $def, ChildDefinition $definition)
{
// overwrite with values specified in the decorator
$changes = $definition->getChanges();
if (isset($changes['class'])) {
Expand All @@ -148,6 +129,9 @@ public static function mergeDefinition(Definition $def, ChildDefinition $definit
if (isset($changes['autowired'])) {
$def->setAutowired($definition->isAutowired());
}
if (isset($changes['shared'])) {
$def->setShared($definition->isShared());
}
if (isset($changes['decorated_service'])) {
$decoratedService = $definition->getDecoratedService();
if (null === $decoratedService) {
Expand Down Expand Up @@ -182,5 +166,16 @@ public static function mergeDefinition(Definition $def, ChildDefinition $definit
if ($calls = $definition->getMethodCalls()) {
$def->setMethodCalls(array_merge($def->getMethodCalls(), $calls));
}

// merge autowiring types
foreach ($definition->getAutowiringTypes(false) as $autowiringType) {
$def->addAutowiringType($autowiringType);
}

// these attributes are always taken from the child
$def->setAbstract($definition->isAbstract());
$def->setTags($definition->getTags());

return $def;
}
}
Loading
0