vendor/friendsofsymfony/rest-bundle/Routing/RestRouteCollection.php line 14

Open in your IDE?
  1. <?php
  2. /*
  3.  * This file is part of the FOSRestBundle package.
  4.  *
  5.  * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
  6.  *
  7.  * For the full copyright and license information, please view the LICENSE
  8.  * file that was distributed with this source code.
  9.  */
  10. namespace FOS\RestBundle\Routing;
  11. @trigger_error(sprintf('The %s\RestRouteCollection class is deprecated since FOSRestBundle 2.8.'__NAMESPACE__), E_USER_DEPRECATED);
  12. use Symfony\Component\Routing\RouteCollection;
  13. /**
  14.  * Restful route collection.
  15.  *
  16.  * @author Konstantin Kudryashov <ever.zet@gmail.com>
  17.  *
  18.  * @deprecated since 2.8
  19.  */
  20. class RestRouteCollection extends RouteCollection
  21. {
  22.     private $singularName;
  23.     /**
  24.      * @param string $name
  25.      */
  26.     public function setSingularName($name)
  27.     {
  28.         $this->singularName $name;
  29.     }
  30.     /**
  31.      * @return string
  32.      */
  33.     public function getSingularName()
  34.     {
  35.         return $this->singularName;
  36.     }
  37.     /**
  38.      * @param string $prefix
  39.      */
  40.     public function prependRouteControllersWithPrefix($prefix)
  41.     {
  42.         foreach (parent::all() as $route) {
  43.             $route->setDefault('_controller'$prefix.$route->getDefault('_controller'));
  44.         }
  45.     }
  46.     /**
  47.      * @param string $format
  48.      */
  49.     public function setDefaultFormat($format)
  50.     {
  51.         foreach (parent::all() as $route) {
  52.             // Set default format only if not set already (could be defined in annotation)
  53.             if (!$route->getDefault('_format')) {
  54.                 $route->setDefault('_format'$format);
  55.             }
  56.         }
  57.     }
  58.     /**
  59.      * Returns routes sorted by custom HTTP methods first.
  60.      *
  61.      * @return array
  62.      */
  63.     public function all()
  64.     {
  65.         $regex '/'.
  66.             '(_|^)'.
  67.             '(get|post|put|delete|patch|head|options|mkcol|propfind|proppatch|lock|unlock|move|copy|link|unlink)_'// allowed http methods
  68.             '/i';
  69.         $routes parent::all();
  70.         $customMethodRoutes = [];
  71.         foreach ($routes as $routeName => $route) {
  72.             if (!preg_match($regex$routeName)) {
  73.                 $customMethodRoutes[$routeName] = $route;
  74.                 unset($routes[$routeName]);
  75.             }
  76.         }
  77.         return $customMethodRoutes $routes;
  78.     }
  79. }