diff --git a/composer.json b/composer.json index e9db233..815601e 100644 --- a/composer.json +++ b/composer.json @@ -10,23 +10,23 @@ "routing", "middleware" ], - "homepage": "http://www.ingeniasoftawre.com.ve", + "homepage": "https://ingenia.me", "require-dev": { "php": ">=5.6.0" }, - "license": "GPL-3.0", + "license": "MIT", "authors": [ { "name": "Anderson Salas", - "email": "me@andersonsalas.com.ve", - "homepage": "http://www.andersonsalas.com.ve", + "email": "anderson@ingenia.me", + "homepage": "https://ingenia.me", "role" : "Lead developer" } ], "support": { - "email": "me@andersonsalas.com.ve" + "email": "anderson@ingenia.me" }, - "minimum-stability": "dev", + "minimum-stability": "stable", "autoload": { "psr-4": { "Luthier\\": "src/" diff --git a/composer.lock b/composer.lock new file mode 100644 index 0000000..2130035 --- /dev/null +++ b/composer.lock @@ -0,0 +1,21 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", + "This file is @generated automatically" + ], + "content-hash": "e9911f4d458cefa15c4819e02684293a", + "packages": [], + "packages-dev": [], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": [], + "prefer-stable": false, + "prefer-lowest": false, + "platform": { + "php": ">=5.6.0" + }, + "platform-dev": { + "php": ">=5.6.0" + } +} diff --git a/readme.md b/readme.md index c8281e2..38e29de 100644 --- a/readme.md +++ b/readme.md @@ -4,28 +4,29 @@ [![Total Downloads](https://poser.pugx.org/luthier/luthier/downloads)](https://packagist.org/packages/luthier/luthier) [![Latest Unstable Version](https://poser.pugx.org/luthier/luthier/v/unstable)](https://packagist.org/packages/luthier/luthier) -Laravel-like routing and Middleware support for CodeIgniter 3. **Luthier-CI** makes the development of CodeIgniter apps even more enjoyable and simple! +Laravel-like routing and Middleware support for CodeIgniter 3. **Luthier-CI** makes the development of CodeIgniter apps even more enjoyable and simple! + +A design goal of Luthier-CI is to have not side efects in your application, so basically all must be working as expected, no matters what libraries, hooks, helpers o third party packages you have installed. ## Features * Clean and easy instalation via hooks * Global and per-route middleware -* Advanced routing: named parameters, optional parameters, default parameter values and "sticky" parameters -* Anonymous routes (using a callback instead a controller) +* Advanced routing: prefixes, namespaces, anonymous functions as routes, route groups, named parameters, optional parameters, default parameter values and "sticky" parameters ## Installation (**Note:** this tutorial is assuming that you have a fresh CodeIgniter installation) -#### Step 1: Get Luthier-CI with Composer +#### Get Luthier-CI with Composer ``` -composer require luthier/luthier dev-master +composer require luthier/luthier ``` -#### Step 2: Enable Hooks and Composer autoload +#### Enable Hooks and Composer autoload -Make sure that you have both *hooks* and *composer autoload* enabled: +Make sure that *hooks* and *composer autoload* are enabled: ```php load->view('some_view'); }); ``` @@ -132,7 +143,6 @@ In your views, you can use the function `route()` with the desired name to retri If you have subdirectories inside your controllers folder, you can specify a *pseudo-namespace* in your routes to indicate to CodeIgniter the path to the controller. -*Example:* ```php Route::get('hello/world', 'testcontroller@index', ['namespace' => 'admin']); @@ -140,7 +150,7 @@ Route::get('hello/world', 'testcontroller@index', ['namespace' => 'admin']); Will be point to *application/controllers/admin/Testcontroller.php* -#### Route prefix +#### Prefixes You can set a *prefix* to your routes with the following syntax: @@ -150,27 +160,95 @@ Route::get('hello/world', 'testcontroller@index', ['prefix' => 'admin']); So the route will be accessed with the 'admin/hello/world' path instead 'hello/world' + +#### Groups + +You can group your routes in a convenient way using the `Route::group()` method. All routes +inside the group will share the *prefix* (first argument) and, optionally, another properties +like *namespace* and *middleware* + +```php +Route::group('prefix', function(){ + Route::get('bar','test@bar'); + Route::get('baz','test@baz); +}); +``` + #### Default controller Luthier-CI automatically set any GET route to '/' path as your default controller, however, you can set it explicitly with: ```php -Route::set('default_controller', 'welcome/index'); // Note that this is a bind to $route['default_controller'] index and must be in CI -// native format +// native format: +Route::set('default_controller', 'welcome/index'); ``` -#### Groups -You can group your routes in a convenient way using the `Route::group()` method. All routes -inside the group will share the *prefix* (first argument) and, optionally, another properties -like *namespace* and *middleware* +## Middleware + +Luthier-CI adds the concept of middleware to the framework. Think on the middleware as a set of "layouts" that the user will pass thru with every request until reach to the desired resource. You can, for example, perform a user validation before enter to a controller, and redirect it to another place in case of failure. An advantage of the middleware is that you can assign it on a specific route/group or even define it as global middleware, and will be executed on all routes! + +#### Middleware execution points + +In global context, there's two points available + +* **pre_controller**: middleware will be executed right after the controller constructor, *BUT* before any controller action were performed. Please notice that the controller constructor is called at this point, because the own CodeIgniter's execution sequence (wich Luthier-CI don't modify) so if you need to do some actions *before* any middleware is executed, you must define a method called *preMiddleware()* in your controller and Luthier-CI will call it first. +* **post_controller**: middleware will be executed exactly in the `post_controller` hook point. + +In a route context, there's only one execution points and works as the **pre_controller** point in global context. + +#### Middleware definition + +All the middleware must be defined in the routes files (`application/routes/web.php`, `application/routes/api.php`, `application/routes/cli.php`) ```php -// Basic example: -Route::group('prefix', function(){ - Route::get('bar', ['uses' => 'test@bar']); - Route::get('baz', ['uses' => 'test@baz']); +# Route middleware: +Route::put('foo/bar','controller@method', ['middleware' => ['Test']]); + +# Route group middleware: +Route::group('site', ['middleware' => ['Tdmin']], function(){ + // ... }); + +# Global middleware: +Route::middleware('Admin', 'pre_controller'); +```` + +The middleware files must be saved in the `application/middleware` folder. If not exists, you must create it. A middleware file is any php class with a public `run()` method, which is the entry point. It's strongly adviced to name all your middleware with CamelCase and avoid name conflicts with your controllers. + +#### Manually running middleware + +In your controllers, you can call to a middleware with the `middleware->run()` method: + +```php +middleware->run('Admin'); + } + + // ... +} +```` + +#### Callbacks as middleware + +You can use callbacks in your middleware definitions and will works exactly as route actions callbacks: + +```php +load->library('twig'); +}, 'pre_controller'); ``` -*Full documentation and website coming soon...* \ No newline at end of file + +## Donate + +Enjoying Luthier-CI? Donate with [Paypal](paypal.me/andersalasm) \ No newline at end of file