Exemplo n.º 1
0
 /**
  * @param DomainEvent $event
  * @return void
  */
 protected function when(DomainEvent $event)
 {
     $method = 'when' . ClassFunctions::short($event);
     if (is_callable([$this, $method])) {
         $this->{$method}($event);
     }
 }
Exemplo n.º 2
0
 /**
  * Construct.
  */
 public function __construct()
 {
     $this->translator = $this->getServiceContainer()->getTranslator();
     if (!$this->defaultDomain) {
         $this->defaultDomain = 'tl_workflow_' . strtolower(ClassFunctions::short($this));
     }
 }
    public function handle(Command $command)
    {
        $short = ClassFunctions::short($command);
        $method = 'handle' . $short;
        if (!is_callable([$this, $method])) {
            $message = <<<MSG
The CommandHandler needs the following code to operate:
protected function {$method}({$short} \$command)
{
}
MSG;
            throw CommandCouldNotBeHandled::forCommand($command, $this, $message);
        }
        $this->{$method}($command);
    }
 /**
  * @test
  */
 public function constants()
 {
     $this->assertEquals(['MY_CONST1' => 'a', 'MY_CONST2' => 'b'], ClassFunctions::constants('Verraes\\ClassFunctions\\Tests\\MyClass'));
 }
Exemplo n.º 5
0
 /**
  * @return string
  */
 public function getName()
 {
     return ClassFunctions::short($this);
 }
Exemplo n.º 6
0
 /**
  * Create default log namespace.
  *
  * @return string
  */
 protected function createDefaultLogNamespace()
 {
     $className = ClassFunctions::underscore(ClassFunctions::short($this));
     return preg_replace('/_action$/', '', $className, 1);
 }
 public static function forCommand(Command $command, CommandHandler $commandHandler, $message = "")
 {
     return new CommandCouldNotBeHandled(sprintf("The command %s could not be handled by %s\n%s", ClassFunctions::fqcn($command), ClassFunctions::fqcn($commandHandler), $message));
 }
Exemplo n.º 8
0
 /**
  * Make a contract from an fully qualified class name, of the form My.Namespace.Class
  * @param object|string $object
  * @return Contract
  */
 public static function canonicalFrom($object)
 {
     return Contract::with(ClassFunctions::canonical($object));
 }
Exemplo n.º 9
0
 protected function when(DomainEvent $event)
 {
     $method = 'when' . ClassFunctions::short($event);
     $this->{$method}($event);
 }
Exemplo n.º 10
0
 /**
  * @param DomainEvent[] $streamEvents
  * @return array
  */
 private function convertToClientProcessEvents(array $streamEvents)
 {
     $clientEvents = [];
     foreach ($streamEvents as $streamEvent) {
         $clientEvent = ['name' => ClassFunctions::short($streamEvent->messageName()), 'process_id' => $streamEvent->metadata()['aggregate_id'], 'payload' => $streamEvent->payload(), 'occurred_on' => $streamEvent->createdAt()->format(\DateTime::ISO8601)];
         $taskListPosition = null;
         if (isset($clientEvent['payload']['taskListPosition'])) {
             $taskListPosition = TaskListPosition::fromString($clientEvent['payload']['taskListPosition']);
         }
         $clientEvent['task_list_id'] = $taskListPosition ? $taskListPosition->taskListId()->toString() : null;
         $clientEvent['task_id'] = $taskListPosition ? $taskListPosition->position() - 1 : null;
         $clientEvents[] = $clientEvent;
     }
     return $clientEvents;
 }