Пример #1
0
 /**
  * @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));
     }
 }
Пример #2
0
 /**
  * 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()));
     }
 }
Пример #3
0
 /**
  * @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')));
     }
 }
Пример #4
0
 /**
  * @param ServiceEvent $event
  */
 public function onCacheLoaded(ServiceEvent $event)
 {
     $service = $event->getService();
     if (!$this->isEligibile($service)) {
         return;
     }
     $serviceHashKey = $service->getHashKey();
     $this->queueWriter->addItem($serviceHashKey, $serviceHashKey);
 }
Пример #5
0
 /**
  * @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));
     }
 }
Пример #6
0
 /**
  * @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()));
     }
 }
Пример #7
0
 public function testGet()
 {
     $service = $this->getMockBuilder('Itkg\\Consumer\\Service\\Service')->disableOriginalConstructor()->getMock();
     $event = new ServiceEvent($service);
     $this->assertEquals($event->getService(), $service);
 }