Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. RequestDataCollector.php

function RequestDataCollector::parseController

Return value

array|string An array of controller data or a simple string

1 call to RequestDataCollector::parseController()
RequestDataCollector::collect in vendor/symfony/http-kernel/DataCollector/RequestDataCollector.php
Collects data for the given Request and Response.

File

vendor/symfony/http-kernel/DataCollector/RequestDataCollector.php, line 432

Class

RequestDataCollector
@author Fabien Potencier <fabien@symfony.com>

Namespace

Symfony\Component\HttpKernel\DataCollector

Code

private function parseController(array|object|string|null $controller) : array|string {
    if (\is_string($controller) && str_contains($controller, '::')) {
        $controller = explode('::', $controller);
    }
    if (\is_array($controller)) {
        try {
            $r = new \ReflectionMethod($controller[0], $controller[1]);
            return [
                'class' => \is_object($controller[0]) ? get_debug_type($controller[0]) : $controller[0],
                'method' => $controller[1],
                'file' => $r->getFileName(),
                'line' => $r->getStartLine(),
            ];
        } catch (\ReflectionException) {
            if (\is_callable($controller)) {
                // using __call or  __callStatic
                return [
                    'class' => \is_object($controller[0]) ? get_debug_type($controller[0]) : $controller[0],
                    'method' => $controller[1],
                    'file' => 'n/a',
                    'line' => 'n/a',
                ];
            }
        }
    }
    if ($controller instanceof \Closure) {
        $r = new \ReflectionFunction($controller);
        $controller = [
            'class' => $r->getName(),
            'method' => null,
            'file' => $r->getFileName(),
            'line' => $r->getStartLine(),
        ];
        if ($r->isAnonymous()) {
            return $controller;
        }
        $controller['method'] = $r->name;
        if ($class = $r->getClosureCalledClass()) {
            $controller['class'] = $class->name;
        }
        else {
            return $r->name;
        }
        return $controller;
    }
    if (\is_object($controller)) {
        $r = new \ReflectionClass($controller);
        return [
            'class' => $r->getName(),
            'method' => null,
            'file' => $r->getFileName(),
            'line' => $r->getStartLine(),
        ];
    }
    return \is_string($controller) ? $controller : 'n/a';
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal