Skip to content

[DependencyInjection] Add a new Syntax to define factories as callables #12008

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 2 commits into from
Sep 24, 2014

Conversation

fabpot
Copy link
Member

@fabpot fabpot commented Sep 24, 2014

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

From the original PR #9839:

"This pull requests adds a new syntax to define factories based on the syntax for configurators. This is more flexible than the old syntax (factoryMethod and either of factoryClass or factoryService), as it also allows for functions as factories.

Since the service is now a Reference to a Definition it also allows us to inline factories for a small performance improvement and better encapsulation.

Lastly this prevents a bug where a private factory is simple removed because it's not referenced in the graph.

I did not change any of the existing definitions (there's one use of a factory in FrameworkBundle) or automatically use the new internal representation when parsing YAML or XML definitions because this could introduce subtle B/C issues.
"

if (is_string($factory)) {
$return[] = sprintf('@return object An instance returned by %s().', $factory);
} elseif (is_array($factory) && (is_string($factory[0]) || $factory[0] instanceof Definition || $factory[0] instanceof Reference)) {
if (is_string($factory[0] || $factory[0] instanceof Reference)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Typo.

Copy link
Member Author

Choose a reason for hiding this comment

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

good catch!

@stof
Copy link
Member

stof commented Sep 24, 2014

👍

1 similar comment
@fabpot
Copy link
Member Author

fabpot commented Sep 24, 2014

👍

@fabpot fabpot merged commit 187aeee into symfony:master Sep 24, 2014
fabpot added a commit that referenced this pull request Sep 24, 2014
…ries as callables (realityking, fabpot)

This PR was merged into the 2.6-dev branch.

Discussion
----------

[DependencyInjection] Add a new Syntax to define factories as callables

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

From the original PR #9839:

"This pull requests adds a new syntax to define factories based on the syntax for configurators. This is more flexible than the old syntax (factoryMethod and either of factoryClass or factoryService), as it also allows for functions as factories.

Since the service is now a Reference to a Definition it also allows us to inline factories for a small performance improvement and better encapsulation.

Lastly this prevents a bug where a private factory is simple removed because it's not referenced in the graph.

I did not change any of the existing definitions (there's one use of a factory in FrameworkBundle) or automatically use the new internal representation when parsing YAML or XML definitions because this could introduce subtle B/C issues.
"

Commits
-------

187aeee fixed CS
bd8531d added a new Syntax to define factories as callables.
@fabpot fabpot deleted the dic-factory branch September 26, 2014 06:45
fabpot added a commit that referenced this pull request Oct 3, 2014
This PR was merged into the 2.6-dev branch.

Discussion
----------

[DependencyInjection] Tweaked factories

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

There are some issues with new service factories:
 * `ContainerBuilder` cannot instantiate service from factory (i.e. currently it works for dumped code only)
 * Dumped code sometimes is invalid (anonymous services as factories, factories without arguments)

Commits
-------

ee82392 [DependencyInjection] Tweaked factories
weaverryan added a commit to symfony/symfony-docs that referenced this pull request Nov 24, 2014
This PR was merged into the 2.6 branch.

Discussion
----------

Use new factory syntax

| Q   | A
| --- | ---
| Doc fix? | no
| New docs? | yes (symfony/symfony#12008)
| Applies to | 2.6+
| Fixed tickets | #4291

Commits
-------

9cbcc2b Applied fixes
d7998b0 Use new factory syntax
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants