PHP code example of gendoria / command-queue-bundle

1. Go to this page and download the library: Download gendoria/command-queue-bundle 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/ */

    

gendoria / command-queue-bundle example snippets



// app/AppKernel.php

// ...
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = array(
            // ...

            new Gendoria\CommandQueueBundle\GendoriaCommandQueueBundle(),
        );

        // ...
    }

    // ...
}

namespace Example\Namespace;

use Gendoria\CommandQueue\Command\CommandInterface;
use JMS\Serializer\Annotation\Type;

class ParseUrlCommand implements CommandInterface
{
    /**
     * Page URL.
     *
     * @var string
     * @Type("string")
     */
    public $url;
    
    /**
     * User ID.
     *
     * @var integer
     * @Type("integer")
     */
    public $userId;
    
    /**
     * Class constructor.
     *
     * @param string  $url    Page URL.
     * @param integer $userId User ID.
     */
    public function __construct($url, $userId)
    {
        $this->url = $url;
        $this->userId = $userId;
    }
}


namespace ExampleBundle\Controller;

use Gendoria\CommandQueue\QueueManager\MultipleQueueManagerInterface;
use Example\Namespace\ParseUrlCommand;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

/**
 * @Route("/")
 */
class ExampleController extends Controller
{

    /**
     * @Route("")
     */
    public function index()
    {
            $command = new ParseUrlCommand("http://example.com", 1);

            /* @var $service MultipleQueueManagerInterface */
            $service = $this->get('gendoria_command_queue.manager');
            $service->sendCommand($command);
    }
}

namespace ExampleBundle\CommandProcessor;

use Gendoria\CommandQueue\Command\CommandInterface;
use Gendoria\CommandQueue\CommandProcessor\CommandProcessorInterface;
use Example\Namespace\ParseUrlCommand;

class ParseUrlProcessor implements CommandProcessorInterface
{
    /**
     * @param ParseUrlCommand $command
     */
    public function process(CommandInterface $command)
    {
        //Parse your URL here
    }
    
    /**
     * {@inheritdoc}
     */
    public function supports(CommandInterface $command)
    {
        return $command instanceof ParseUrlCommand;
    }
}