/**
  * Creates a new Requestobject
  *
  * @param ConfigurationInterface $configuration The configurationobject
  *
  * @return \ZalandoPHP\Request\RequestInterface
  */
 public static function createRequest(ConfigurationInterface $configuration)
 {
     $class = $configuration->getRequest();
     $factoryCallback = $configuration->getRequestFactory();
     if (true === is_object($class) && $class instanceof \ZalandoPHP\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('\\ZalandoPHP\\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));
 }
Esempio n. 2
0
 /**
  * Runs the given operation
  *
  * @param OperationInterface     $operation     The operation object
  * @param ConfigurationInterface $configuration The configuration object
  *
  * @return mixed
  */
 public function runOperation(OperationInterface $operation)
 {
     $configuration = @is_null($configuration) ? $this->configuration : $configuration;
     if (true === is_null($configuration)) {
         throw new \Exception('No configuration passed.');
     }
     $requestObject = RequestFactory::createRequest($configuration);
     $response = $requestObject->perform($operation);
     if ($this->configuration->getResponseType() == 'object') {
         return json_decode($response);
     } else {
         return json_decode($response, true);
     }
 }
Esempio n. 3
0
 /**
  * Builds the http headers
  *
  * @param array $params
  *
  * @return array
  */
 protected function buildHeaders()
 {
     $headers = [];
     $headers["Signature"] = "ZalandoPHP";
     $headers["Accept-Encoding"] = "gzip";
     //        $headers["test"]                = "blaat";
     // only set when input is geven
     if (!empty($this->configuration->getClientName())) {
         $headers["x-client-name"] = $this->configuration->getClientName();
     }
     if (!empty($this->configuration->getLocale())) {
         $headers["Accept-Language"] = $this->configuration->getLocale();
     }
     return $headers;
 }