예제 #1
0
 /**
  * createMap
  *
  * @param RouteCollectionInterface $routes
  *
  * @return array
  */
 private function createMap(RouteCollectionInterface $routes)
 {
     $i = 0;
     $m = [];
     $rpl = sprintf(self::NGRP_RPLC, Ps::EXP_DELIM);
     $expr = [];
     $pfx = 'r' . time();
     $expr['prefix'] = $pfx;
     foreach ($routes->all() as $name => $route) {
         foreach ($route->getMethods() as $method) {
             $m[$method][$name] = $route;
         }
     }
     foreach ($m as $mn => $rts) {
         $mn = strtolower($mn);
         $expr[$mn]['map'] = [];
         $regex = [];
         foreach ($rts as $rn => $rt) {
             $ctx = $rt->getContext();
             $index = $pfx . '_' . $this->replaceRouteName($rn, $i);
             $ctxRegex = preg_replace($rpl, '$1r' . (string) $i . '_$2>', $ctx->getRegex(true));
             $regex[] = sprintf('(?P<%s>%s)', $index, $ctxRegex);
             $expr[$mn]['map'][$index] = [$i, $rn, 'r' . $i . '_'];
             $i++;
         }
         $i = 0;
         $expr[$mn]['regex'] = sprintf('%1$s(?:^' . join('|', $regex) . ')$%1$sx', Ps::EXP_DELIM);
     }
     return $expr;
 }
예제 #2
0
 /**
  * createMaps
  *
  * @param RouteCollectionInterface $routes
  *
  * @return void
  */
 private function createMaps(RouteCollectionInterface $routes)
 {
     foreach ($routes->all() as $name => $route) {
         foreach ($route->getMethods() as $method) {
             $this->mMap[$method][] = $name;
         }
         foreach ($route->getSchemes() as $scheme) {
             $this->scMap[$scheme][] = $name;
         }
         $this->spMap[$route->getContext()->getStaticPath()][] = $name;
     }
 }