/** * Handles event if the apply method is available * * This method delegates to a protected method based on the domain event * class name: 'apply'.$className * * @param DomainEvent $domainEvent The domain event * * @return void */ protected function handle(DomainEvent $domainEvent) { $method = 'apply' . ClassName::short($domainEvent); if (!method_exists($this, $method)) { return; } $this->{$method}($domainEvent); }
/** * {@inheritdoc} */ public function process(CommandMessage $message, callable $next) { $command = ClassName::short($message->payloadType()->toString()); try { $this->logger->debug(sprintf('Command (%s) received: %s', $command, date(DATE_ATOM)), ['message' => $message->toString()]); $next($message); $this->logger->debug(sprintf('Command (%s) handled: %s', $command, date(DATE_ATOM)), ['message' => $message->toString()]); } catch (Exception $exception) { $this->logger->error(sprintf('Command (%s) failed: %s', $command, date(DATE_ATOM)), ['message' => $message->toString(), 'exception' => $exception]); throw $exception; } }
/** * {@inheritdoc} */ public function process(QueryMessage $message, callable $next) { $query = ClassName::short($message->payloadType()->toString()); try { $this->logger->debug(sprintf('Query (%s) received: %s', $query, date(DATE_ATOM)), ['message' => $message->serialize()]); $data = $next($message); $this->logger->debug(sprintf('Query (%s) handled: %s', $query, date(DATE_ATOM)), ['message' => $message->serialize()]); } catch (Exception $exception) { $this->logger->error(sprintf('Query (%s) failed: %s', $query, date(DATE_ATOM)), ['message' => $message->serialize(), 'exception' => $exception]); throw $exception; } return $data; }
/** * Retrieves a string representation * * @return string */ public final function toString() : string { return sprintf('%s.%s', ClassName::short(static::class), $this->name()); }
public function test_that_short_returns_expected_value() { $expected = 'ClassName'; $className = 'Novuso\\System\\Utility\\ClassName'; $this->assertSame($expected, ClassName::short($className)); }