This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /** |
||
4 | * @file |
||
5 | * Contains \Drupal\service_container\Plugin\ContainerAwarePluginManager |
||
6 | */ |
||
7 | |||
8 | namespace Drupal\service_container\Plugin; |
||
9 | |||
10 | use Drupal\Component\Plugin\Exception\PluginException; |
||
11 | use Drupal\Component\Plugin\PluginManagerInterface; |
||
12 | use Drupal\service_container\DependencyInjection\ContainerAware; |
||
13 | |||
14 | /** |
||
15 | * Base class for plugin managers. |
||
16 | */ |
||
17 | class ContainerAwarePluginManager extends ContainerAware implements PluginManagerInterface { |
||
18 | |||
19 | /** |
||
20 | * Constructs a ContainerAwarePluginManager object. |
||
21 | * |
||
22 | * @param string $service_prefix |
||
23 | * The service prefix used to get the plugin instances from the container. |
||
24 | */ |
||
25 | public function __construct($service_prefix) { |
||
26 | $this->servicePrefix = $service_prefix; |
||
0 ignored issues
–
show
|
|||
27 | } |
||
28 | |||
29 | /** |
||
30 | * {@inheritdoc} |
||
31 | */ |
||
32 | public function getDefinition($plugin_id, $exception_on_invalid = TRUE) { |
||
33 | return $this->container->getDefinition($this->servicePrefix . $plugin_id, $exception_on_invalid); |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Symfony\Component\Depend...tion\ContainerInterface as the method getDefinition() does only exist in the following implementations of said interface: Container14\ProjectServiceContainer , Drupal\Core\DependencyInjection\ContainerBuilder , Drupal\service_container...encyInjection\Container , Symfony\Component\Depend...ection\ContainerBuilder , Symfony\Component\Depend...\Tests\ProjectContainer .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
34 | } |
||
35 | |||
36 | /** |
||
37 | * {@inheritdoc} |
||
38 | */ |
||
39 | public function getDefinitions() { |
||
40 | $definitions = $this->container->getDefinitions(); |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Symfony\Component\Depend...tion\ContainerInterface as the method getDefinitions() does only exist in the following implementations of said interface: Container14\ProjectServiceContainer , Drupal\Core\DependencyInjection\ContainerBuilder , Drupal\service_container...encyInjection\Container , Symfony\Component\Depend...ection\ContainerBuilder , Symfony\Component\Depend...\Tests\ProjectContainer .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
41 | $prefix = $this->servicePrefix; |
||
42 | |||
43 | // Note: ARRAY_FILTER_USE_BOTH is not supported in HHVM and PHP 5.4. |
||
44 | $keys = array_filter(array_keys($definitions), |
||
45 | function($key) use ($prefix) { |
||
46 | return strpos($key, $prefix) === 0; |
||
47 | }); |
||
48 | return array_intersect_key($definitions, array_flip($keys)); |
||
49 | } |
||
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | */ |
||
54 | public function hasDefinition($plugin_id) { |
||
55 | return $this->container->hasDefinition($this->servicePrefix . $plugin_id); |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Symfony\Component\Depend...tion\ContainerInterface as the method hasDefinition() does only exist in the following implementations of said interface: Container14\ProjectServiceContainer , Drupal\Core\DependencyInjection\ContainerBuilder , Drupal\service_container...encyInjection\Container , Symfony\Component\Depend...ection\ContainerBuilder , Symfony\Component\Depend...\Tests\ProjectContainer .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
56 | } |
||
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | */ |
||
61 | public function createInstance($plugin_id, array $configuration = array()) { |
||
62 | $plugin_definition_copy = $plugin_definition = $this->getDefinition($plugin_id); |
||
63 | $plugin_class = static::getPluginClass($plugin_id, $plugin_definition); |
||
64 | |||
65 | // If the plugin provides a factory method, pass the container to it. |
||
66 | if (is_subclass_of($plugin_class, 'Drupal\Core\Plugin\ContainerFactoryPluginInterface')) { |
||
67 | return $plugin_class::create($this->container, $configuration, $plugin_id, $plugin_definition); |
||
68 | } |
||
69 | |||
70 | $plugin_definition += array( |
||
71 | 'arguments' => array(), |
||
72 | ); |
||
73 | |||
74 | array_unshift($plugin_definition['arguments'], $plugin_definition_copy); |
||
75 | array_unshift($plugin_definition['arguments'], $plugin_id); |
||
76 | array_unshift($plugin_definition['arguments'], $configuration); |
||
77 | |||
78 | // Otherwise, create the plugin directly. |
||
79 | return $this->container->createInstance($this->servicePrefix . $plugin_id, $plugin_definition); |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Symfony\Component\Depend...tion\ContainerInterface as the method createInstance() does only exist in the following implementations of said interface: Drupal\service_container...encyInjection\Container .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
![]() |
|||
80 | } |
||
81 | |||
82 | /** |
||
83 | * {@inheritdoc} |
||
84 | */ |
||
85 | public function getInstance(array $options) { |
||
86 | // 90% of core does not use the generic $mapper functionality, so use a |
||
87 | // sane default function. |
||
88 | if (isset($options['id'])) { |
||
89 | return $this->createInstance($options['id']); |
||
90 | } |
||
91 | return FALSE; |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * Finds the class relevant for a given plugin. |
||
96 | * |
||
97 | * @param string $plugin_id |
||
98 | * The id of a plugin. |
||
99 | * @param mixed $plugin_definition |
||
100 | * The plugin definition associated with the plugin ID. |
||
101 | * @param string $required_interface |
||
102 | * (optional) THe required plugin interface. |
||
103 | * |
||
104 | * @return string |
||
105 | * The appropriate class name. |
||
106 | * |
||
107 | * @throws \Drupal\Component\Plugin\Exception\PluginException |
||
108 | * Thrown when there is no class specified, the class doesn't exist, or |
||
109 | * the class does not implement the specified required interface. |
||
110 | * |
||
111 | */ |
||
112 | public static function getPluginClass($plugin_id, $plugin_definition = NULL, $required_interface = NULL) { |
||
113 | if (empty($plugin_definition['class'])) { |
||
114 | throw new PluginException(sprintf('The plugin (%s) did not specify an instance class.', $plugin_id)); |
||
115 | } |
||
116 | |||
117 | $class = $plugin_definition['class']; |
||
118 | |||
119 | if (!class_exists($class)) { |
||
120 | throw new PluginException(sprintf('Plugin (%s) instance class "%s" does not exist.', $plugin_id, $class)); |
||
121 | } |
||
122 | |||
123 | if ($required_interface && !is_subclass_of($plugin_definition['class'], $required_interface)) { |
||
0 ignored issues
–
show
The expression
$required_interface of type string|null is loosely compared to true ; this is ambiguous if the string can be empty. You might want to explicitly use !== null instead.
In PHP, under loose comparison (like For '' == false // true
'' == null // true
'ab' == false // false
'ab' == null // false
// It is often better to use strict comparison
'' === false // false
'' === null // false
![]() |
|||
124 | throw new PluginException(sprintf('Plugin "%s" (%s) in %s should implement interface %s.', $plugin_id, $plugin_definition['class'], $plugin_definition['provider'], $required_interface)); |
||
125 | } |
||
126 | |||
127 | return $class; |
||
128 | } |
||
129 | } |
||
130 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: