Skip to content
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

[DI] Factorize compiler passes around new AbstractRecursivePass #21327

Merged
merged 1 commit into from Jan 23, 2017

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Jan 17, 2017

Q A
Branch? master
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

This PR introduces an AbstractRecursivePass that is able to visit the definition tree recursively everywhere a Definition or a Reference can be nested.

All existing compiler passes that need recursivity are updated to leverage this new class.
This remove a bunch of boilerplate that was previously repeated all over.
It also fixes compiler passes that eg missed looking at configurators for no reason (this "fix" is a new feature really).
It then applies recursivity to AutowirePass, that does not handle it today, but should.

I'm happy that the net result is a loss of 153 lines :)

} else {
$arguments[$k] = clone $definition;
}
if ($definition->isShared()) {
Copy link
Member

Choose a reason for hiding this comment

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

Can this be turned into a 1-liner?

$value = $definition->isShared() ? $definition : clone $definition;

Copy link
Member

Choose a reason for hiding this comment

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

no. Shared definitions are returned directly, while non-shared ones are passed to the parent processing

Copy link
Member Author

Choose a reason for hiding this comment

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

Indeed now - I changed that after @javiereguiluz's comment :)

}
}
}
$this->lazy = false;

foreach ($container->getAliases() as $id => $alias) {
Copy link
Member

Choose a reason for hiding this comment

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

this is moved before the processing of definitions instead of after. Is it expected ? And does it make any difference ?

Copy link
Member Author

Choose a reason for hiding this comment

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

given that this pass is ready-only, that doesn't make any difference yes

} else {
$arguments[$k] = clone $definition;
}
if ($definition->isShared()) {
Copy link
Member

Choose a reason for hiding this comment

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

no. Shared definitions are returned directly, while non-shared ones are passed to the parent processing

$definition->setFactory($this->updateFactoryReference($replacements, $definition->getFactory()));
}
parent::process($container);
$this->replacements = array();
Copy link
Member

Choose a reason for hiding this comment

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

should be in a finally block to ensure it is still reset on exceptions

Copy link
Member Author

Choose a reason for hiding this comment

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

I decided not, to remove one level of indentation: on exception, there would be no circular refs to cleanup - thus no need.

}

/**
* Process a value found in a definition tree.
Copy link
Member

Choose a reason for hiding this comment

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

Processes

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

* @param mixed $value
* @param bool $isRoot
*
* @return mixed The processed value
Copy link
Member

Choose a reason for hiding this comment

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

Can be removed as mixed does not really help :)

Copy link
Member Author

Choose a reason for hiding this comment

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

I fear that people won't notice that the return value is here at all.

abstract class AbstractRecursivePass implements CompilerPassInterface
{
protected $container;
protected $currentId;
Copy link
Member

Choose a reason for hiding this comment

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

Wouldn't it be "better" to create getters for those?

Copy link
Member Author

Choose a reason for hiding this comment

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

Some passes set the value also. They are "local vars passed as properties". Cleaned after use. Just saves boilerplates this way. I'd prefer keep them asis.

@fabpot fabpot merged commit 6acb80f into symfony:master Jan 23, 2017
fabpot added a commit that referenced this pull request Jan 23, 2017
…rsivePass (nicolas-grekas)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[DI] Factorize compiler passes around new AbstractRecursivePass

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

This PR introduces an AbstractRecursivePass that is able to visit the definition tree recursively everywhere a Definition or a Reference can be nested.

All existing compiler passes that need recursivity are updated to leverage this new class.
This remove a bunch of boilerplate that was previously repeated all over.
It also fixes compiler passes that eg missed looking at configurators for no reason (this "fix" is a new feature really).
It then applies recursivity to AutowirePass, that does not handle it today, but should.

I'm happy that the net result is a loss of 153 lines :)

Commits
-------

6acb80f [DI] Factorize compiler passes around new AbstractRecursivePass
@nicolas-grekas nicolas-grekas deleted the di-recursive branch January 23, 2017 21:12
fabpot added a commit that referenced this pull request Jan 24, 2017
This PR was merged into the 3.3-dev branch.

Discussion
----------

[DependencyInjection] Remove an unused docblock

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | n/a
| License       | MIT
| Doc PR        | n/a

The removal of this doc block was forgotten in #21327.

Commits
-------

9e33434 [DependencyInjection] Remove an unused docblock
@fabpot fabpot mentioned this pull request May 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants