Updated Drupal to 8.6. This goes with the following updates because it's possible...
[yaffs-website] / vendor / symfony / http-kernel / ControllerMetadata / ArgumentMetadataFactory.php
index d1e7af206804b9d92e1b04edbe1a88812ffc5e86..b46be7e8b70976b3d51dd1f393836282eaa135ac 100644 (file)
@@ -49,16 +49,16 @@ final class ArgumentMetadataFactory implements ArgumentMetadataFactoryInterface
     {
         $arguments = array();
 
-        if (is_array($controller)) {
+        if (\is_array($controller)) {
             $reflection = new \ReflectionMethod($controller[0], $controller[1]);
-        } elseif (is_object($controller) && !$controller instanceof \Closure) {
+        } elseif (\is_object($controller) && !$controller instanceof \Closure) {
             $reflection = (new \ReflectionObject($controller))->getMethod('__invoke');
         } else {
             $reflection = new \ReflectionFunction($controller);
         }
 
         foreach ($reflection->getParameters() as $param) {
-            $arguments[] = new ArgumentMetadata($param->getName(), $this->getType($param), $this->isVariadic($param), $this->hasDefaultValue($param), $this->getDefaultValue($param), $param->allowsNull());
+            $arguments[] = new ArgumentMetadata($param->getName(), $this->getType($param, $reflection), $this->isVariadic($param), $this->hasDefaultValue($param), $this->getDefaultValue($param), $param->allowsNull());
         }
 
         return $arguments;
@@ -105,25 +105,37 @@ final class ArgumentMetadataFactory implements ArgumentMetadataFactoryInterface
      *
      * @param \ReflectionParameter $parameter
      *
-     * @return null|string
+     * @return string|null
      */
-    private function getType(\ReflectionParameter $parameter)
+    private function getType(\ReflectionParameter $parameter, \ReflectionFunctionAbstract $function)
     {
         if ($this->supportsParameterType) {
             if (!$type = $parameter->getType()) {
                 return;
             }
-            $typeName = $type instanceof \ReflectionNamedType ? $type->getName() : $type->__toString();
-            if ('array' === $typeName && !$type->isBuiltin()) {
+            $name = $type instanceof \ReflectionNamedType ? $type->getName() : $type->__toString();
+            if ('array' === $name && !$type->isBuiltin()) {
                 // Special case for HHVM with variadics
                 return;
             }
-
-            return $typeName;
+        } elseif (preg_match('/^(?:[^ ]++ ){4}([a-zA-Z_\x7F-\xFF][^ ]++)/', $parameter, $name)) {
+            $name = $name[1];
+        } else {
+            return;
         }
+        $lcName = strtolower($name);
 
-        if (preg_match('/^(?:[^ ]++ ){4}([a-zA-Z_\x7F-\xFF][^ ]++)/', $parameter, $info)) {
-            return $info[1];
+        if ('self' !== $lcName && 'parent' !== $lcName) {
+            return $name;
+        }
+        if (!$function instanceof \ReflectionMethod) {
+            return;
+        }
+        if ('self' === $lcName) {
+            return $function->getDeclaringClass()->name;
+        }
+        if ($parent = $function->getDeclaringClass()->getParentClass()) {
+            return $parent->name;
         }
     }
 }