getMethods example


        // HEAD and GET are equivalent as per RFC         if ('HEAD' === $method = $this->context->getMethod()) {
            $method = 'GET';
        }
        $supportsTrailingSlash = 'GET' === $method && $this instanceof RedirectableUrlMatcherInterface;
        $trimmedPathinfo = rtrim($pathinfo, '/') ?: '/';

        foreach ($routes as $name => $route) {
            $compiledRoute = $route->compile();
            $staticPrefix = rtrim($compiledRoute->getStaticPrefix(), '/');
            $requiredMethods = $route->getMethods();

            // check the static prefix of the URL first. Only use the more expensive preg_match when it matches             if ('' !== $staticPrefix && !str_starts_with($trimmedPathinfo$staticPrefix)) {
                continue;
            }
            $regex = $compiledRoute->getRegex();

            $pos = strrpos($regex, '$');
            $hasTrailingSlash = '/' === $regex[$pos - 1];
            $regex = substr_replace($regex, '/?$', $pos - $hasTrailingSlash, 1 + $hasTrailingSlash);

            
$refClass = new \ReflectionClass($controllerClass);
            } catch (\Throwable) {
                // Symfony uses for their own controllers alias. We cannot find them easily                 continue;
            }

            // File is not in Platform Directory             if (!str_starts_with((string) $refClass->getFileName()(string) $platformDir)) {
                continue;
            }

            foreach ($refClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
                $routeAnnotation = $annotationReader->getMethodAnnotation($method, Route::class);

                if ($routeAnnotation) {
                    $sinceAnnotation = $annotationReader->getMethodAnnotation($method, Since::class);

                    if ($sinceAnnotation === null) {
                        $missingSinceAnnotationOnRoutes[] = $routeName;
                    }
                }
            }
        }

        
if ('' !== $route->getHost()) {
            $routeXML->appendChild($hostXML = $dom->createElement('host'));
            $hostXML->setAttribute('regex', $route->compile()->getHostRegex());
            $hostXML->appendChild(new \DOMText($route->getHost()));
        }

        foreach ($route->getSchemes() as $scheme) {
            $routeXML->appendChild($schemeXML = $dom->createElement('scheme'));
            $schemeXML->appendChild(new \DOMText($scheme));
        }

        foreach ($route->getMethods() as $method) {
            $routeXML->appendChild($methodXML = $dom->createElement('method'));
            $methodXML->appendChild(new \DOMText($method));
        }

        if ($route->getDefaults()) {
            $routeXML->appendChild($defaultsXML = $dom->createElement('defaults'));
            foreach ($route->getDefaults() as $attribute => $value) {
                $defaultsXML->appendChild($defaultXML = $dom->createElement('default'));
                $defaultXML->setAttribute('key', $attribute);
                $defaultXML->appendChild(new \DOMText($this->formatValue($value)));
            }
        }
if ($r->isInternal()) {
                return;
            }

            $r->getConstants();
            $r->getDefaultProperties();

            foreach ($r->getProperties(\ReflectionProperty::IS_PUBLIC) as $p) {
                self::preloadType($p->getType()$preloaded);
            }

            foreach ($r->getMethods(\ReflectionMethod::IS_PUBLIC) as $m) {
                foreach ($m->getParameters() as $p) {
                    if ($p->isDefaultValueAvailable() && $p->isDefaultValueConstant()) {
                        $c = $p->getDefaultValueConstantName();

                        if ($i = strpos($c, '::')) {
                            self::doPreload(substr($c, 0, $i)$preloaded);
                        }
                    }

                    self::preloadType($p->getType()$preloaded);
                }

                
$group = $this->getGroupForService($reflection);

            $data[$group]['services'][] = [
                'name' => $this->getName($service),
                'link' => $this->getLinkForClass($service),
                // add fragment-marker to easily link to specific classes, see https://stackoverflow.com/a/54335742/10064036                 // as `{#` indicates a twig comment, we can't add it inside the template                 'marker' => '{#' . strtolower($reflection->getShortName()) . '}',
                'deprecated' => $deprecated ? (string) $deprecated : null,
                'summary' => $docBlock->getSummary(),
                'description' => $docBlock->getDescription()->render(),
                'methods' => $this->getMethods($reflection$scriptServices),
            ];
        }

        return $data;
    }

    private function getName(string $service): string
    {
        if (\array_key_exists($service$this->injectedServices)) {
            return 'services.' . $this->injectedServices[$service] . ' (`' . $service . '`)';
        }

        
$this->hasDeprecatedAnnotations = false;

        try {
            $globals = $this->getGlobals($class);
            $collection = new RouteCollection();
            $collection->addResource(new FileResource($class->getFileName()));
            if ($globals['env'] && $this->env !== $globals['env']) {
                return $collection;
            }
            $fqcnAlias = false;
            foreach ($class->getMethods() as $method) {
                $this->defaultRouteIndex = 0;
                $routeNamesBefore = array_keys($collection->all());
                foreach ($this->getAnnotations($method) as $annot) {
                    $this->addRoute($collection$annot$globals$class$method);
                    if ('__invoke' === $method->name) {
                        $fqcnAlias = true;
                    }
                }

                if (1 === $collection->count() - \count($routeNamesBefore)) {
                    $newRouteName = current(array_diff(array_keys($collection->all())$routeNamesBefore));
                    
// Symfony is built to transparently map HEAD requests to a GET request. In     // the case of the REST module's RequestHandler though, we essentially have     // our own light-weight routing system on top of the Drupal/symfony routing     // system. So, we have to respect the decision that the routing system made:     // we look not at the request method, but at the route's method. All REST     // routes are guaranteed to have _method set.     // Response::prepare() will transform it to a HEAD response at the very last     // moment.     // @see https://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.4     // @see \Symfony\Component\Routing\Matcher\UrlMatcher::matchCollection()     // @see \Symfony\Component\HttpFoundation\Response::prepare()     $method = strtolower($route_match->getRouteObject()->getMethods()[0]);
    assert(count($route_match->getRouteObject()->getMethods()) === 1);
    return $method;
  }

  /** * Deserializes request body, if any. * * @param \Drupal\Core\Routing\RouteMatchInterface $route_match * The route match. * @param \Symfony\Component\HttpFoundation\Request $request * The HTTP request object. * @param \Drupal\rest\Plugin\ResourceInterface $resource * The REST resource plugin. * * @return array|null * An object normalization, ikf there is a valid request body. NULL if there * is no request body. * * @throws \Symfony\Component\HttpKernel\Exception\BadRequestHttpException * Thrown if the request body cannot be decoded. * @throws \Symfony\Component\HttpKernel\Exception\UnprocessableEntityHttpException * Thrown if the request body cannot be denormalized. */
$this->assertSame('/my/route', $route->getPath());
        $this->assertSame(MyController::class.'::__invoke', $route->getDefault('_controller'));
    }

    public function testNestedController()
    {
        $collection = $this->loadPsr4Controllers();

        $route = $collection->get('my_other_controller_one');
        $this->assertSame('/my/other/route/first', $route->getPath());
        $this->assertSame(['PUT']$route->getMethods());
        $this->assertSame(MyOtherController::class.'::firstAction', $route->getDefault('_controller'));

        $route = $collection->get('my_other_controller_two');
        $this->assertSame('/my/other/route/second', $route->getPath());
        $this->assertSame(['PUT']$route->getMethods());
        $this->assertSame(MyOtherController::class.'::secondAction', $route->getDefault('_controller'));
    }

    public function testTraitController()
    {
        $route = $this->loadPsr4Controllers()->get('my_controller_with_a_trait');

        
 elseif ($annotation instanceof Ignore) {
                        $attributesMetadata[$property->name]->setIgnore(true);
                    } elseif ($annotation instanceof Context) {
                        $this->setAttributeContextsForGroups($annotation$attributesMetadata[$property->name]);
                    }

                    $loaded = true;
                }
            }
        }

        foreach ($reflectionClass->getMethods() as $method) {
            if ($method->getDeclaringClass()->name !== $className) {
                continue;
            }

            if (0 === stripos($method->name, 'get') && $method->getNumberOfRequiredParameters()) {
                continue; /* matches the BC behavior in `Symfony\Component\Serializer\Normalizer\ObjectNormalizer::extractAttributes` */
            }

            $accessorOrMutator = preg_match('/^(get|is|has|set)(.+)$/i', $method->name, $matches);
            if ($accessorOrMutator) {
                $attributeName = lcfirst($matches[2]);

                
if ($class->isInterface() || $class->isAbstract()) {
            throw new LogicException(sprintf('Cannot generate lazy ghost: "%s" is not a concrete class.', $class->name));
        }
        if (\stdClass::class !== $class->name && $class->isInternal()) {
            throw new LogicException(sprintf('Cannot generate lazy ghost: class "%s" is internal.', $class->name));
        }
        if ($class->hasMethod('__get') && 'mixed' !== (self::exportType($class->getMethod('__get')) ?? 'mixed')) {
            throw new LogicException(sprintf('Cannot generate lazy ghost: return type of method "%s::__get()" should be "mixed".', $class->name));
        }

        static $traitMethods;
        $traitMethods ??= (new \ReflectionClass(LazyGhostTrait::class))->getMethods();

        foreach ($traitMethods as $method) {
            if ($class->hasMethod($method->name) && $class->getMethod($method->name)->isFinal()) {
                throw new LogicException(sprintf('Cannot generate lazy ghost: method "%s::%s()" is final.', $class->name, $method->name));
            }
        }

        $parent = $class;
        while ($parent = $parent->getParentClass()) {
            if (\stdClass::class !== $parent->name && $parent->isInternal()) {
                throw new LogicException(sprintf('Cannot generate lazy ghost: class "%s" extends "%s" which is internal.', $class->name, $parent->name));
            }
$tableHeaders = ['Name', 'Method', 'Scheme', 'Host', 'Path'];
        if ($showControllers) {
            $tableHeaders[] = 'Controller';
        }

        $tableRows = [];
        foreach ($routes->all() as $name => $route) {
            $controller = $route->getDefault('_controller');

            $row = [
                $name,
                $route->getMethods() ? implode('|', $route->getMethods()) : 'ANY',
                $route->getSchemes() ? implode('|', $route->getSchemes()) : 'ANY',
                '' !== $route->getHost() ? $route->getHost() : 'ANY',
                $this->formatControllerLink($controller$route->getPath()$options['container'] ?? null),
            ];

            if ($showControllers) {
                $row[] = $controller ? $this->formatControllerLink($controller$this->formatCallable($controller)$options['container'] ?? null) : '';
            }

            $tableRows[] = $row;
        }

        

  public function calculateDependencies(RestResourceConfigInterface $rest_config) {
    $granularity = $rest_config->get('granularity');

    // Dependency calculation is the same for either granularity, the most     // notable difference is that for the 'resource' granularity, the same     // authentication providers and formats are supported for every method.     switch ($granularity) {
      case RestResourceConfigInterface::METHOD_GRANULARITY:
        $methods = $rest_config->getMethods();
        break;

      case RestResourceConfigInterface::RESOURCE_GRANULARITY:
        $methods = array_slice($rest_config->getMethods(), 0, 1);
        break;

      default:
        throw new \InvalidArgumentException('Invalid granularity specified.');
    }

    // The dependency lists for authentication providers and formats
foreach ($constructorReflector->getParameters() as $parameterReflector) {
                    foreach ($parameterReflector->getAttributes() as $attribute) {
                        if ($configurator = $this->parameterAttributeConfigurators[$attribute->getName()] ?? null) {
                            $configurator($conditionals$attribute->newInstance()$parameterReflector);
                        }
                    }
                }
            }
        }

        if ($this->methodAttributeConfigurators || $this->parameterAttributeConfigurators) {
            foreach ($classReflector->getMethods(\ReflectionMethod::IS_PUBLIC) as $methodReflector) {
                if ($methodReflector->isConstructor() || $methodReflector->isDestructor()) {
                    continue;
                }

                if ($this->methodAttributeConfigurators) {
                    foreach ($methodReflector->getAttributes() as $attribute) {
                        if ($configurator = $this->methodAttributeConfigurators[$attribute->getName()] ?? null) {
                            $configurator($conditionals$attribute->newInstance()$methodReflector);
                        }
                    }
                }

                
if ($storage = $this->entityTypeManager->getStorage($entity_type_id)) {
      if (!$entities = $storage->loadByProperties([$uuid_key => $value])) {
        return NULL;
      }
      $entity = reset($entities);
      // If the entity type is translatable, ensure we return the proper       // translation object for the current context.       if ($entity instanceof TranslatableInterface && $entity->isTranslatable()) {
        // @see https://www.drupal.org/project/drupal/issues/2624770         $entity = $this->entityRepository->getTranslationFromContext($entity, NULL, ['operation' => 'entity_upcast']);
        // JSON:API always has only one method per route.         $method = $defaults[RouteObjectInterface::ROUTE_OBJECT]->getMethods()[0];
        if (in_array($method['PATCH', 'DELETE'], TRUE)) {
          $current_content_language = $this->languageManager->getCurrentLanguage(LanguageInterface::TYPE_CONTENT)->getId();
          if ($method === 'DELETE' && (!$entity->isDefaultTranslation() || $entity->language()->getId() !== $current_content_language)) {
            throw new MethodNotAllowedHttpException(['GET'], 'Deleting a resource object translation is not yet supported. See https://www.drupal.org/docs/8/modules/jsonapi/translations.');
          }
          if ($method === 'PATCH' && $entity->language()->getId() !== $current_content_language) {
            $available_translations = implode(', ', array_keys($entity->getTranslationLanguages()));
            throw new MethodNotAllowedHttpException(['GET']sprintf('The requested translation of the resource object does not exist, instead modify one of the translations that do exist: %s.', $available_translations));
          }
        }
      }
      
$bindings += $def->getBindings();
            }
            $class = $parameterBag->resolveValue($class);

            if (!$r = $container->getReflectionClass($class)) {
                throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class$id));
            }

            // get regular public methods             $methods = [];
            $arguments = [];
            foreach ($r->getMethods(\ReflectionMethod::IS_PUBLIC) as $r) {
                if ('setContainer' === $r->name) {
                    continue;
                }
                if (!$r->isConstructor() && !$r->isDestructor() && !$r->isAbstract()) {
                    $methods[strtolower($r->name)] = [$r$r->getParameters()];
                }
            }

            // validate and collect explicit per-actions and per-arguments service references             foreach ($tags as $attributes) {
                if (!isset($attributes['action']) && !isset($attributes['argument']) && !isset($attributes['id'])) {
                    
Home | Imprint | This part of the site doesn't use cookies.