elefantlabs/public-events-bundle

There is no license information available for the latest version (v2.0.0) of this package.

Installs: 2 461

Dependents: 0

Suggesters: 0

Security: 0

Stars: 6

Watchers: 2

Forks: 6

Open Issues: 1

Type:symfony-bundle

v2.0.0 2018-01-29 13:07 UTC

This package is not auto-updated.

Last update: 2020-11-13 22:28:56 UTC


README

Build Status Coverage Status

PublicEventsBundle helps you transform a Symfony event into a public event. An event is made public by logging it, calling an API, publishing it to an AMQP exchange..

Installation

composer require elefantlabs/public-events-bundle

add to AppKernel.php

public function registerBundles()
{
    $bundles = array(
        //...
        new Elefant\PublicEventsBundle\ElefantPublicEventsBundle(),
        //...
    );
}

Configuration reference

elefant_public_events:
    formatters: [metadata, formatter2] #or a service id for a custom formatter
    enabled: #default true
    trace: #default false, if enabled, 'event_source' is set for PublicEvent (uses debug_backtrace)
    handlers:
        logger_test: #You need a logger service
            type: logger
            filters:
                - {name: regex}
                - {class: MyEventType}
                - my_custom_filter # the service Id of your custom filter.
            formatters: [formatter1, formatter2] # the service Id of your custom formatter.
        guzzle_test: #You need a GuzzleClient service
            type: guzzle
            config:
                client: 'guzzle_client' #Guzzle client service ID
                method: test_method #Http method, default: get
                uri: /test_uri #default: /
                headers: ['extra headers'] #default: []
        rabbit_test: #You need rabbitmq bundle
             type: rabbitmq
             config:
                 connection: default# default: default
                 exchange_options: {}
                 queue_options: {}
                 callback: 'your_bundle.service_definition' #must implement ConsumerInterface
                 idle_timeout: #default null
                 idle_timeout_exit_code: #default null
You choose how you want to make your events public you choose which events to make public and what data should be appended
you define a Handler You define filters You define formatters

Handlers

Handlers process public events. Supported handlers:

  • LoggerHandler uses Monolog (supports a psr-log LoggerInterface)
  • GuzzleHandler uses Guzzle
  • RabbitmqHandler uses RabbitMqBundle
  • Custom handlers should implement Elefant\PublicEventsBundle\PublicEvents\Handler\HandlerInterface

RabbitmqHandler will automatically create one consumer and one producer for each handler of type rabbitmq

For rabbit_test handler, old_sound_rabbit_mq.public_events_rabbit_test_consumer and old_sound_rabbit_mq.public_events_rabbit_test_producer will be created.

Many handlers can handle the same event if they have overlapping filters

Filters

Filters which event you want to make public. Filters can be stacked and the first one that returns true on isPublic will mark the event as public. Currently there are name, class and custom filters.

If no filters are specified, the handler will handle all events. This is the equivalent to

filters:
    - {name: '/.*/'}

A filter should implement Elefant\PublicEventsBundle\PublicEvents\Filter\FilterInterface.

Formatters

A formatter produces an array from an event, all formatters will be called in the order they are defined and their results will be array_merged.