Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

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

resolver.php

Zuletzt modifiziert: 09.10.2024, 12:52 - Dateigröße: 4.76 KiB


 001  <?php
 002  /**
 003  *
 004  * This file is part of the phpBB Forum Software package.
 005  *
 006  * @copyright (c) phpBB Limited <https://www.phpbb.com>
 007  * @license GNU General Public License, version 2 (GPL-2.0)
 008  *
 009  * For full copyright and license information, please see
 010  * the docs/CREDITS.txt file.
 011  *
 012  */
 013   
 014  namespace phpbb\controller;
 015   
 016  use Symfony\Component\HttpKernel\Controller\ControllerResolverInterface;
 017  use Symfony\Component\DependencyInjection\ContainerInterface;
 018  use Symfony\Component\HttpFoundation\Request;
 019   
 020  /**
 021  * Controller manager class
 022  */
 023  class resolver implements ControllerResolverInterface
 024  {
 025      /**
 026      * ContainerInterface object
 027      * @var ContainerInterface
 028      */
 029      protected $container;
 030   
 031      /**
 032      * phpbb\template\template object
 033      * @var \phpbb\template\template
 034      */
 035      protected $template;
 036   
 037      /**
 038      * Request type cast helper object
 039      * @var \phpbb\request\type_cast_helper
 040      */
 041      protected $type_cast_helper;
 042   
 043      /**
 044      * phpBB root path
 045      * @var string
 046      */
 047      protected $phpbb_root_path;
 048   
 049      /**
 050      * Construct method
 051      *
 052      * @param ContainerInterface $container ContainerInterface object
 053      * @param string $phpbb_root_path Relative path to phpBB root
 054      * @param \phpbb\template\template $template
 055      */
 056      public function __construct(ContainerInterface $container, $phpbb_root_path, \phpbb\template\template $template = null)
 057      {
 058          $this->container = $container;
 059          $this->template = $template;
 060          $this->type_cast_helper = new \phpbb\request\type_cast_helper();
 061          $this->phpbb_root_path = $phpbb_root_path;
 062      }
 063   
 064      /**
 065      * Load a controller callable
 066      *
 067      * @param \Symfony\Component\HttpFoundation\Request $request Symfony Request object
 068      * @return bool|Callable Callable or false
 069      * @throws \phpbb\controller\exception
 070      */
 071      public function getController(Request $request)
 072      {
 073          $controller = $request->attributes->get('_controller');
 074   
 075          if (!$controller)
 076          {
 077              throw new \phpbb\controller\exception('CONTROLLER_NOT_SPECIFIED');
 078          }
 079   
 080          // Require a method name along with the service name
 081          if (stripos($controller, ':') === false)
 082          {
 083              throw new \phpbb\controller\exception('CONTROLLER_METHOD_NOT_SPECIFIED');
 084          }
 085   
 086          list($service, $method) = explode(':', $controller);
 087   
 088          if (!$this->container->has($service))
 089          {
 090              throw new \phpbb\controller\exception('CONTROLLER_SERVICE_UNDEFINED', array($service));
 091          }
 092   
 093          $controller_object = $this->container->get($service);
 094   
 095          /*
 096          * If this is an extension controller, we'll try to automatically set
 097          * the style paths for the extension (the ext author can change them
 098          * if necessary).
 099          */
 100          $controller_dir = explode('\\', get_class($controller_object));
 101   
 102          // 0 vendor, 1 extension name, ...
 103          if (!is_null($this->template) && isset($controller_dir[1]))
 104          {
 105              $controller_style_dir = 'ext/' . $controller_dir[0] . '/' . $controller_dir[1] . '/styles';
 106   
 107              if (is_dir($this->phpbb_root_path . $controller_style_dir))
 108              {
 109                  $this->template->set_style(array($controller_style_dir, 'styles'));
 110              }
 111          }
 112   
 113          return array($controller_object, $method);
 114      }
 115   
 116      /**
 117      * Dependencies should be specified in the service definition and can be
 118      * then accessed in __construct(). Arguments are sent through the URL path
 119      * and should match the parameters of the method you are using as your
 120      * controller.
 121      *
 122      * @param \Symfony\Component\HttpFoundation\Request $request Symfony Request object
 123      * @param mixed $controller A callable (controller class, method)
 124      * @return array An array of arguments to pass to the controller
 125      * @throws \phpbb\controller\exception
 126      */
 127      public function getArguments(Request $request, $controller)
 128      {
 129          // At this point, $controller should be a callable
 130          if (is_array($controller))
 131          {
 132              list($object, $method) = $controller;
 133              $mirror = new \ReflectionMethod($object, $method);
 134          }
 135          else if (is_object($controller) && !$controller instanceof \Closure)
 136          {
 137              $mirror = new \ReflectionObject($controller);
 138              $mirror = $mirror->getMethod('__invoke');
 139          }
 140          else
 141          {
 142              $mirror = new \ReflectionFunction($controller);
 143          }
 144   
 145          $arguments = array();
 146          $parameters = $mirror->getParameters();
 147          $attributes = $request->attributes->all();
 148          foreach ($parameters as $param)
 149          {
 150              if (array_key_exists($param->name, $attributes))
 151              {
 152                  if (is_string($attributes[$param->name]))
 153                  {
 154                      $value = $attributes[$param->name];
 155                      $this->type_cast_helper->set_var($value, $attributes[$param->name], 'string', true, false);
 156                      $arguments[] = $value;
 157                  }
 158                  else
 159                  {
 160                      $arguments[] = $attributes[$param->name];
 161                  }
 162              }
 163              else if ($param->getClass() && $param->getClass()->isInstance($request))
 164              {
 165                  $arguments[] = $request;
 166              }
 167              else if ($param->isDefaultValueAvailable())
 168              {
 169                  $arguments[] = $param->getDefaultValue();
 170              }
 171              else
 172              {
 173                  throw new \phpbb\controller\exception('CONTROLLER_ARGUMENT_VALUE_MISSING', array($param->getPosition() + 1, get_class($object) . ':' . $method, $param->name));
 174              }
 175          }
 176   
 177          return $arguments;
 178      }
 179  }
 180