Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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.71 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      * User object
027      * @var \phpbb\user
028      */
029      protected $user;
030   
031      /**
032      * ContainerInterface object
033      * @var ContainerInterface
034      */
035      protected $container;
036   
037      /**
038      * phpbb\template\template object
039      * @var \phpbb\template\template
040      */
041      protected $template;
042   
043      /**
044      * Request type cast helper object
045      * @var \phpbb\request\type_cast_helper
046      */
047      protected $type_cast_helper;
048   
049      /**
050      * phpBB root path
051      * @var string
052      */
053      protected $phpbb_root_path;
054   
055      /**
056      * Construct method
057      *
058      * @param \phpbb\user $user User Object
059      * @param ContainerInterface $container ContainerInterface object
060      * @param string $phpbb_root_path Relative path to phpBB root
061      * @param \phpbb\template\template $template
062      */
063      public function __construct(\phpbb\user $user, ContainerInterface $container, $phpbb_root_path, \phpbb\template\template $template = null)
064      {
065          $this->user = $user;
066          $this->container = $container;
067          $this->template = $template;
068          $this->type_cast_helper = new \phpbb\request\type_cast_helper();
069          $this->phpbb_root_path = $phpbb_root_path;
070      }
071   
072      /**
073      * Load a controller callable
074      *
075      * @param \Symfony\Component\HttpFoundation\Request $request Symfony Request object
076      * @return bool|Callable Callable or false
077      * @throws \phpbb\controller\exception
078      */
079      public function getController(Request $request)
080      {
081          $controller = $request->attributes->get('_controller');
082   
083          if (!$controller)
084          {
085              throw new \phpbb\controller\exception($this->user->lang['CONTROLLER_NOT_SPECIFIED']);
086          }
087   
088          // Require a method name along with the service name
089          if (stripos($controller, ':') === false)
090          {
091              throw new \phpbb\controller\exception($this->user->lang['CONTROLLER_METHOD_NOT_SPECIFIED']);
092          }
093   
094          list($service, $method) = explode(':', $controller);
095   
096          if (!$this->container->has($service))
097          {
098              throw new \phpbb\controller\exception($this->user->lang('CONTROLLER_SERVICE_UNDEFINED', $service));
099          }
100   
101          $controller_object = $this->container->get($service);
102   
103          /*
104          * If this is an extension controller, we'll try to automatically set
105          * the style paths for the extension (the ext author can change them
106          * if necessary).
107          */
108          $controller_dir = explode('\\', get_class($controller_object));
109   
110          // 0 vendor, 1 extension name, ...
111          if (!is_null($this->template) && isset($controller_dir[1]))
112          {
113              $controller_style_dir = 'ext/' . $controller_dir[0] . '/' . $controller_dir[1] . '/styles';
114   
115              if (is_dir($this->phpbb_root_path . $controller_style_dir))
116              {
117                  $this->template->set_style(array($controller_style_dir, 'styles'));
118              }
119          }
120   
121          return array($controller_object, $method);
122      }
123   
124      /**
125      * Dependencies should be specified in the service definition and can be
126      * then accessed in __construct(). Arguments are sent through the URL path
127      * and should match the parameters of the method you are using as your
128      * controller.
129      *
130      * @param \Symfony\Component\HttpFoundation\Request $request Symfony Request object
131      * @param mixed $controller A callable (controller class, method)
132      * @return array An array of arguments to pass to the controller
133      * @throws \phpbb\controller\exception
134      */
135      public function getArguments(Request $request, $controller)
136      {
137          // At this point, $controller contains the object and method name
138          list($object, $method) = $controller;
139          $mirror = new \ReflectionMethod($object, $method);
140   
141          $arguments = array();
142          $parameters = $mirror->getParameters();
143          $attributes = $request->attributes->all();
144          foreach ($parameters as $param)
145          {
146              if (array_key_exists($param->name, $attributes))
147              {
148                  if (is_string($attributes[$param->name]))
149                  {
150                      $value = $attributes[$param->name];
151                      $this->type_cast_helper->set_var($value, $attributes[$param->name], 'string', true, false);
152                      $arguments[] = $value;
153                  }
154                  else
155                  {
156                      $arguments[] = $attributes[$param->name];
157                  }
158              }
159              else if ($param->getClass() && $param->getClass()->isInstance($request))
160              {
161                  $arguments[] = $request;
162              }
163              else if ($param->isDefaultValueAvailable())
164              {
165                  $arguments[] = $param->getDefaultValue();
166              }
167              else
168              {
169                  throw new \phpbb\controller\exception($this->user->lang('CONTROLLER_ARGUMENT_VALUE_MISSING', $param->getPosition() + 1, get_class($object) . ':' . $method, $param->name));
170              }
171          }
172   
173          return $arguments;
174      }
175  }
176