예제 #1
0
 public static function createRequest(ConfigurationInterface $configuration)
 {
     $class = $configuration->getRequest();
     $factoryCallback = $configuration->getRequestFactory();
     if (true === is_object($class) && $class instanceof \AliexApi\Request\RequestInterface) {
         $class->setConfiguration($configuration);
         return self::applyCallback($factoryCallback, $class);
     }
     if (true === is_string($class) && true === array_key_exists($class, self::$requestObjects)) {
         $request = self::$requestObjects[$class];
         $request->setConfiguration($configuration);
         return self::applyCallback($factoryCallback, $request);
     }
     try {
         $reflectionClass = new \ReflectionClass($class);
     } catch (\ReflectionException $e) {
         throw new \InvalidArgumentException(sprintf("Requestclass not found: %s", $class));
     }
     if ($reflectionClass->implementsInterface('\\AliexApi\\Request\\RequestInterface')) {
         $request = new $class();
         $request->setConfiguration($configuration);
         return self::$requestObjects[$class] = self::applyCallback($factoryCallback, $request);
     }
     throw new \LogicException(sprintf("Requestclass does not implements the RequestInterface: %s", $class));
 }
예제 #2
0
 protected function applyResponseTransformer($response, ConfigurationInterface $configuration)
 {
     if (true === is_null($configuration->getResponseTransformer())) {
         return $response;
     }
     $responseTransformer = ResponseTransformerFactory::createResponseTransformer($configuration);
     return $responseTransformer->transform($response);
 }