-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
[DependencyInjection] Add autowiring capabilities #15613
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
Closed
Closed
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
9828da2
[DependencyInjection] Add autowiring capabilities
dunglas 195f6c0
Fix CS
dunglas 8d23c9d
Remove unused argument
dunglas 27f4de8
Fix CS
dunglas 5575ec1
Fix issues raised by @stof
dunglas edce23d
Better RunTime exception error.
dunglas 07d475e
Fix CS
dunglas afe009a
Flag to enable/disable autowiring. no_autowiring tag.
dunglas 7ab5b08
Fix some tests
dunglas a7ca3f2
Fix @meyerbaptiste comments
dunglas 57c494c
Move the autowiring parameter to a setter
dunglas e642aa8
Fix SecurityBundle test
dunglas d00c7e3
Optin. Removed config flag.
dunglas 55bb42c
Fix CS
dunglas 7806487
[DependencyInjection] Rename types to autowiring_types
dunglas 585616d
[DependencyInjection] Add the new 'autowire' syntax.
dunglas c717c69
Fix tests.
dunglas 3b7f553
Fix @fabpot and @stof comments.
dunglas 936a16a
Typehint against a non-existing class
dunglas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
- Loading branch information
commit 3b7f5538643a5b25e8e5c4060a50826fc34d59f9
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,18 +59,19 @@ public function process(ContainerBuilder $container) | |
*/ | ||
private function completeDefinition($id, Definition $definition) | ||
{ | ||
if (!($reflectionClass = $this->getReflectionClass($id, $definition))) { | ||
if (!$reflectionClass = $this->getReflectionClass($id, $definition)) { | ||
return; | ||
} | ||
|
||
$this->container->addClassResource($reflectionClass); | ||
|
||
if (!($constructor = $reflectionClass->getConstructor())) { | ||
if (!$constructor = $reflectionClass->getConstructor()) { | ||
return; | ||
} | ||
|
||
$arguments = $definition->getArguments(); | ||
foreach ($constructor->getParameters() as $index => $parameter) { | ||
if (!($typeHint = $parameter->getClass())) { | ||
if (!$typeHint = $parameter->getClass()) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the case of non-existent classes still need to be handled |
||
continue; | ||
} | ||
|
||
|
@@ -243,6 +244,10 @@ private function getReflectionClass($id, Definition $definition) | |
|
||
$class = $this->container->getParameterBag()->resolveValue($class); | ||
|
||
return $this->reflectionClasses[$id] = new \ReflectionClass($class); | ||
try { | ||
return $this->reflectionClasses[$id] = new \ReflectionClass($class); | ||
} catch (\ReflectionException $reflectionException) { | ||
// return null | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ services: | |
foo_service: | ||
class: FooClass | ||
# types is not an array | ||
autowiring_types: string | ||
autowiring_types: 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess this method can be simplified if we use
PropertyInfo
component ?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so. What do you have in mind?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought it might be useful for guessing types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's useful here because the PHP reflection is enough. We only need typehint information.