match() public method

Register a new route with the given verbs.
public match ( array | string $methods, string $uri, Closure | array | string | null $action = null ) : Illuminate\Routing\Route
$methods array | string
$uri string
$action Closure | array | string | null
return Illuminate\Routing\Route
Example #1
0
 /**
  * Register routes from an array
  *
  * @param array $data
  *
  * @return void
  */
 protected function registerRoutes(array $data)
 {
     foreach ($data as $method => $routes) {
         if (in_array($method, $this->verbs)) {
             foreach ($routes as $uri => $action) {
                 $this->router->match(array($method), $uri, $action);
             }
         }
     }
 }
 function let(Repository $config, Filesystem $fs, OutputInterface $output)
 {
     $config_file = (include __DIR__ . '/../../src/config/path2api.php');
     $this->tempFile = $config_file['file'];
     $config->get('path2api')->willReturn($config_file);
     $router = new Router(new Dispatcher());
     $router->get('/api', ['uses' => 'Stubs\\Pomek\\Path2API\\Controller@homepage']);
     $router->post('/api/contact/{email}', ['uses' => 'Stubs\\Pomek\\Path2API\\Controller@contact']);
     $router->match(['GET', 'POST'], '/api/test/{id}', function ($id) {
         return $id;
     });
     $this->beConstructedWith($router, $config, $fs);
     $this->setOutput($output);
 }
 /**
  * Make route from route data and register it into router
  *
  * @param array $route_data
  * @param string $controller
  * @return Illuminate\Routing\Route
  */
 protected function makeAndRegisterRoute($controller, ReflectionMethod $method, array $route_data)
 {
     $uses = $controller . '@' . $method->getName();
     $methods = $route_data['methods'];
     $uri = $route_data['uri'];
     $action = ['uses' => $uses];
     if (!empty($route_data['middleware'])) {
         $action['middleware'] = $route_data['middleware'];
     }
     if (!empty($route_data['name'])) {
         $action['as'] = $route_data['name'];
     }
     $route = $this->router->match($methods, $uri, $action);
     foreach ($route_data['conditions'] as $param => $regex) {
         $route->where($param, $regex);
     }
     // Laravel Route doesn't provide method for get route conditions,
     // so we need to declare new attribute for generating(transforming) purpose
     $route->conditions = $route_data['conditions'];
     $route->description = $route_data['description'];
     return $route;
 }
Example #4
0
 /**
  * Register a new route with the given verbs.
  *
  * @param array|string $methods
  * @param string $uri
  * @param \Closure|array|string $action
  * @return \Illuminate\Routing\Route 
  * @static 
  */
 public static function match($methods, $uri, $action)
 {
     return \Illuminate\Routing\Router::match($methods, $uri, $action);
 }
Example #5
0
 /**
  * Register a new route with the given verbs.
  *
  * @param  array|string           $methods
  * @param  string                 $uri
  * @param  \Closure|array|string  $action
  *
  * @return \Illuminate\Routing\Route|void
  */
 public function match($methods, $uri, $action)
 {
     return $this->router->match($methods, $uri, $action);
 }
 /**
  * Inject routes into the provided router.
  *
  * @param Router $router
  * @return Router
  */
 public function inject(Router $router)
 {
     $router->group(Arr::filterNullValues(['middleware' => $this->middleware, 'prefix' => $this->prefix]), function (Router $router) {
         Std::each(function (ResourceMethod $method) use($router) {
             $handler = vsprintf('%s@%s', [$this->controller, $method->getMethod()]);
             $router->match([$method->getVerb()], $method->getPath(), $handler);
         }, $this->methods);
     });
     return $router;
 }
 /**
  * Add the update method for a resourceful route.
  *
  * @param  string  $name
  * @param  string  $base
  * @param  string  $controller
  * @param  array   $options
  * @return void
  */
 protected function addResourceUpdate($name, $base, $controller, $options)
 {
     $uri = $this->getResourceUri($name) . '/{' . $base . '}';
     $action = $this->getResourceAction($name, $controller, 'update', $options);
     return $this->router->match(['PUT', 'PATCH'], $uri, $action);
 }
 /**
  * Register a new route with the given verbs.
  *
  * @param  array|string  $methods
  * @param  string  $uri
  * @param  \Closure|array|string|null  $action
  * @return \Illuminate\Routing\Route
  */
 public function match($methods, $uri, $action = null)
 {
     return $this->router->match($methods, $uri, $this->compileAction($action));
 }
 /**
  * Expose symfonys routes to Laravel.
  *
  * @param Router $router
  */
 public function addSymfonyRoutes(Router $router)
 {
     foreach ($this->routesFromSymfony as $route) {
         $router->match($route['methods'], $route['path'], $route['action']);
     }
 }