Nenhuma descrição

Herton 2243235223 Fixing minor issues 4 anos atrás
Controllers 2243235223 Fixing minor issues 4 anos atrás
tests 4fed480dc2 Basic structure, missing final steps to handle request 4 anos atrás
.gitignore d749025e73 Basic setup of the example of usage for the new package 4 anos atrás
Application.php 32cffea3aa Fixed methods and got to a basic working version 4 anos atrás
Dockerfile d749025e73 Basic setup of the example of usage for the new package 4 anos atrás
Helpers.php 4fed480dc2 Basic structure, missing final steps to handle request 4 anos atrás
Resource.php 9acb58ba16 Adding methods to the other controllers to test and some clean up 4 anos atrás
Route.php 2243235223 Fixing minor issues 4 anos atrás
composer.json 4fed480dc2 Basic structure, missing final steps to handle request 4 anos atrás
docker-compose.yml d749025e73 Basic setup of the example of usage for the new package 4 anos atrás
handle.php 32cffea3aa Fixed methods and got to a basic working version 4 anos atrás
index.php 4fed480dc2 Basic structure, missing final steps to handle request 4 anos atrás
readme.md d749025e73 Basic setup of the example of usage for the new package 4 anos atrás
routes.php 32cffea3aa Fixed methods and got to a basic working version 4 anos atrás
serve.sh d749025e73 Basic setup of the example of usage for the new package 4 anos atrás

readme.md

Wild Alaskan Company Routing Assignment

You are familar with the Laravel router code no doubt. What we want is to implement from scratch, a simplified version of Laravel's "resource router".

https://laravel.com/docs/5.8/controllers#resource-controllers

Step 1

Given a routes file say routes.php

We want to be able to declare resources routes. Resource routes will automatically pick up the HTTP verb from the web request and execute the corresponding functions in a controller that matches the route name.

Step 2 Detect and support HTTP verbs automatically

For all supported HTTP verbs, implement the corresponding execution of the controller method.

For example a verb of GET will execute the controller method show. Here is a table of the all the verbs we want to support. If a controller or method does not exist, then throw an exception.

Verb Method
get (with parameter) show
get / index
post store
put update
delete destroy

Here is an example of a routes.php file for a hypothetical blog application

Route::resource('posts');
Route::resource('users.posts');
Route::resource('categories.posts');

For simplicity, the controller will have to be named based on the route parameter. So for the above example we expect these controllers.

PostsController.php
UsersPostsController.php
CategoriesPostsController.php

We will not support custom controller names.

Furthermore, the parameters in the route url should be passed to the controller methods.

In the above example a url call of GET /posts/123 should execute the method show($id) where $id is 123

Another example: a url call of GET /users/bob/posts/999 should execute show($name, $id) where $name should evaluate to bob and $id should evaluate to 999

There is no need to handle any query strings or the actual request payload in a post or put. We only want to see the execution of the controller methods.

Bonus: package into a standalone composer library

Extra Bonus: Run this inside a docker container