2017 © Pedro Peláez
 

library router

Laravel Ratchet Router

image

calen/router

Laravel Ratchet Router

  • Sunday, August 7, 2016
  • by Calen
  • Repository
  • 2 Watchers
  • 1 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Laravel WS Router

The Router provides a good way to do kind or URL routing for websockets. The library depends on cboden/ratchet which is the WebSocket server used but feel free to write the same for other WebSocket servers., (*1)

The library works based on the fields path given in the JSON message. All the configuration is done via the router.php file published., (*2)

The library handles Middlewares, Prefixes namespaces in grouping similarly to Laravel 5 URL routing., (*3)

Installation

Require Calen/router in your L5 project. I used PHP7 to write it, so it has a dependency on it., (*4)

composer require calen/router, (*5)

Then add the Service Provider in the providers in L5 config/app.php:, (*6)

 'providers' => [
    App\Providers\AppServiceProvider::class,
    App\Providers\AuthServiceProvider::class,
    App\Providers\EventServiceProvider::class,
    App\Providers\RouteServiceProvider::class,

    // ...

    Calen\Router\RatchetRouterServiceProvider::class,

 ],
 ```

 Once the ServiceProvider is added, you can publish the configuration file by running artisan:

 ``` php artisan vendor:publish ```

 This will add the config file *router.php* in the config repository.


Configuration
---

You will need to configure the library for it to run correctly. The config file publishes as this:

return [ 'middlewares' => [ // 'test' => App\WS\AuthMiddleware::class, ], 'routes' => function ($routes) { $routes->group(['namespace' => 'App\Http\Controllers'], function ($routes) { $routes->route('/', 'HomeController@index'); }); }, ];, (*7)


### Middlewares The middlewares look the same as the L5's ones. If you want to provide a middleware on some routes on can add the `middleware` key to the array given in `group` function. The middleware must implement the Calen\Router\Routing\Middleware\Middleware interface. For example:

$routes->group( [ 'namespace' => 'App\Http\Controllers', 'middleware' => 'dummy', 'prefix' => 'CalenApp', ], function ($routes) { // My routes }); ```, (*8)

We add the middleware dummy to all the routes given in the closure., (*9)

As L5, the middleware are registered in the config/router.php file, as a name to the class corresponding like this:, (*10)

return [ 'middlewares' => [ 'dummy' => App\WS\Dummyddleware::class, ], 'routes' => function ($routes) { $routes->group(['namespace' => 'App\Http\Controllers'], function ($routes) { $routes->route('/', 'HomeController@index'); }); }, ];, (*11)

Note:

If the middleware is not registered, it will not be handled, (*12)

Packagist

My packagist repo is here: https://packagist.org/packages/calen/router, (*13)

The Versions

07/08 2016

dev-master

9999999-dev

Laravel Ratchet Router

  Sources   Download

MIT

The Requires

 

by Pierre-Louis Dagues

07/08 2016

1.0.0

1.0.0.0

Laravel Ratchet Router

  Sources   Download

MIT

The Requires

 

by Pierre-Louis Dagues