├── .gitignore
├── .travis.yml
├── LICENSE
├── README.md
├── RoboFile.php
├── composer.json
├── src
├── Router.php
└── Router
│ ├── Input.php
│ └── Request.php
└── tests
├── RouterTest.php
├── bootstrap.php
└── environment
├── index.php
└── routes
├── container-calls.GET.php
├── foobar.GET.php
├── foobar.POST.php
├── index.GET.php
├── input-interface.GET.php
├── request-interface.GET.php
└── uri-vars-{name}-{age}.GET.php
/.gitignore:
--------------------------------------------------------------------------------
1 | vendor
2 | composer.lock
--------------------------------------------------------------------------------
/.travis.yml:
--------------------------------------------------------------------------------
1 | language: php
2 |
3 | php:
4 | - "5.5"
5 | - "5.4"
6 |
7 | install: "composer install"
8 |
9 | script: "./vendor/bin/robo test"
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2014 Brad Jones
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | > Looking for maintainers, I no longer do much if any PHP dev, I have moved on, mostly work in dotnet core, node.js & golang these days. If anyone is keen to take over these projects, get in touch - brad@bjc.id.au
2 |
3 | The Router Gear
4 | ================================================================================
5 | [](https://travis-ci.org/phpgearbox/router)
6 | [](https://packagist.org/packages/gears/router)
7 | [](https://packagist.org/packages/gears/router)
8 | [](https://packagist.org/packages/gears/router)
9 |
10 | **Laravel Router Standalone**
11 |
12 | Okay so by now hopefully you have heard of [Laravel](http://laravel.com/),
13 | the PHP framework that just makes things easy. So first things first full credit
14 | goes to [Taylor Otwell](https://github.com/taylorotwell) for the Router API.
15 |
16 | How to Install
17 | --------------------------------------------------------------------------------
18 | Installation via composer is easy:
19 |
20 | composer require gears/router:*
21 |
22 | How to Use
23 | --------------------------------------------------------------------------------
24 | In your *legacy* - non Laravel application.
25 | You can use the Laravel Router API like so:
26 |
27 | ```php
28 | // Make sure you have composer included
29 | require('vendor/autoload.php');
30 |
31 | // Install the gears router component
32 | $router = new Gears\Router();
33 | $router->routesPath = '/file/path/to/my/routes';
34 | $router->dispatch();
35 |
36 | // At this point execution will not continue. The router will either output
37 | // the results from a route and exit or it will output a 404 and then exit.
38 | ```
39 |
40 | The ```/file/path/to/my/routes``` can either be a routes php file.
41 | eg: ```/file/path/to/my/routes.php``` this file would look just like any
42 | *routes.php* file you would find in any other Laravel App.
43 |
44 | **OR**
45 |
46 | The path can be to a folder containing lots of route files. The files will be
47 | included automatically for you and added to the router. This is my prefered
48 | solution.
49 |
50 | > A little aside: In my Laravel Apps I place some code, similar to what is in
51 | > this Router that loops through a *routes* folder inside my *app* dir.
52 | > I place one route definition per file. I rarely use Controllers.
53 | > I name each route file like *search-{postcode}.GET.php* which contains:
54 | > ```Route::get('/search/{postcode}', function($postcode){});```
55 | > It makes for a very fast prototyping development life cycle.
56 |
57 | An Example Route
58 | --------------------------------------------------------------------------------
59 | So just like a Laravel Route, see: http://laravel.com/docs/routing
60 | Here is an example route file.
61 |
62 | ```php
63 | Route::get('/', function()
64 | {
65 | return 'I Am Groot';
66 | });
67 | ```
68 |
69 | **Class Alias**
70 | Behind the scenes when you call ```dispatch()``` we automatically create a new
71 | class alias called ```Route```, this sets up the normal public API you are used
72 | to. However if the class ```Route``` is already in existence.
73 | We also alias ourselves to ```Gears\Route```.
74 |
75 | The 404 Error
76 | --------------------------------------------------------------------------------
77 | Out of the box we have built in a simple and clean looking 404 error page.
78 | Credits go to: http://html5boilerplate.com/ Thank Guys.
79 |
80 | However if you wish to overide the 404 content the router returns.
81 | The instalation of the router might look like:
82 |
83 | ```php
84 | $router = new Gears\Router();
85 | $router->routesPath = '/file/path/to/my/routes';
86 | $router->notFound = 'Custom 404 HTML';
87 | $router->dispatch();
88 | ```
89 |
90 | **The 404 Exception**
91 | If you set the 404 parameter to a boolean value of *false*.
92 | Then we will simply re-throw the 404 exception, which is an instance of:
93 |
94 | ```
95 | Symfony\Component\HttpKernel\Exception\NotFoundHttpException
96 | ```
97 |
98 | You can then deal with this yourself. An example use case might be to have
99 | multiple routers. Which then could provide a HMVC type setup.
100 |
101 | Exit On Complete
102 | --------------------------------------------------------------------------------
103 | For most setups you will probably want the execution of PHP to stop after the
104 | router has done it's thing and sent the response. However if for whatever
105 | reason you don't want this, perhaps some sort of output buffering or something.
106 | The instalation of the router might look like:
107 |
108 | ```php
109 | $router = new Gears\Router();
110 | $router->routesPath = '/file/path/to/my/routes';
111 | $router->exitOnComplete = false;
112 | $router->dispatch();
113 | ```
114 |
115 | So now for the why?
116 | --------------------------------------------------------------------------------
117 | While laravel is so awesomely cool and great. If you want to pull a feature out
118 | and use it in another project it can become difficult. Firstly you have to have
119 | an innate understanding of the [IoC Container](http://laravel.com/docs/ioc).
120 |
121 | You then find that this class needs that class which then requires some other
122 | config variable that is normally present in the IoC when run inside a normal
123 | Laravel App but in your case you haven't defined it and don't really want
124 | to define that value because it makes no sense in your lets say *legacy*
125 | application.
126 |
127 | Perfect example is when I tried to pull the session API out to use in wordpress.
128 | It wanted to know about a ```booted``` method, which I think comes from
129 | ```Illuminate\Foundation\Application```. At this point in time I already had to
130 | add various other things into the IoC to make it happy and it was the last straw
131 | that broke the camels back, I chucked a coders tantrum, walked to the fridge,
132 | grabbed another Redbull and sat back down with a new approach.
133 |
134 | The result is this project.
135 |
136 | --------------------------------------------------------------------------------
137 | Developed by Brad Jones - brad@bjc.id.au
138 |
--------------------------------------------------------------------------------
/RoboFile.php:
--------------------------------------------------------------------------------
1 | > \_\ \ ___/ / __ \| | \/ | ( <_> > <
7 | // |____| |___| / __/ \______ /\___ >____ /__| |______ /\____/__/\_ \
8 | // \/|__| \/ \/ \/ \/ \/
9 | // -----------------------------------------------------------------------------
10 | // Designed and Developed by Brad Jones
11 | // -----------------------------------------------------------------------------
12 | ////////////////////////////////////////////////////////////////////////////////
13 |
14 | class RoboFile extends Robo\Tasks
15 | {
16 | /**
17 | * Property: serverPort
18 | * =========================================================================
19 | * The port the built in PHP server will run on for our acceptance testing.
20 | */
21 | public static $serverPort = 8000;
22 |
23 | /**
24 | * Method: test
25 | * =========================================================================
26 | * This will run our unit / acceptance testing. All the *gears* within
27 | * the **PhpGearBox** utlise PhpUnit as the basis for our testing with the
28 | * addition of the built in PHP Web Server, making the acceptance tests
29 | * almost as portable as standard unit tests.
30 | *
31 | * Just run: ```php ./vendor/bin/robo test```
32 | *
33 | * Parameters:
34 | * -------------------------------------------------------------------------
35 | * n/a
36 | *
37 | * Returns:
38 | * -------------------------------------------------------------------------
39 | * void
40 | */
41 | public function test()
42 | {
43 | $this->taskServer(self::$serverPort)
44 | ->dir('./tests/environment')
45 | ->background(true)
46 | ->run();
47 |
48 | exit($this->taskPHPUnit()->bootstrap('./tests/bootstrap.php')->arg('./tests')->run()->getExitCode());
49 | }
50 | }
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "gears/router",
3 | "description": "Laravel Router Standalone",
4 | "homepage": "https://github.com/phpgearbox/router",
5 | "keywords": ["laravel", "router", "standalone"],
6 | "license": "MIT",
7 | "autoload":
8 | {
9 | "psr-4":
10 | {
11 | "Gears\\": "src"
12 | }
13 | },
14 | "require":
15 | {
16 | "gears/di":"*",
17 | "illuminate/routing": "4.*",
18 | "illuminate/events": "4.*"
19 | },
20 | "require-dev":
21 | {
22 | "phpunit/phpunit": "4.*",
23 | "codegyre/robo": "*",
24 | "guzzlehttp/guzzle": "4.*"
25 | }
26 | }
--------------------------------------------------------------------------------
/src/Router.php:
--------------------------------------------------------------------------------
1 | > \_\ \ ___/ / __ \| | \/ | ( <_> > <
7 | // |____| |___| / __/ \______ /\___ >____ /__| |______ /\____/__/\_ \
8 | // \/|__| \/ \/ \/ \/ \/
9 | // -----------------------------------------------------------------------------
10 | // Designed and Developed by Brad Jones
11 | // -----------------------------------------------------------------------------
12 | ////////////////////////////////////////////////////////////////////////////////
13 |
14 | use RuntimeException;
15 | use Gears\Di\Container;
16 | use Illuminate\Events\Dispatcher;
17 | use Gears\Router\Request;
18 | use Illuminate\Routing\Router as LaravelRouter;
19 | use Symfony\Component\Finder\Finder;
20 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
21 |
22 | class Router extends Container
23 | {
24 | /**
25 | * Property: routesPath
26 | * =========================================================================
27 | * This is the file path to where our route file or files are stored.
28 | */
29 | protected $injectRoutesPath;
30 |
31 | /**
32 | * Property: notFound
33 | * =========================================================================
34 | * If this is set we will use this as the 404 response.
35 | * If nothing is supplied we output a nice looking default 404 page.
36 | * Credits: http://html5boilerplate.com/
37 | */
38 | protected $injectNotFound;
39 |
40 | /**
41 | * Property: exitOnComplete
42 | * =========================================================================
43 | * When set to true (the default) we will exit the current PHP process after
44 | * sending the response. This ensures that no other output can mess things
45 | * up. However some setups may require the opposite.
46 | */
47 | protected $injectExitOnComplete;
48 |
49 | /**
50 | * Property: dispatcher
51 | * =========================================================================
52 | * An instance of ```Illuminate\Events\Dispatcher```.
53 | */
54 | protected $injectDispatcher;
55 |
56 | /**
57 | * Property: finder
58 | * =========================================================================
59 | * An instance of ```Symfony\Component\Finder\Finder```.
60 | */
61 | protected $injectFinder;
62 |
63 | /**
64 | * Property: request
65 | * =========================================================================
66 | * An instance of ```Illuminate\Http\Request```.
67 | */
68 | protected $injectRequest;
69 |
70 | /**
71 | * Property: laravelRouter
72 | * =========================================================================
73 | * An instance of ```Illuminate\Routing\Router```.
74 | */
75 | protected $injectLaravelRouter;
76 |
77 | /**
78 | * Property: router
79 | * =========================================================================
80 | * This is where we statically store a copy of the LaravelRouter
81 | * after the container has been installed.
82 | */
83 | private static $router;
84 |
85 | /**
86 | * Method: setDefaults
87 | * =========================================================================
88 | * This is where we set all our defaults. If you need to customise this
89 | * container this is a good place to look to see what can be configured
90 | * and how to configure it.
91 | *
92 | * Parameters:
93 | * -------------------------------------------------------------------------
94 | * n/a
95 | *
96 | * Returns:
97 | * -------------------------------------------------------------------------
98 | * void
99 | */
100 | protected function setDefaults()
101 | {
102 | $this->exitOnComplete = true;
103 |
104 | $this->dispatcher = function()
105 | {
106 | return new Dispatcher;
107 | };
108 |
109 | $this->finder = $this->factory(function()
110 | {
111 | return new Finder;
112 | });
113 |
114 | $this->request = function()
115 | {
116 | return Request::createFromGlobals();
117 | };
118 |
119 | $this->laravelRouter = function()
120 | {
121 | return new LaravelRouter($this->dispatcher);
122 | };
123 | }
124 |
125 | /**
126 | * Method: install
127 | * =========================================================================
128 | * Once the router has been configured, simply run this method and we will
129 | * resolve the router from the container. Setup some class alias's,
130 | * add the routes and finally dispatch the underlying router.
131 | *
132 | * Parameters:
133 | * -------------------------------------------------------------------------
134 | * n/a
135 | *
136 | * Returns:
137 | * -------------------------------------------------------------------------
138 | * If not set to exit we will return ```Illuminate\Http\Response```
139 | */
140 | public function install()
141 | {
142 | // Resolve the router from the container
143 | self::$router = $this->laravelRouter;
144 |
145 | // Alias ourselves
146 | if (!class_exists('\Route'))
147 | {
148 | class_alias('\Gears\Router', '\Route');
149 | }
150 |
151 | if (!class_exists('\Gears\Route'))
152 | {
153 | class_alias('\Gears\Router', '\Gears\Route');
154 | }
155 |
156 | if (!class_exists('\Request'))
157 | {
158 | class_alias('\Gears\Router\Request', '\Request');
159 | }
160 |
161 | if (!class_exists('\Input'))
162 | {
163 | class_alias('\Gears\Router\Input', '\Input');
164 | }
165 |
166 | // Check if the path is a file or dir
167 | if (is_dir($this->routesPath))
168 | {
169 | // Loop through all our route files.
170 | foreach ($this->finder->files()->in($this->routesPath)->sortByName() as $file)
171 | {
172 | // Load the file
173 | require($file->getRealpath());
174 | }
175 | }
176 | else
177 | {
178 | // Load the single file
179 | require($this->routesPath);
180 | }
181 |
182 | /*
183 | * Now that we have looped through all our routes we can reset the
184 | * static router property. We do this so that further static calls
185 | * to this class will fail.
186 | *
187 | * We want to avoid this situation:
188 | *
189 | * ```php
190 | * $router1 = new Gears\Router();
191 | * $router1->install();
192 | *
193 | * $router2 = new Gears\Router();
194 | *
195 | * // this route would not be added to router2 but to router1
196 | * Route::get('/', function(){ return 'foo'; });
197 | * ```
198 | */
199 | $router = self::$router;
200 | self::$router = null;
201 |
202 | try
203 | {
204 | // Run the router
205 | $response = $router->dispatch($this->request);
206 | }
207 | catch (NotFoundHttpException $e)
208 | {
209 | /*
210 | * If the 404 is explicitly set to the boolean value of false.
211 | * We re-throw the exception and make that the responsibility
212 | * of the caller.
213 | */
214 | if ($this->notFound === false) throw $e;
215 |
216 | // Output the 404 header
217 | header('HTTP/1.0 404 Not Found');
218 |
219 | // Output our 404 page
220 | if (!is_null($this->notFound))
221 | {
222 | echo $this->notFound;
223 | }
224 | else
225 | {
226 | echo
227 | '
228 |
229 |
230 |
231 |
232 | Page Not Found
233 |
234 |
246 |
247 |
248 | Page Not Found
249 | Sorry, but the page you were trying to view does not exist.
250 |
251 |
252 |
253 | ';
254 | }
255 |
256 | // If we output a 404 we will exit regardless of exitOnComplete
257 | exit;
258 | }
259 |
260 | // Send the response
261 | if ($this->exitOnComplete)
262 | {
263 | $response->send(); exit;
264 | }
265 |
266 | return $response;
267 | }
268 |
269 | /**
270 | * Method: dispatch
271 | * =========================================================================
272 | * This is just an alias of install as it makes slightly more sense to
273 | * dispatch the router than to install it.
274 | *
275 | * Parameters:
276 | * -------------------------------------------------------------------------
277 | * n/a
278 | *
279 | * Returns:
280 | * -------------------------------------------------------------------------
281 | * void
282 | */
283 | public function dispatch()
284 | {
285 | return $this->install();
286 | }
287 |
288 | /**
289 | * Method: __call
290 | * =========================================================================
291 | * Okay so this is the magic method that makes it possible to do this:
292 | *
293 | * Route::get('/', function(){ return 'Hello World!'; });
294 | *
295 | * For more info on how the laravel route api works, please see:
296 | * http://laravel.com/docs/routing
297 | *
298 | * > NOTE: Due to an odd PHP behaviour we are overriding the DI Containers
299 | * > __call method and no longer use the __callStatic method. See this
300 | * > stackoverflow link: http://stackoverflow.com/q/13232445
301 | *
302 | * Parameters:
303 | * -------------------------------------------------------------------------
304 | * - $name: The name of the method to call.
305 | * - $args: The argumnent array that is given to us.
306 | *
307 | * Returns:
308 | * -------------------------------------------------------------------------
309 | * mixed
310 | *
311 | * Throws:
312 | * -------------------------------------------------------------------------
313 | * - RuntimeException: When the router has not been installed.
314 | */
315 | public function __call($name, $args)
316 | {
317 | if ($this->offsetExists($name))
318 | {
319 | return parent::__call($name, $args);
320 | }
321 | else
322 | {
323 | if (empty(self::$router))
324 | {
325 | throw new RuntimeException('You need to install a router first!');
326 | }
327 |
328 | return call_user_func_array([self::$router, $name], $args);
329 | }
330 | }
331 | }
--------------------------------------------------------------------------------
/src/Router/Input.php:
--------------------------------------------------------------------------------
1 | > \_\ \ ___/ / __ \| | \/ | ( <_> > <
7 | // |____| |___| / __/ \______ /\___ >____ /__| |______ /\____/__/\_ \
8 | // \/|__| \/ \/ \/ \/ \/
9 | // -----------------------------------------------------------------------------
10 | // Designed and Developed by Brad Jones
11 | // -----------------------------------------------------------------------------
12 | ////////////////////////////////////////////////////////////////////////////////
13 |
14 | use Gears\Router\Request;
15 |
16 | class Input
17 | {
18 | public static function get($key = null, $default = null)
19 | {
20 | return Request::input($key, $default);
21 | }
22 |
23 | public static function __callStatic($name, $args)
24 | {
25 | return call_user_func_array([Request::class, $name], $args);
26 | }
27 | }
--------------------------------------------------------------------------------
/src/Router/Request.php:
--------------------------------------------------------------------------------
1 | > \_\ \ ___/ / __ \| | \/ | ( <_> > <
7 | // |____| |___| / __/ \______ /\___ >____ /__| |______ /\____/__/\_ \
8 | // \/|__| \/ \/ \/ \/ \/
9 | // -----------------------------------------------------------------------------
10 | // Designed and Developed by Brad Jones
11 | // -----------------------------------------------------------------------------
12 | ////////////////////////////////////////////////////////////////////////////////
13 |
14 | use RuntimeException;
15 | use Illuminate\Http\Request as LaravelRequest;
16 |
17 | class Request
18 | {
19 | private static $instance;
20 |
21 | public static function createFromGlobals()
22 | {
23 | static::$instance = LaravelRequest::createFromGlobals();
24 |
25 | return static::$instance;
26 | }
27 |
28 | public static function __callStatic($name, $args)
29 | {
30 | if (empty(static::$instance))
31 | {
32 | throw new RuntimeException('You need to install a router first!');
33 | }
34 |
35 | return call_user_func_array([self::$instance, $name], $args);
36 | }
37 | }
--------------------------------------------------------------------------------
/tests/RouterTest.php:
--------------------------------------------------------------------------------
1 | > \_\ \ ___/ / __ \| | \/ | ( <_> > <
7 | // |____| |___| / __/ \______ /\___ >____ /__| |______ /\____/__/\_ \
8 | // \/|__| \/ \/ \/ \/ \/
9 | // -----------------------------------------------------------------------------
10 | // Designed and Developed by Brad Jones
11 | // -----------------------------------------------------------------------------
12 | ////////////////////////////////////////////////////////////////////////////////
13 |
14 | class RouterTest extends PHPUnit_Framework_TestCase
15 | {
16 | protected $http;
17 |
18 | protected function setUp()
19 | {
20 | // Get a new guzzle client
21 | $this->http = GuzzleTester();
22 | }
23 |
24 | public function testDefaultRoute()
25 | {
26 | $this->assertEquals('Hello World', $this->http->get()->getBody());
27 | }
28 |
29 | public function test404Response()
30 | {
31 | try
32 | {
33 | $this->http->get('/404');
34 | }
35 | catch (GuzzleHttp\Exception\ClientException $e)
36 | {
37 | return;
38 | }
39 |
40 | $this->fail('404 Exception Not Thrown');
41 | }
42 |
43 | public function testRoutesWithSameNameButDifferentVerbs()
44 | {
45 | $this->assertEquals('FOOBAR GET', $this->http->get('/foobar')->getBody());
46 | $this->assertEquals('FOOBAR POST', $this->http->post('/foobar')->getBody());
47 | }
48 |
49 | public function testUriVars()
50 | {
51 | $name = 'Brad Jones';
52 | $age = @date('Y') - 1988;
53 |
54 | $this->assertEquals
55 | (
56 | 'Hello '.$name.' of '.$age.' years old.',
57 | $this->http->get('/uri/vars/'.$name.'/'.$age)->getBody()
58 | );
59 | }
60 |
61 | public function testContainerCalls()
62 | {
63 | $this->assertEquals('bar', $this->http->get('/container-calls?foo=bar')->getBody());
64 | }
65 |
66 | public function testRequestInterface()
67 | {
68 | $this->assertEquals('bar', $this->http->get('/request-interface?foo=bar')->getBody());
69 | }
70 |
71 | public function testInputInterface()
72 | {
73 | $this->assertEquals('bar', $this->http->get('/input-interface?foo=bar')->getBody());
74 | }
75 | }
--------------------------------------------------------------------------------
/tests/bootstrap.php:
--------------------------------------------------------------------------------
1 | > \_\ \ ___/ / __ \| | \/ | ( <_> > <
7 | // |____| |___| / __/ \______ /\___ >____ /__| |______ /\____/__/\_ \
8 | // \/|__| \/ \/ \/ \/ \/
9 | // -----------------------------------------------------------------------------
10 | // Designed and Developed by Brad Jones
11 | // -----------------------------------------------------------------------------
12 | ////////////////////////////////////////////////////////////////////////////////
13 |
14 | /*
15 | * Include the robo file so we know what port
16 | * the built in php server is running on.
17 | */
18 | require(__DIR__.'/../RoboFile.php');
19 |
20 | /*
21 | * Create the base Guzzle Client we will use for all our acceptance testing.
22 | * NOTE: We return a new client each time so that we don't have any chance of
23 | * cross contamination.
24 | */
25 | function GuzzleTester()
26 | {
27 | return new GuzzleHttp\Client
28 | ([
29 | 'base_url' => 'http://127.0.0.1:'.RoboFile::$serverPort,
30 | 'defaults' => ['cookies' => true]
31 | ]);
32 | }
--------------------------------------------------------------------------------
/tests/environment/index.php:
--------------------------------------------------------------------------------
1 | > \_\ \ ___/ / __ \| | \/ | ( <_> > <
7 | // |____| |___| / __/ \______ /\___ >____ /__| |______ /\____/__/\_ \
8 | // \/|__| \/ \/ \/ \/ \/
9 | // -----------------------------------------------------------------------------
10 | // Designed and Developed by Brad Jones
11 | // -----------------------------------------------------------------------------
12 | ////////////////////////////////////////////////////////////////////////////////
13 |
14 | // Load the composer autoloader
15 | require('../../vendor/autoload.php');
16 |
17 | // Install the router
18 | $router = new Gears\Router();
19 | $router->routesPath = './routes';
20 | $router->install();
--------------------------------------------------------------------------------
/tests/environment/routes/container-calls.GET.php:
--------------------------------------------------------------------------------
1 | > \_\ \ ___/ / __ \| | \/ | ( <_> > <
7 | // |____| |___| / __/ \______ /\___ >____ /__| |______ /\____/__/\_ \
8 | // \/|__| \/ \/ \/ \/ \/
9 | // -----------------------------------------------------------------------------
10 | // Designed and Developed by Brad Jones
11 | // -----------------------------------------------------------------------------
12 | ////////////////////////////////////////////////////////////////////////////////
13 |
14 | Route::get('/container-calls', function()
15 | {
16 | return Route::request()->get('foo');
17 | });
--------------------------------------------------------------------------------
/tests/environment/routes/foobar.GET.php:
--------------------------------------------------------------------------------
1 | > \_\ \ ___/ / __ \| | \/ | ( <_> > <
7 | // |____| |___| / __/ \______ /\___ >____ /__| |______ /\____/__/\_ \
8 | // \/|__| \/ \/ \/ \/ \/
9 | // -----------------------------------------------------------------------------
10 | // Designed and Developed by Brad Jones
11 | // -----------------------------------------------------------------------------
12 | ////////////////////////////////////////////////////////////////////////////////
13 |
14 | Route::get('/foobar', function()
15 | {
16 | // This is a GET specific route
17 | return 'FOOBAR GET';
18 | });
--------------------------------------------------------------------------------
/tests/environment/routes/foobar.POST.php:
--------------------------------------------------------------------------------
1 | > \_\ \ ___/ / __ \| | \/ | ( <_> > <
7 | // |____| |___| / __/ \______ /\___ >____ /__| |______ /\____/__/\_ \
8 | // \/|__| \/ \/ \/ \/ \/
9 | // -----------------------------------------------------------------------------
10 | // Designed and Developed by Brad Jones
11 | // -----------------------------------------------------------------------------
12 | ////////////////////////////////////////////////////////////////////////////////
13 |
14 | Route::post('/foobar', function()
15 | {
16 | // This is a POST specific route
17 | return 'FOOBAR POST';
18 | });
--------------------------------------------------------------------------------
/tests/environment/routes/index.GET.php:
--------------------------------------------------------------------------------
1 | > \_\ \ ___/ / __ \| | \/ | ( <_> > <
7 | // |____| |___| / __/ \______ /\___ >____ /__| |______ /\____/__/\_ \
8 | // \/|__| \/ \/ \/ \/ \/
9 | // -----------------------------------------------------------------------------
10 | // Designed and Developed by Brad Jones
11 | // -----------------------------------------------------------------------------
12 | ////////////////////////////////////////////////////////////////////////////////
13 |
14 | Route::get('/', function()
15 | {
16 | // The simplest route ever
17 | return 'Hello World';
18 | });
--------------------------------------------------------------------------------
/tests/environment/routes/input-interface.GET.php:
--------------------------------------------------------------------------------
1 | > \_\ \ ___/ / __ \| | \/ | ( <_> > <
7 | // |____| |___| / __/ \______ /\___ >____ /__| |______ /\____/__/\_ \
8 | // \/|__| \/ \/ \/ \/ \/
9 | // -----------------------------------------------------------------------------
10 | // Designed and Developed by Brad Jones
11 | // -----------------------------------------------------------------------------
12 | ////////////////////////////////////////////////////////////////////////////////
13 |
14 | Route::get('/input-interface', function()
15 | {
16 | return Input::get('foo');
17 | });
--------------------------------------------------------------------------------
/tests/environment/routes/request-interface.GET.php:
--------------------------------------------------------------------------------
1 | > \_\ \ ___/ / __ \| | \/ | ( <_> > <
7 | // |____| |___| / __/ \______ /\___ >____ /__| |______ /\____/__/\_ \
8 | // \/|__| \/ \/ \/ \/ \/
9 | // -----------------------------------------------------------------------------
10 | // Designed and Developed by Brad Jones
11 | // -----------------------------------------------------------------------------
12 | ////////////////////////////////////////////////////////////////////////////////
13 |
14 | Route::get('/request-interface', function()
15 | {
16 | return Request::get('foo');
17 | });
--------------------------------------------------------------------------------
/tests/environment/routes/uri-vars-{name}-{age}.GET.php:
--------------------------------------------------------------------------------
1 | > \_\ \ ___/ / __ \| | \/ | ( <_> > <
7 | // |____| |___| / __/ \______ /\___ >____ /__| |______ /\____/__/\_ \
8 | // \/|__| \/ \/ \/ \/ \/
9 | // -----------------------------------------------------------------------------
10 | // Designed and Developed by Brad Jones
11 | // -----------------------------------------------------------------------------
12 | ////////////////////////////////////////////////////////////////////////////////
13 |
14 | Route::get('/uri/vars/{name}/{age}', function($name, $age)
15 | {
16 | // Example of how to use uri vars
17 | return 'Hello '.$name.' of '.$age.' years old.';
18 | });
--------------------------------------------------------------------------------