예제 #1
0
 protected function buildUrl($url)
 {
     if (!$this->apiKey) {
         throw new MissingAPIKeyException('Missing the API key.  Please either call setApiKey(), set the API key as a dependency parameter, or create a Magium/Mail/GeneratorConfiguration.php file to set the API key');
     }
     $uri = new Http($url);
     $uri->setQuery(['key' => $this->apiKey]);
     return $uri->toString();
 }
예제 #2
0
파일: Youtube.php 프로젝트: patrova/omeka-s
 public function render(PhpRenderer $view, MediaRepresentation $media, array $options = [])
 {
     if (!isset($options['width'])) {
         $options['width'] = self::WIDTH;
     }
     if (!isset($options['height'])) {
         $options['height'] = self::HEIGHT;
     }
     if (!isset($options['allowfullscreen'])) {
         $options['allowfullscreen'] = self::ALLOWFULLSCREEN;
     }
     // Compose the YouTube embed URL and build the markup.
     $data = $media->mediaData();
     $url = new HttpUri(sprintf('https://www.youtube.com/embed/%s', $data['id']));
     $url->setQuery(['start' => $data['start'], 'end' => $data['end']]);
     $embed = sprintf('<iframe width="%s" height="%s" src="%s" frameborder="0"%s></iframe>', $view->escapeHtml($options['width']), $view->escapeHtml($options['height']), $view->escapeHtml($url), $options['allowfullscreen'] ? ' allowfullscreen' : '');
     return $embed;
 }
예제 #3
0
    /**
     * Provide an alternate Parameter Container implementation for server parameters in this object, (this is NOT the
     * primary API for value setting, for that see server())
     *
     * @param \Zend\Stdlib\ParametersInterface $server
     * @return Request
     */
    public function setServer(ParametersInterface $server)
    {
        $this->serverParams = $server;

        // This seems to be the only way to get the Authorization header on Apache
        if (function_exists('apache_request_headers')) {
            $apacheRequestHeaders = apache_request_headers();
            if (isset($apacheRequestHeaders['Authorization'])) {
                if (!$this->serverParams->get('HTTP_AUTHORIZATION')) {
                    $this->serverParams->set('HTTP_AUTHORIZATION', $apacheRequestHeaders['Authorization']);
                }
            }
        }

        $this->headers()->addHeaders($this->serverToHeaders($this->serverParams));

        if (isset($this->serverParams['REQUEST_METHOD'])) {
            $this->setMethod($this->serverParams['REQUEST_METHOD']);
        }

        if (isset($this->serverParams['SERVER_PROTOCOL']) 
            && strpos($this->serverParams['SERVER_PROTOCOL'], '1.0') !== false) {
            $this->setVersion('1.0');
        }

        $this->setUri($uri = new HttpUri());

        if (isset($this->serverParams['HTTPS']) && $this->serverParams['HTTPS'] === 'on') { 
            $uri->setScheme('https');
        } else {
            $uri->setScheme('http');
        }

        if (isset($this->serverParams['QUERY_STRING'])) {
            $uri->setQuery($this->serverParams['QUERY_STRING']);
        }

        if ($this->headers()->get('host')) {
            //TODO handle IPv6 with port
            if (preg_match('|^([^:]+):([^:]+)$|', $this->headers()->get('host')->getFieldValue(), $match)) {
                $uri->setHost($match[1]);
                $uri->setPort($match[2]);
            } else {
                $uri->setHost($this->headers()->get('host')->getFieldValue());
            }
        } elseif (isset($this->serverParams['SERVER_NAME'])) {
            $uri->setHost($this->serverParams['SERVER_NAME']);
            if (isset($this->serverParams['SERVER_PORT'])) {
                $uri->setPort($this->serverParams['SERVER_PORT']);
            }
        }

        $requestUri = $this->getRequestUri();
        $uri->setPath(substr($requestUri, 0, strpos($requestUri, '?') ?: strlen($requestUri)));

        return $this;
    }
    /**
     * Provide an alternate Parameter Container implementation for server parameters in this object,
     * (this is NOT the primary API for value setting, for that see getServer())
     *
     * @param  ParametersInterface $server
     * @return Request
     */
    public function setServer(ParametersInterface $server)
    {
        $this->serverParams = $server;

        // This seems to be the only way to get the Authorization header on Apache
        if (function_exists('apache_request_headers')) {
            $apacheRequestHeaders = apache_request_headers();
            if (!isset($this->serverParams['HTTP_AUTHORIZATION'])) {
                if (isset($apacheRequestHeaders['Authorization'])) {
                    $this->serverParams->set('HTTP_AUTHORIZATION', $apacheRequestHeaders['Authorization']);
                } elseif (isset($apacheRequestHeaders['authorization'])) {
                    $this->serverParams->set('HTTP_AUTHORIZATION', $apacheRequestHeaders['authorization']);
                }
            }
        }

        // set headers
        $headers = array();

        foreach ($server as $key => $value) {
            if ($value && strpos($key, 'HTTP_') === 0) {
                if (strpos($key, 'HTTP_COOKIE') === 0) {
                    // Cookies are handled using the $_COOKIE superglobal
                    continue;
                }
                $name = strtr(substr($key, 5), '_', ' ');
                $name = strtr(ucwords(strtolower($name)), ' ', '-');
            } elseif ($value && strpos($key, 'CONTENT_') === 0) {
                $name = substr($key, 8); // Content-
                $name = 'Content-' . (($name == 'MD5') ? $name : ucfirst(strtolower($name)));
            } else {
                continue;
            }

            $headers[$name] = $value;
        }

        $this->getHeaders()->addHeaders($headers);

        // set method
        if (isset($this->serverParams['REQUEST_METHOD'])) {
            $this->setMethod($this->serverParams['REQUEST_METHOD']);
        }

        // set HTTP version
        if (isset($this->serverParams['SERVER_PROTOCOL'])
            && strpos($this->serverParams['SERVER_PROTOCOL'], self::VERSION_10) !== false
        ) {
            $this->setVersion(self::VERSION_10);
        }

        // set URI
        $uri = new HttpUri();

        // URI scheme
        $scheme = (!empty($this->serverParams['HTTPS'])
                   && $this->serverParams['HTTPS'] !== 'off') ? 'https' : 'http';
        $uri->setScheme($scheme);

        // URI host & port
        $host = null;
        $port = null;
        if (isset($this->serverParams['SERVER_NAME'])) {
            $host = $this->serverParams['SERVER_NAME'];
            if (isset($this->serverParams['SERVER_PORT'])) {
                $port = (int) $this->serverParams['SERVER_PORT'];
            }
            // Check for missinterpreted IPv6-Address
            // Reported at least for Safari on Windows
            if (isset($this->serverParams['SERVER_ADDR']) && preg_match('/^\[[0-9a-fA-F\:]+\]$/', $host)) {
                $host = '[' . $this->serverParams['SERVER_ADDR'] . ']';
                if ($port . ']' == substr($host, strrpos($host, ':')+1)) {
                    // The last digit of the IPv6-Address has been taken as port
                    // Unset the port so the default port can be used
                    $port = null;
                }
            }
        } elseif ($this->getHeaders()->get('host')) {
            $host = $this->getHeaders()->get('host')->getFieldValue();
            // works for regname, IPv4 & IPv6
            if (preg_match('|\:(\d+)$|', $host, $matches)) {
                $host = substr($host, 0, -1 * (strlen($matches[1]) + 1));
                $port = (int) $matches[1];
            }
        }
        $uri->setHost($host);
        $uri->setPort($port);

        // URI path
        $requestUri = $this->getRequestUri();
        if (($qpos = strpos($requestUri, '?')) !== false) {
            $requestUri = substr($requestUri, 0, $qpos);
        }

        $uri->setPath($requestUri);

        // URI query
        if (isset($this->serverParams['QUERY_STRING'])) {
            $uri->setQuery($this->serverParams['QUERY_STRING']);
        }

        $this->setUri($uri);

        return $this;
    }
예제 #5
0
 /**
  * Provide an alternate Parameter Container implementation for server parameters in this object, (this is NOT the
  * primary API for value setting, for that see server())
  *
  * @param \Zend\Stdlib\ParametersDescription $server
  * @return Request
  */
 public function setServer(ParametersDescription $server)
 {
     $this->serverParams = $server;
     $this->headers()->addHeaders($this->serverToHeaders($this->serverParams));
     if (isset($this->serverParams['REQUEST_METHOD'])) {
         $this->setMethod($this->serverParams['REQUEST_METHOD']);
     }
     if (isset($this->serverParams['SERVER_PROTOCOL']) && strpos($this->serverParams['SERVER_PROTOCOL'], '1.0') !== false) {
         $this->setVersion('1.0');
     }
     $this->setUri($uri = new HttpUri());
     if (isset($this->serverParams['HTTPS']) && $this->serverParams['HTTPS'] === 'on') {
         $uri->setScheme('https');
     } else {
         $uri->setScheme('http');
     }
     if (isset($this->serverParams['QUERY_STRING'])) {
         $uri->setQuery($this->serverParams['QUERY_STRING']);
     }
     if ($this->headers()->get('host')) {
         //TODO handle IPv6 with port
         if (preg_match('|^([^:]+):([^:]+)$|', $this->headers()->get('host')->getFieldValue(), $match)) {
             $uri->setHost($match[1]);
             $uri->setPort($match[2]);
         } else {
             $uri->setHost($this->headers()->get('host')->getFieldValue());
         }
     } elseif (isset($this->serverParams['SERVER_NAME'])) {
         $uri->setHost($this->serverParams['SERVER_NAME']);
         if (isset($this->serverParams['SERVER_PORT'])) {
             $uri->setPort($this->serverParams['SERVER_PORT']);
         }
     }
     $requestUri = $this->getRequestUri();
     $uri->setPath(substr($requestUri, 0, strpos($requestUri, '?') ?: strlen($requestUri)));
     return $this;
 }
예제 #6
0
파일: Request.php 프로젝트: moln/gzfextra
 public function setServer(ParametersInterface $server)
 {
     $this->serverParams = $server;
     // This seems to be the only way to get the Authorization header on Apache
     if (function_exists('apache_request_headers')) {
         $apacheRequestHeaders = apache_request_headers();
         if (!isset($this->serverParams['HTTP_AUTHORIZATION'])) {
             if (isset($apacheRequestHeaders['Authorization'])) {
                 $this->serverParams->set('HTTP_AUTHORIZATION', $apacheRequestHeaders['Authorization']);
             } elseif (isset($apacheRequestHeaders['authorization'])) {
                 $this->serverParams->set('HTTP_AUTHORIZATION', $apacheRequestHeaders['authorization']);
             }
         }
     }
     // set headers
     $headers = array();
     foreach ($server as $key => $value) {
         if ($value && strpos($key, 'HTTP_') === 0) {
             if (strpos($key, 'HTTP_COOKIE') === 0) {
                 // Cookies are handled using the $_COOKIE superglobal
                 continue;
             }
             $name = strtr(substr($key, 5), '_', ' ');
             $name = strtr(ucwords(strtolower($name)), ' ', '-');
         } elseif ($value && strpos($key, 'CONTENT_') === 0) {
             $name = substr($key, 8);
             // Content-
             $name = 'Content-' . ($name == 'MD5' ? $name : ucfirst(strtolower($name)));
         } else {
             continue;
         }
         $headers[$name] = $value;
     }
     $this->getHeaders()->addHeaders($headers);
     // set method
     if (isset($this->serverParams['REQUEST_METHOD'])) {
         $this->setMethod($this->serverParams['REQUEST_METHOD']);
     }
     // set HTTP version
     if (isset($this->serverParams['SERVER_PROTOCOL']) && strpos($this->serverParams['SERVER_PROTOCOL'], self::VERSION_10) !== false) {
         $this->setVersion(self::VERSION_10);
     }
     // set URI
     $uri = new HttpUri();
     // URI scheme
     if (!empty($this->serverParams['HTTPS']) && $this->serverParams['HTTPS'] !== 'off' || !empty($this->serverParams['HTTP_X_FORWARDED_PROTO']) && $this->serverParams['HTTP_X_FORWARDED_PROTO'] == 'https') {
         $scheme = 'https';
     } else {
         $scheme = 'http';
     }
     $uri->setScheme($scheme);
     // URI host & port
     $uri->setHost($this->serverParams['SERVER_NAME']);
     $uri->setPort($this->serverParams['SERVER_PORT']);
     // URI path
     if (isset($this->serverParams['REQUEST_URI'])) {
         $this->setRequestUri($this->serverParams['REQUEST_URI']);
     }
     $requestUri = $this->getRequestUri();
     if (($qpos = strpos($requestUri, '?')) !== false) {
         $requestUri = substr($requestUri, 0, $qpos);
     }
     $uri->setPath($requestUri);
     // URI query
     if (isset($this->serverParams['QUERY_STRING'])) {
         $uri->setQuery($this->serverParams['QUERY_STRING']);
     }
     $this->setUri($uri);
     return $this;
 }
 /**
  * @param Http $httpUri
  * @param int $offset
  * @param int $limit
  * @return array
  */
 protected function partiallyRequest(Http $httpUri, $offset, $limit)
 {
     $query = $httpUri->getQueryAsArray();
     $query['start'] = $offset;
     $query['count'] = $limit;
     $httpUri->setQuery($query);
     $elements = $this->mapper->fetchAll($httpUri->toString());
     $entityName = $this->classMetadata->getName();
     $entities = array();
     foreach ($elements as $element) {
         $hydrator = new EntityHydrator($this->classMetadata);
         $entities[] = $hydrator->hydrate($element, new $entityName());
     }
     return $entities;
 }