for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/******************************************************************************
* Copyright (c) 2017 Constantin Galbenu <[email protected]> *
******************************************************************************/
namespace Gica\Cqrs\CodeGeneration;
use Gica\CodeAnalysis\MethodListenerDiscovery;
use Gica\CodeAnalysis\MethodListenerDiscovery\ListenerClassValidator\AnyPhpClassIsAccepted;
use Gica\CodeAnalysis\MethodListenerDiscovery\MapGrouper\GrouperByEvent;
use Gica\Cqrs\CodeGeneration\Traits\GroupedByEventTrait;
use Gica\Cqrs\Command\CodeAnalysis\AggregateCommandHandlerDetector;
class CommandHandlersMapCodeGenerator
{
use GroupedByEventTrait;
protected function log($outputFilePath)
$this->logger->info("Commands map wrote to: $outputFilePath");
}
private function validateMap(array $map)
foreach ($map as $command => $commandHandlers) {
if (count($commandHandlers) > 1) {
throw new \Exception(
sprintf("multiple handlers exists for command %s", $command));
protected function discover(\Iterator $files)
$discoverer = new MethodListenerDiscovery(
new AggregateCommandHandlerDetector(),
new AnyPhpClassIsAccepted);
$map = $discoverer->discoverListeners($files);
$this->validateMap($this->groupMap($map));
return $map;
private function groupMap(array $map)
return (new GrouperByEvent())->groupMap($map);