vendor/broadway/broadway-bundle/src/Command/CommandMetadataEnricher.php line 47

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4.  * This file is part of the broadway/broadway-bundle package.
  5.  *
  6.  * (c) 2020 Broadway project
  7.  *
  8.  * For the full copyright and license information, please view the LICENSE
  9.  * file that was distributed with this source code.
  10.  */
  11. namespace Broadway\Bundle\BroadwayBundle\Command;
  12. use Broadway\Domain\Metadata;
  13. use Broadway\EventSourcing\MetadataEnrichment\MetadataEnricher;
  14. use Symfony\Component\Console\Event\ConsoleCommandEvent;
  15. /**
  16.  * Enricher that adds information about the excecuted console command.
  17.  */
  18. class CommandMetadataEnricher implements MetadataEnricher
  19. {
  20.     private $event;
  21.     /**
  22.      * {@inheritdoc}
  23.      */
  24.     public function enrich(Metadata $metadata): Metadata
  25.     {
  26.         if (null === $this->event) {
  27.             return $metadata;
  28.         }
  29.         $data = [
  30.             'console' => [
  31.                 'command' => get_class($this->event->getCommand()),
  32.                 'arguments' => $this->event->getInput()->__toString(),
  33.             ],
  34.         ];
  35.         $newMetadata = new Metadata($data);
  36.         return $metadata->merge($newMetadata);
  37.     }
  38.     public function handleConsoleCommandEvent(ConsoleCommandEvent $event)
  39.     {
  40.         $this->event $event;
  41.     }
  42. }