2017 © Pedro Peláez
 

symfony-bundle pubsub-router-bundle

Symfony PubSub Router Bundle

image

gos/pubsub-router-bundle

Symfony PubSub Router Bundle

  • Monday, May 21, 2018
  • by ProPheT777
  • Repository
  • 6 Watchers
  • 19 Stars
  • 235,573 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 9 Forks
  • 1 Open issues
  • 22 Versions
  • 26 % Grown

The README.md

GosPubSubRouterBundle

Latest Stable Version Latest Unstable Version Total Downloads License Run Tests, (*1)

About

GosPubSubRouterBundle is a Symfony Bundle whose goal is to plug any logic behind pubsub channel. When you use PubSub pattern you will make face to a problem, rely channels with business logic. PubSub router is here to make the junction between channel and business logic., (*2)

Support

Version Status Symfony Versions
1.x No Longer Supported 3.4, 4.4, 5.2-5.4
2.x Actively Supported 4.4, 5.3-5.4, 6.0
3.x In Development 5.3-5.4, 6.0

Features

  • [x] Route definition
  • [x] Route matching
  • [x] Route generator

Installation

Add the bundle to your project using Composer:, (*3)

composer require gos/pubsub-router-bundle

Once installed, you will need to add the bundle to your project., (*4)

If your project is based on Symfony Flex, the bundle should be automatically added to your config/bundles.php file:, (*5)

Gos\Bundle\PubSubRouterBundle\GosPubSubRouterBundle::class => ['all' => true],

If your project is based on the Symfony Standard Edition, you will need to add the bundle to your Kernel's registerBundles method by editing app/AppKernel.php:, (*6)

class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            ...
            new \Gos\Bundle\PubSubRouterBundle\GosPubSubRouterBundle()
        );

        ...
    }

Bundle configuration, (*7)

Below is an example bundle configuration. For projects based on Symfony Flex, this should be stored in config/packages/gos_pubsub_router.yaml. For projects based on Symfony Standard Edition, this should be added to app/config/config.yml., (*8)

#Gos PubSub Router
gos_pubsub_router:
    routers:
        websocket: #available from container through gos_pubsub_router.websocket
            resources:
                - @GosNotificationBundle/Resources/config/pubsub/websocket/notification.yml
        redis: #available from container through gos_pubsub_router.redis
            resources:
                - @GosNotificationBundle/Resources/config/pubsub/redis/notification.yml

NOTE : Each router is insulated. If you have several routers in the same class you will need to inject each router that you need., (*9)

Usage

Routing definition

Example with websocket pubsub, (*10)

user_notification:
    channel: notification/user/{role}/{application}/{user_ref}
    handler: ['Acme\Chat\MessageHandler', 'addPushers']
    requirements:
        role: "editor|admin|client"
        application: "[a-z]+"
        user_ref: "\d+"

Example with redis pubsub, (*11)

user_app_notification:
    channel: notification:user:{role}:{application}:{user_ref}
    handler: ['Acme\Chat\MessageHandler', 'addPushers']
    requirements:
        role: "editor|admin|client"
        application: "[a-z-]+-app"
        user_ref: "\d+"

NOTE : The handler is not typehinted, this allows you to define the handler callback in any way you'd like (such as an array to call a method on a class or a string to call a PHP function or a service from the container)., (*12)

Use router

Let's generate a route !, (*13)

$router = $this->container->get('gos_pubsub_router.websocket');
$channel = $router->generate('user_notification', ['role' => 'admin', 'application' => 'blog-app', 'user_ref' => '123']);

echo $channel // notification/user/admin/blog/123

Match your first route !, (*14)

use Gos\Bundle\PubSubRouterBundle\Request\PubSubRequest;

$channel = 'notification/user/admin/billing-app/639409'; // 'notification/user/admin/billing-app/*' work :)

list($routeName, $route, $attributes) = $router->match($channel);

$request = new PubSubRequest($routeName, $route, $attributes); //Create a request object if you want transport the request data as dependency

//$request->getAttributes()->get('user_ref'); it's a parameterBag

// $router->match($channel);

// $routeName -> 'user_app_notification
// $route -> instance of Gos\Bundle\PubSubRouterBundle\Router\Route
// $attributes -> [ 'role' => 'admin', 'application' => 'billing-app', 'user_ref' => '639409' ]

What about mismatch?, (*15)

use Gos\Bundle\PubSubRouterBundle\Exception\ResourceNotFoundException;

$channel = 'notification/user/admin/billing-app/azerty'; // will miss match

try {
    list($routeName, $route, $attributes) = $router->match($channel);
} catch (ResourceNotFoundException $e) {
    //handle exception
}
  • If you only need to generate route, typehint against Gos\Bundle\PubSubRouterBundle\Generator\GeneratorInterface
  • If you only need to match route, typehint against Gos\Bundle\PubSubRouterBundle\Matcher\MatcherInterface
  • If you need both, typehint against Gos\Bundle\PubSubRouterBundle\Router\RouterInterface

Router CLI

php bin/console gos:prouter:debug -r websocket dump all registered routes for websocket router, (*16)

License

MIT, See LICENSE file in the root of project., (*17)

The Versions

21/05 2018

dev-master

9999999-dev https://github.com/GeniusesOfSymfony/PubSubRouterBundle

Symfony PubSub Router Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johann Saunier

redis bundle zmq wamp pubsub pubsub bundle

21/05 2018

v0.3.4

0.3.4.0 https://github.com/GeniusesOfSymfony/PubSubRouterBundle

Symfony PubSub Router Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johann Saunier

redis bundle zmq wamp pubsub pubsub bundle

23/01 2018

v0.3.3

0.3.3.0 https://github.com/GeniusesOfSymfony/PubSubRouterBundle

Symfony PubSub Router Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johann Saunier

redis bundle zmq wamp pubsub pubsub bundle

12/12 2017

v0.3.2

0.3.2.0 https://github.com/GeniusesOfSymfony/PubSubRouterBundle

Symfony PubSub Router Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johann Saunier

redis bundle zmq wamp pubsub pubsub bundle

05/07 2017

v0.3.1

0.3.1.0 https://github.com/GeniusesOfSymfony/PubSubRouterBundle

Symfony PubSub Router Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johann Saunier

redis bundle zmq wamp pubsub pubsub bundle

07/02 2017

v0.3.0

0.3.0.0 https://github.com/GeniusesOfSymfony/PubSubRouterBundle

Symfony PubSub Router Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johann Saunier

redis bundle zmq wamp pubsub pubsub bundle

27/05 2016

v0.2.1

0.2.1.0 https://github.com/GeniusesOfSymfony/PubSubRouterBundle

Symfony PubSub Router Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johann Saunier

redis bundle zmq wamp pubsub pubsub bundle

05/03 2016

v0.2.0

0.2.0.0 https://github.com/GeniusesOfSymfony/PubSubRouterBundle

Symfony PubSub Router Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johann Saunier

redis bundle zmq wamp pubsub pubsub bundle

03/03 2016

dev-sf3

dev-sf3 https://github.com/GeniusesOfSymfony/PubSubRouterBundle

Symfony PubSub Router Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johann Saunier

redis bundle zmq wamp pubsub pubsub bundle

02/11 2015

v0.1.10

0.1.10.0 https://github.com/GeniusesOfSymfony/PubSubRouterBundle

Symfony PubSub Router Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johann Saunier

redis bundle zmq wamp pubsub pubsub bundle

02/11 2015

v0.1.11

0.1.11.0 https://github.com/GeniusesOfSymfony/PubSubRouterBundle

Symfony PubSub Router Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johann Saunier

redis bundle zmq wamp pubsub pubsub bundle

02/11 2015

dev-sf-23

dev-sf-23 https://github.com/GeniusesOfSymfony/PubSubRouterBundle

Symfony PubSub Router Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johann Saunier

redis bundle zmq wamp pubsub pubsub bundle

20/10 2015

v0.1.9

0.1.9.0 https://github.com/GeniusesOfSymfony/PubSubRouterBundle

Symfony PubSub Router Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johann Saunier

redis bundle zmq wamp pubsub pubsub bundle

13/10 2015

v0.1.8

0.1.8.0 https://github.com/GeniusesOfSymfony/PubSubRouterBundle

Symfony PubSub Router Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johann Saunier

redis bundle zmq wamp pubsub pubsub bundle

09/07 2015

v0.1.7

0.1.7.0 https://github.com/GeniusesOfSymfony/PubSubRouterBundle

Symfony PubSub Router Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johann Saunier

redis bundle zmq wamp pubsub pubsub bundle

09/07 2015

v0.1.6

0.1.6.0 https://github.com/GeniusesOfSymfony/PubSubRouterBundle

Symfony PubSub Router Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johann Saunier

redis bundle zmq wamp pubsub pubsub bundle

27/06 2015

v0.1.5

0.1.5.0 https://github.com/GeniusesOfSymfony/PubSubRouterBundle

Symfony PubSub Router Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johann Saunier

redis bundle zmq wamp pubsub pubsub bundle

24/06 2015

v0.1.4

0.1.4.0 https://github.com/GeniusesOfSymfony/PubSubRouterBundle

Symfony PubSub Router Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johann Saunier

redis bundle zmq wamp pubsub pubsub bundle

23/06 2015

v0.1.3

0.1.3.0 https://github.com/GeniusesOfSymfony/PubSubRouterBundle

Symfony PubSub Router Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johann Saunier

redis bundle zmq wamp pubsub pubsub bundle

23/06 2015

v0.1.2

0.1.2.0 https://github.com/GeniusesOfSymfony/PubSubRouterBundle

Symfony PubSub Router Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johann Saunier

redis bundle zmq wamp pubsub pubsub bundle

18/04 2015

v0.1.1

0.1.1.0 https://github.com/GeniusesOfSymfony/PubSubRouterBundle

Symfony PubSub Router Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johann Saunier

redis bundle zmq wamp pubsub pubsub bundle

12/04 2015

v0.1.0

0.1.0.0 https://github.com/GeniusesOfSymfony/PubSubRouterBundle

Symfony PubSub Router Bundle

  Sources   Download

MIT

The Requires

 

The Development Requires

by Johann Saunier

redis bundle zmq wamp pubsub pubsub bundle