Exemple #1
0
 public static function appendParameters($url, array $parameters)
 {
     $url = new Customweb_Core_Url($url);
     foreach ($parameters as $key => $value) {
         $url->appendQueryParameter($key, $value);
     }
     return $url->toString();
 }
 protected function processKeyedHeader($headerKey, $headerValue)
 {
     parent::processKeyedHeader($headerKey, $headerValue);
     if ($headerKey == self::HEADER_KEY_COOKIE) {
         $this->processCookieHeader($headerValue);
     } else {
         if ($headerKey == self::HEADER_KEY_HOST) {
             $this->url->setHost($headerValue);
         } else {
             if ($headerKey == self::HEADER_KEY_USER_AGENT) {
                 $this->userAgent = $headerValue;
             } else {
                 if ($headerKey == self::HEADER_KEY_AUTHORIZATION) {
                     $authorizationName = strtolower(trim(substr($headerValue, 0, strpos($headerValue, ' '))));
                     if (isset(self::$authorizations[$authorizationName])) {
                         $className = self::$authorizations[$authorizationName];
                         Customweb_Core_Util_Class::loadLibraryClassByName($className);
                         $object = new $className();
                         if (!$object instanceof Customweb_Core_Http_IAuthorization) {
                             throw new Exception("The given authorization class does not implement the authorization interface.");
                         }
                         $object->parseHeaderFieldValue($headerValue);
                         $this->authorization = $object;
                     }
                 }
             }
         }
     }
 }
Exemple #3
0
 /**
  * This method converts all relative and absolute URLs to absolute URLs.
  *
  * @param string $href
  * @param Customweb_Http_Url $baseUrl
  * @return Customweb_Http_Url
  */
 public static function toAbsoluteUrl($href, Customweb_Core_Url $baseUrl)
 {
     if ($href instanceof Customweb_Core_Url) {
         return $href;
     }
     $href = (string) $href;
     $href = trim($href);
     // If the URL string contains :// then the protocol etc. defined.
     if (strstr($href, '://')) {
         return new Customweb_Core_Url($href);
     } else {
         // Append a slash at the begin, when there is no one. This
         // insures that we get always a valid URL.
         if (substr($href, 0, 1) !== '/') {
             $href = '/' . $href;
         }
         return new Customweb_Core_Url($baseUrl->getBaseUrl() . $href);
     }
 }
 /**
  * Sets the body of the message. Either a string or array can be 
  * provided. In case it is an array the body is treated as a query
  * string. 
  *
  * 
  * @param string|array $body
  * @return void
  */
 public function setBody($body)
 {
     if (is_array($body)) {
         $this->body = Customweb_Core_Url::parseArrayToString($body);
         $this->parsedBody = $body;
     } else {
         $this->body = (string) $body;
     }
     $this->removeHeadersWithKey(self::HEADER_KEY_CONTENT_LENGTH);
     $length = strlen($this->body);
     if ($length > 0) {
         $this->appendHeader(self::HEADER_KEY_CONTENT_LENGTH . ': ' . $length);
     }
 }
 /**
  * Creates a URL based on the parameters given and the order context.
  * Subclasses may override this method to apply SEO optimizations.
  * 
  * @param Customweb_Payment_Authorization_IOrderContext $orderContext
  * @param array $parameters
  * @return string
  */
 protected function createUrl(array $parameters)
 {
     $url = new Customweb_Core_Url($this->getBaseUrl());
     $url->appendQueryParameters($parameters);
     return $url->toString();
 }