PHP code example of interactive-solutions / zf-bernard

1. Go to this page and download the library: Download interactive-solutions/zf-bernard library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

interactive-solutions / zf-bernard example snippets


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));

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);
    }
}
bash
$ php public/index interactive-solutions:bernard:consume <queueName>