2017 © Pedro Peláez
 

library zf-bernard

image

interactive-solutions/zf-bernard

  • Thursday, January 18, 2018
  • by mac_nibblet
  • Repository
  • 3 Watchers
  • 3 Stars
  • 1,484 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 19 Versions
  • 3 % Grown

The README.md

ZF-Bernard

Code Quality Build status, (*1)

Provides zend framework 2, 3 and zend-expressive integrations, (*2)

Installing

We support installation via composer, note for now you need to set the minimum stability to alpha to install, (*3)

composer require interactive-solutions/zf-bernard, (*4)

Usage

To consume a queue:, (*5)

$ php public/index interactive-solutions:bernard:consume <queueName>

You can also pass the following options: - --max-runtime=<VALUE>: This will make the consumer shutdown after <VALUE> seconds. PHP_INT_MAX by default - --stop-on-failure: This will make the consumer halt on unhandled exceptions. Off by default - --max-messages=<VALUE>: This will make the consumer shutdown after <VALUE> messages are ran. Infinite by default - --stop-on-empty: This will make the consumer run all the queued messages and then shutdown. Off by default, (*6)

Normalizers

You can add any normalizer that you wish to use by adding it to the BernardOptions::enabledNormalizers, (*7)

The default enabled normalizers are, (*8)

  • Bernard\Normalizer\DefaultMessageNormalizer
  • Bernard\Normalider\EnvelopeNormalizer
  • InteractiveSolutions\Bernard\Normalizer\ExplicitNormalizer

Add to the queue

Create an object extending the AbstractExplicitMessage class and it to the producer queue like this:, (*9)

final class SomeClass
{
    // This method is called when the task is consumed
    public function __invoke(Message $message)
    {
        // do stuff
    }
}

final class Message extends AbstractExplicitMessage
{
    // various parameters for your application

    /**
     * Message constructor.
     */
    public function __construct(...parameters)
    {
        // Initialize parameters
    }

    /**
     * @return string
     */
    public function getName()
    {
        return SomeClass::class;
    }

    // getters for your parameters

    public function getQueue(): string
    {
        return 'some-queue';
    }
}

$producer->produce(new Message(...parameters));

Register the SomeClass under bernard_consumer_manager in the config and you're done., (*10)

Hooking into the event manager using a delegate factory

This delegate factory supports both zend framework service manager 2 & 3, read more about it here, (*11)

Example of introducing the ClearObjectManager event listener, (*12)

final class EventDispatcherDelegateFactory implements DelegatorFactoryInterface
{
    public function __invoke(ContainerInterface $container, $requestedName, callable $callback, array $options = null)
    {
        /* @var $dispatcher EventDispatcherInterface */
        $dispatcher = $callback();
        $dispatcher->addListener(BernardEvents::ACKNOWLEDGE, $container->get(ClearObjectManager::class));

        return $dispatcher;
    }

    public function createDelegatorWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName, $callback)
    {
        return $this($serviceLocator, $requestedName, $callback);
    }
}

The Versions

18/01 2018
02/11 2017
15/06 2017

dev-zf-log-subscriber

dev-zf-log-subscriber https://github.com/interactives-solutions/zf-bernard

  Sources   Download

MIT

The Requires

 

11/10 2016

dev-feature/consume-options

dev-feature/consume-options https://github.com/interactives-solutions/zf-bernard

  Sources   Download

MIT

The Requires