registerFactory(WebhookEvent::FEED_ENTRY_TYPE, new FeedEntryProcessorFactory($app)); $this->registerFactory(WebhookEvent::USER_REGISTRATION_TYPE, new UserRegistrationProcessorFactory($app)); } /** * @param string $eventType * @param ProcessorFactory $processorFactory */ public function registerFactory($eventType, ProcessorFactory $processorFactory) { $this->processorFactories[$eventType] = $processorFactory; } /** * @param string $eventType * @param callback|callable $callable */ public function registerCallableFactory($eventType, $callable) { if (! is_callable($callable)) { throw new InvalidArgumentException(sprintf( 'Expected a callable, got "%s" instead', is_object($callable) ? get_class($callable) : gettype($callable) )); } $this->processorFactories[$eventType] = new CallableProcessorFactory($callable); } /** * @param WebhookEvent $event * @return Processor\ProcessorInterface */ public function get(WebhookEvent $event) { if (! isset($this->processorFactories[$event->getType()])) { throw new \RuntimeException(sprintf('No processor found for %s', $event->getType())); } $factory = $this->processorFactories[$event->getType()]; return $factory->createProcessor(); } }