Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
drupal
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
drupal
Merge requests
!5879
Added automatically wiring dependencies if ContainerInjectionInterface is not implemented.
Code
Review changes
Check out branch
Download
Patches
Plain diff
Open
Added automatically wiring dependencies if ContainerInjectionInterface is not implemented.
issue/drupal-3409787:3409787-add-support-for
into
11.x
Overview
4
Commits
13
Pipelines
10
Changes
16
1 unresolved thread
Hide all comments
Open
Alexander Yureskul
requested to merge
issue/drupal-3409787:3409787-add-support-for
into
11.x
1 year ago
Overview
4
Commits
13
Pipelines
10
Changes
16
1 unresolved thread
Hide all comments
Expand
Closes
#3409787
1
0
Merge request reports
Compare
11.x
version 9
c3d8c787
1 year ago
version 8
3b547041
1 year ago
version 7
2806166d
1 year ago
version 6
7be85e5f
1 year ago
version 5
da919bad
1 year ago
version 4
45b2670a
1 year ago
version 3
11e1b185
1 year ago
version 2
5c376cd1
1 year ago
version 1
8a109e4b
1 year ago
11.x (base)
and
latest version
latest version
6c938eb7
13 commits,
1 year ago
version 9
c3d8c787
12 commits,
1 year ago
version 8
3b547041
10 commits,
1 year ago
version 7
2806166d
8 commits,
1 year ago
version 6
7be85e5f
6 commits,
1 year ago
version 5
da919bad
5 commits,
1 year ago
version 4
45b2670a
4 commits,
1 year ago
version 3
11e1b185
3 commits,
1 year ago
version 2
5c376cd1
2 commits,
1 year ago
version 1
8a109e4b
1 commit,
1 year ago
16 files
+
387
−
28
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
16
Search (e.g. *.vue) (Ctrl+P)
core/lib/Drupal/Core/DependencyInjection/AutowireTrait.php
+
1
−
21
Options
@@ -2,9 +2,7 @@
namespace
Drupal\Core\DependencyInjection
;
use
Symfony\Component\DependencyInjection\Attribute\Autowire
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Symfony\Component\DependencyInjection\Exception\AutowiringFailedException
;
/**
* Defines a trait for automatically wiring dependencies from the container.
@@ -23,25 +21,7 @@ trait AutowireTrait {
* @return static
*/
public
static
function
create
(
ContainerInterface
$container
)
{
$args
=
[];
if
(
method_exists
(
static
::
class
,
'__construct'
))
{
$constructor
=
new
\ReflectionMethod
(
static
::
class
,
'__construct'
);
foreach
(
$constructor
->
getParameters
()
as
$parameter
)
{
$service
=
ltrim
((
string
)
$parameter
->
getType
(),
'?'
);
foreach
(
$parameter
->
getAttributes
(
Autowire
::
class
)
as
$attribute
)
{
$service
=
(
string
)
$attribute
->
newInstance
()
->
value
;
}
if
(
!
$container
->
has
(
$service
))
{
throw
new
AutowiringFailedException
(
$service
,
sprintf
(
'Cannot autowire service "%s": argument "$%s" of method "%s::_construct()", you should configure its value explicitly.'
,
$service
,
$parameter
->
getName
(),
static
::
class
));
}
$args
[]
=
$container
->
get
(
$service
);
}
}
return
new
static
(
...
$args
);
return
$container
->
get
(
DependencyAutowire
::
class
)
->
autowireClass
(
new
\ReflectionClass
(
static
::
class
));
}
}
Loading