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

RouteCollection.php

Zuletzt modifiziert: 09.10.2024, 12:58 - Dateigröße: 6.85 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\Routing;
 013   
 014  use Symfony\Component\Config\Resource\ResourceInterface;
 015   
 016  /**
 017   * A RouteCollection represents a set of Route instances.
 018   *
 019   * When adding a route at the end of the collection, an existing route
 020   * with the same name is removed first. So there can only be one route
 021   * with a given name.
 022   *
 023   * @author Fabien Potencier <fabien@symfony.com>
 024   * @author Tobias Schultze <http://tobion.de>
 025   *
 026   * @api
 027   */
 028  class RouteCollection implements \IteratorAggregate, \Countable
 029  {
 030      /**
 031       * @var Route[]
 032       */
 033      private $routes = array();
 034   
 035      /**
 036       * @var array
 037       */
 038      private $resources = array();
 039   
 040      public function __clone()
 041      {
 042          foreach ($this->routes as $name => $route) {
 043              $this->routes[$name] = clone $route;
 044          }
 045      }
 046   
 047      /**
 048       * Gets the current RouteCollection as an Iterator that includes all routes.
 049       *
 050       * It implements \IteratorAggregate.
 051       *
 052       * @see all()
 053       *
 054       * @return \ArrayIterator An \ArrayIterator object for iterating over routes
 055       */
 056      public function getIterator()
 057      {
 058          return new \ArrayIterator($this->routes);
 059      }
 060   
 061      /**
 062       * Gets the number of Routes in this collection.
 063       *
 064       * @return int The number of routes
 065       */
 066      public function count()
 067      {
 068          return count($this->routes);
 069      }
 070   
 071      /**
 072       * Adds a route.
 073       *
 074       * @param string $name  The route name
 075       * @param Route  $route A Route instance
 076       *
 077       * @api
 078       */
 079      public function add($name, Route $route)
 080      {
 081          unset($this->routes[$name]);
 082   
 083          $this->routes[$name] = $route;
 084      }
 085   
 086      /**
 087       * Returns all routes in this collection.
 088       *
 089       * @return Route[] An array of routes
 090       */
 091      public function all()
 092      {
 093          return $this->routes;
 094      }
 095   
 096      /**
 097       * Gets a route by name.
 098       *
 099       * @param string $name The route name
 100       *
 101       * @return Route|null A Route instance or null when not found
 102       */
 103      public function get($name)
 104      {
 105          return isset($this->routes[$name]) ? $this->routes[$name] : null;
 106      }
 107   
 108      /**
 109       * Removes a route or an array of routes by name from the collection
 110       *
 111       * @param string|array $name The route name or an array of route names
 112       */
 113      public function remove($name)
 114      {
 115          foreach ((array) $name as $n) {
 116              unset($this->routes[$n]);
 117          }
 118      }
 119   
 120      /**
 121       * Adds a route collection at the end of the current set by appending all
 122       * routes of the added collection.
 123       *
 124       * @param RouteCollection $collection      A RouteCollection instance
 125       *
 126       * @api
 127       */
 128      public function addCollection(RouteCollection $collection)
 129      {
 130          // we need to remove all routes with the same names first because just replacing them
 131          // would not place the new route at the end of the merged array
 132          foreach ($collection->all() as $name => $route) {
 133              unset($this->routes[$name]);
 134              $this->routes[$name] = $route;
 135          }
 136   
 137          $this->resources = array_merge($this->resources, $collection->getResources());
 138      }
 139   
 140      /**
 141       * Adds a prefix to the path of all child routes.
 142       *
 143       * @param string $prefix       An optional prefix to add before each pattern of the route collection
 144       * @param array  $defaults     An array of default values
 145       * @param array  $requirements An array of requirements
 146       *
 147       * @api
 148       */
 149      public function addPrefix($prefix, array $defaults = array(), array $requirements = array())
 150      {
 151          $prefix = trim(trim($prefix), '/');
 152   
 153          if ('' === $prefix) {
 154              return;
 155          }
 156   
 157          foreach ($this->routes as $route) {
 158              $route->setPath('/'.$prefix.$route->getPath());
 159              $route->addDefaults($defaults);
 160              $route->addRequirements($requirements);
 161          }
 162      }
 163   
 164      /**
 165       * Sets the host pattern on all routes.
 166       *
 167       * @param string $pattern      The pattern
 168       * @param array  $defaults     An array of default values
 169       * @param array  $requirements An array of requirements
 170       */
 171      public function setHost($pattern, array $defaults = array(), array $requirements = array())
 172      {
 173          foreach ($this->routes as $route) {
 174              $route->setHost($pattern);
 175              $route->addDefaults($defaults);
 176              $route->addRequirements($requirements);
 177          }
 178      }
 179   
 180      /**
 181       * Adds defaults to all routes.
 182       *
 183       * An existing default value under the same name in a route will be overridden.
 184       *
 185       * @param array $defaults An array of default values
 186       */
 187      public function addDefaults(array $defaults)
 188      {
 189          if ($defaults) {
 190              foreach ($this->routes as $route) {
 191                  $route->addDefaults($defaults);
 192              }
 193          }
 194      }
 195   
 196      /**
 197       * Adds requirements to all routes.
 198       *
 199       * An existing requirement under the same name in a route will be overridden.
 200       *
 201       * @param array $requirements An array of requirements
 202       */
 203      public function addRequirements(array $requirements)
 204      {
 205          if ($requirements) {
 206              foreach ($this->routes as $route) {
 207                  $route->addRequirements($requirements);
 208              }
 209          }
 210      }
 211   
 212      /**
 213       * Adds options to all routes.
 214       *
 215       * An existing option value under the same name in a route will be overridden.
 216       *
 217       * @param array $options An array of options
 218       */
 219      public function addOptions(array $options)
 220      {
 221          if ($options) {
 222              foreach ($this->routes as $route) {
 223                  $route->addOptions($options);
 224              }
 225          }
 226      }
 227   
 228      /**
 229       * Sets the schemes (e.g. 'https') all child routes are restricted to.
 230       *
 231       * @param string|array $schemes The scheme or an array of schemes
 232       */
 233      public function setSchemes($schemes)
 234      {
 235          foreach ($this->routes as $route) {
 236              $route->setSchemes($schemes);
 237          }
 238      }
 239   
 240      /**
 241       * Sets the HTTP methods (e.g. 'POST') all child routes are restricted to.
 242       *
 243       * @param string|array $methods The method or an array of methods
 244       */
 245      public function setMethods($methods)
 246      {
 247          foreach ($this->routes as $route) {
 248              $route->setMethods($methods);
 249          }
 250      }
 251   
 252      /**
 253       * Returns an array of resources loaded to build this collection.
 254       *
 255       * @return ResourceInterface[] An array of resources
 256       */
 257      public function getResources()
 258      {
 259          return array_unique($this->resources);
 260      }
 261   
 262      /**
 263       * Adds a resource for this collection.
 264       *
 265       * @param ResourceInterface $resource A resource instance
 266       */
 267      public function addResource(ResourceInterface $resource)
 268      {
 269          $this->resources[] = $resource;
 270      }
 271  }
 272