1: <?php
2: /**
3: * This file is part of the Autarky package.
4: *
5: * (c) Andreas Lutro <anlutro@gmail.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:
11: namespace Autarky\Routing;
12:
13: use Closure;
14: use Symfony\Component\HttpFoundation\Request;
15:
16: /**
17: * Interface for routers that the framework can utilize.
18: */
19: interface RouterInterface
20: {
21: /**
22: * Dispatch a request in the router.
23: *
24: * @param \Symfony\Component\HttpFoundation\Request $request
25: *
26: * @return \Symfony\Component\HttpFoundation\Response
27: */
28: public function dispatch(Request $request);
29:
30: /**
31: * Add a route to the router.
32: *
33: * @param string|array $method HTTP methods the route should respond to
34: * @param string $path Relative URL the route should respond to. Parameters wrapped in {}
35: * @param string $handler string of "class:method" or "global_function"
36: * @param string $name Route name (optional)
37: */
38: public function addRoute($method, $path, $handler, $name = null);
39:
40: /**
41: * Given a route name, get the route object.
42: *
43: * @param string $name
44: *
45: * @return \Autarky\Routing\Route
46: *
47: * @throws \InvalidArgumentException if route with the name does not exist
48: */
49: public function getRoute($name);
50:
51: /**
52: * Get the route matched to the current request.
53: *
54: * @return \Autarky\Routing\Route
55: */
56: public function getCurrentRoute();
57:
58: /**
59: * Define a route group.
60: *
61: * @param array $flags Valid keys are 'before', 'after', 'prefix'
62: * @param \Closure $callback First argument is the router ($this)
63: *
64: * @return void
65: */
66: public function group(array $flags, Closure $callback);
67:
68: /**
69: * Mount an array config onto the routes.
70: *
71: * @param array $routes
72: * @param string $path
73: *
74: * @return void
75: */
76: public function mount(array $routes, $path = '/');
77: }
78: