Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

ContainerControllerResolver.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 3.72 KiB


001  <?php
002   
003  /*
004   * This file is part of the Symfony package.
005   *
006   * (c) Fabien Potencier <fabien@symfony.com>
007   *
008   * For the full copyright and license information, please view the LICENSE
009   * file that was distributed with this source code.
010   */
011   
012  namespace Symfony\Component\HttpKernel\Controller;
013   
014  use Psr\Container\ContainerInterface;
015  use Psr\Log\LoggerInterface;
016  use Symfony\Component\DependencyInjection\Container;
017  use Symfony\Component\HttpFoundation\Request;
018   
019  /**
020   * A controller resolver searching for a controller in a psr-11 container when using the "service:method" notation.
021   *
022   * @author Fabien Potencier <fabien@symfony.com>
023   * @author Maxime Steinhausser <maxime.steinhausser@gmail.com>
024   */
025  class ContainerControllerResolver extends ControllerResolver
026  {
027      protected $container;
028   
029      public function __construct(ContainerInterface $container, LoggerInterface $logger = null)
030      {
031          $this->container = $container;
032   
033          parent::__construct($logger);
034      }
035   
036      /**
037       * {@inheritdoc}
038       */
039      public function getController(Request $request)
040      {
041          $controller = parent::getController($request);
042   
043          if (\is_array($controller) && isset($controller[0]) && \is_string($controller[0]) && $this->container->has($controller[0])) {
044              $controller[0] = $this->instantiateController($controller[0]);
045          }
046   
047          return $controller;
048      }
049   
050      /**
051       * Returns a callable for the given controller.
052       *
053       * @param string $controller A Controller string
054       *
055       * @return mixed A PHP callable
056       *
057       * @throws \LogicException           When the name could not be parsed
058       * @throws \InvalidArgumentException When the controller class does not exist
059       */
060      protected function createController($controller)
061      {
062          if (false !== strpos($controller, '::')) {
063              return parent::createController($controller);
064          }
065   
066          $method = null;
067          if (1 == substr_count($controller, ':')) {
068              // controller in the "service:method" notation
069              list($controller, $method) = explode(':', $controller, 2);
070          }
071   
072          if (!$this->container->has($controller)) {
073              $this->throwExceptionIfControllerWasRemoved($controller);
074   
075              throw new \LogicException(sprintf('Controller not found: service "%s" does not exist.', $controller));
076          }
077   
078          $service = $this->container->get($controller);
079          if (null !== $method) {
080              return [$service, $method];
081          }
082   
083          if (!method_exists($service, '__invoke')) {
084              throw new \LogicException(sprintf('Controller "%s" cannot be called without a method name. Did you forget an "__invoke" method?', $controller));
085          }
086   
087          return $service;
088      }
089   
090      /**
091       * {@inheritdoc}
092       */
093      protected function instantiateController($class)
094      {
095          if ($this->container->has($class)) {
096              return $this->container->get($class);
097          }
098   
099          try {
100              return parent::instantiateController($class);
101          } catch (\ArgumentCountError $e) {
102          } catch (\ErrorException $e) {
103          } catch (\TypeError $e) {
104          }
105   
106          $this->throwExceptionIfControllerWasRemoved($class, $e);
107   
108          throw $e;
109      }
110   
111      /**
112       * @param string                     $controller
113       * @param \Exception|\Throwable|null $previous
114       */
115      private function throwExceptionIfControllerWasRemoved($controller, $previous = null)
116      {
117          if ($this->container instanceof Container && isset($this->container->getRemovedIds()[$controller])) {
118              throw new \LogicException(sprintf('Controller "%s" cannot be fetched from the container because it is private. Did you forget to tag the service with "controller.service_arguments"?', $controller), 0, $previous);
119          }
120      }
121  }
122