/** * @param ServiceEvent $event */ public function onServiceException(ServiceEvent $event) { $service = $event->getService(); if ($service instanceof ServiceLoggableInterface && null !== ($logger = $service->getLogger())) { $logger->error('Response KO', array('service' => $service)); } }
/** * throw exception if service is disabled * * @param ServiceEvent $event * @throws \Itkg\Consumer\Exception\DisabledServiceException */ public function onServiceRequest(ServiceEvent $event) { $service = $event->getService(); if ($service instanceof AdvancedServiceInterface && $service->isDisabled()) { throw new DisabledServiceException(sprintf('Service %s is disabled', $service->getIdentifier())); } }
/** * @param ServiceEvent $event */ public function onResponseEvent(ServiceEvent $event) { $service = $event->getService(); if ($service instanceof ServiceConfigurableInterface && null !== $service->getOption('response_type')) { /** @var Service $service */ $service->getResponse()->setDeserializedContent($this->serializer->deserialize($service->getResponse()->getContent(), $service->getOption('response_type'), $service->getOption('response_format'))); } }
/** * @param ServiceEvent $event */ public function onCacheLoaded(ServiceEvent $event) { $service = $event->getService(); if (!$this->isEligibile($service)) { return; } $serviceHashKey = $service->getHashKey(); $this->queueWriter->addItem($serviceHashKey, $serviceHashKey); }
/** * @param ServiceEvent $event */ public function onServiceResponse(ServiceEvent $event) { $service = $event->getService(); if (!$service instanceof ServiceCacheableInterface || null === $service->getCacheAdapter()) { return; } if (!$service->isLoaded()) { $cache = $this->createCache($service); $service->getCacheAdapter()->set($cache); $this->eventDispatcher->dispatch(ServiceCacheEvents::SET, new CacheEvent($cache)); } }
/** * @param ServiceEvent $event */ public function onServiceRequest(ServiceEvent $event) { /** @var Service $service */ $service = $event->getService(); if (!$service instanceof ServiceConfigurableInterface) { return; } if ($serviceConfig = $this->repository->findOneByServiceKey($service->getIdentifier())) { // Inject service configuration & client configuration $service->configure(array_merge($service->getOptions(), $serviceConfig->toOptions())); $service->getClient()->setNormalizedOptions(array_merge($service->getClient()->getOptions(), $serviceConfig->getClientConfig()->toOptions())); } }
public function testGet() { $service = $this->getMockBuilder('Itkg\\Consumer\\Service\\Service')->disableOriginalConstructor()->getMock(); $event = new ServiceEvent($service); $this->assertEquals($event->getService(), $service); }