protected ArgumentsResolver::getArgument(\ReflectionParameter $parameter)
Gets the argument value for a parameter.
Parameters
\ReflectionParameter $parameter: The parameter of a callable to get the value for.
Return value
mixed The value of the requested parameter value.
Throws
\RuntimeException Thrown when there is a missing parameter.
File
- core/lib/Drupal/Component/Utility/ArgumentsResolver.php, line 71
Class
- ArgumentsResolver
- Resolves the arguments to pass to a callable.
Namespace
Drupal\Component\Utility
Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | protected function getArgument(\ReflectionParameter $parameter ) { $parameter_type_hint = $parameter ->getClass(); $parameter_name = $parameter ->getName(); // If the argument exists and is NULL, return it, regardless of // parameter type hint. if (!isset( $this ->objects[ $parameter_name ]) && array_key_exists ( $parameter_name , $this ->objects)) { return NULL; } if ( $parameter_type_hint ) { // If the argument exists and complies with the type hint, return it. if (isset( $this ->objects[ $parameter_name ]) && is_object ( $this ->objects[ $parameter_name ]) && $parameter_type_hint ->isInstance( $this ->objects[ $parameter_name ])) { return $this ->objects[ $parameter_name ]; } // Otherwise, resolve wildcard arguments by type matching. foreach ( $this ->wildcards as $wildcard ) { if ( $parameter_type_hint ->isInstance( $wildcard )) { return $wildcard ; } } } elseif (isset( $this ->scalars[ $parameter_name ])) { return $this ->scalars[ $parameter_name ]; } // If the callable provides a default value, use it. if ( $parameter ->isDefaultValueAvailable()) { return $parameter ->getDefaultValue(); } // Can't resolve it: call a method that throws an exception or can be // overridden to do something else. return $this ->handleUnresolvedArgument( $parameter ); } |
Please login to continue.