コード例 #1
1
ファイル: Import.php プロジェクト: utrenkner/YAWIK
 public function setData($data)
 {
     if ($data instanceof Traversable) {
         $data = ArrayUtils::iteratorToArray($data);
     }
     $isAts = isset($data['atsEnabled']) && $data['atsEnabled'];
     $isUri = isset($data['uriApply']) && !empty($data['uriApply']);
     $email = isset($data['contactEmail']) ? $data['contactEmail'] : '';
     if ($isAts && $isUri) {
         $data['atsMode']['mode'] = 'uri';
         $data['atsMode']['uri'] = $data['uriApply'];
         $uri = new Http($data['uriApply']);
         if ($uri->getHost() == $this->host) {
             $data['atsMode']['mode'] = 'intern';
         }
     } elseif ($isAts && !$isUri) {
         $data['atsMode']['mode'] = 'intern';
     } elseif (!$isAts && !empty($email)) {
         $data['atsMode']['mode'] = 'email';
         $data['atsMode']['email'] = $email;
     } else {
         $data['atsMode']['mode'] = 'none';
     }
     if (!array_key_exists('job', $data)) {
         $data = array('job' => $data);
     }
     return parent::setData($data);
 }
コード例 #2
0
ファイル: ZF2.php プロジェクト: NaszvadiG/ImageCMS
 /**
  * @param Request $request
  *
  * @return Response
  * @throws \Exception
  */
 public function doRequest($request)
 {
     $zendRequest = $this->application->getRequest();
     $zendResponse = $this->application->getResponse();
     $uri = new HttpUri($request->getUri());
     $queryString = $uri->getQuery();
     $method = $request->getMethod();
     if ($queryString) {
         parse_str($queryString, $query);
     }
     if ($method == HttpRequest::METHOD_POST) {
         $post = $request->getParameters();
         $zendRequest->setPost(new Parameters($post));
     } elseif ($method == HttpRequest::METHOD_GET) {
         $query = $request->getParameters();
         $zendRequest->setQuery(new Parameters($query));
     } elseif ($method == HttpRequest::METHOD_PUT) {
         $zendRequest->setContent($request->getContent());
     }
     $zendRequest->setMethod($method);
     $zendRequest->setUri($uri);
     $this->application->run();
     $this->zendRequest = $zendRequest;
     $exception = $this->application->getMvcEvent()->getParam('exception');
     if ($exception instanceof \Exception) {
         throw $exception;
     }
     $response = new Response($zendResponse->getBody(), $zendResponse->getStatusCode(), $zendResponse->getHeaders()->toArray());
     return $response;
 }
コード例 #3
0
ファイル: ZF2.php プロジェクト: namnv609/Codeception
 /**
  * @param Request $request
  *
  * @return Response
  * @throws \Exception
  */
 public function doRequest($request)
 {
     $zendRequest = $this->application->getRequest();
     $zendResponse = $this->application->getResponse();
     $zendResponse->setStatusCode(200);
     $uri = new HttpUri($request->getUri());
     $queryString = $uri->getQuery();
     $method = strtoupper($request->getMethod());
     $zendRequest->setCookies(new Parameters($request->getCookies()));
     if ($queryString) {
         parse_str($queryString, $query);
         $zendRequest->setQuery(new Parameters($query));
     }
     if ($request->getContent() !== null) {
         $zendRequest->setContent($request->getContent());
     } elseif ($method != HttpRequest::METHOD_GET) {
         $post = $request->getParameters();
         $zendRequest->setPost(new Parameters($post));
     }
     $zendRequest->setMethod($method);
     $zendRequest->setUri($uri);
     $zendRequest->setRequestUri(str_replace('http://localhost', '', $request->getUri()));
     $zendRequest->setHeaders($this->extractHeaders($request));
     $this->application->run();
     $this->zendRequest = $zendRequest;
     $exception = $this->application->getMvcEvent()->getParam('exception');
     if ($exception instanceof \Exception) {
         throw $exception;
     }
     $response = new Response($zendResponse->getBody(), $zendResponse->getStatusCode(), $zendResponse->getHeaders()->toArray());
     return $response;
 }
コード例 #4
0
ファイル: Url.php プロジェクト: patrova/omeka-s
 /**
  * Ingest from a URL.
  *
  * Accepts the following non-prefixed keys:
  *
  * + ingest_url: (required) The URL to ingest. The idea is that some URLs
  *   contain sensitive data that should not be saved to the database, such
  *   as private keys. To preserve the URL, remove sensitive data from the
  *   URL and set it to o:source.
  * + store_original: (optional, default true) Whether to store an original
  *   file. This is helpful when you want the media to have thumbnails but do
  *   not need the original file.
  *
  * {@inheritDoc}
  */
 public function ingest(Media $media, Request $request, ErrorStore $errorStore)
 {
     $data = $request->getContent();
     if (!isset($data['ingest_url'])) {
         $errorStore->addError('error', 'No ingest URL specified');
         return;
     }
     $uri = new HttpUri($data['ingest_url']);
     if (!($uri->isValid() && $uri->isAbsolute())) {
         $errorStore->addError('ingest_url', 'Invalid ingest URL');
         return;
     }
     $file = $this->getServiceLocator()->get('Omeka\\File');
     $file->setSourceName($uri->getPath());
     $this->downloadFile($uri, $file->getTempPath());
     $fileManager = $this->getServiceLocator()->get('Omeka\\File\\Manager');
     $hasThumbnails = $fileManager->storeThumbnails($file);
     $media->setHasThumbnails($hasThumbnails);
     if (!isset($data['store_original']) || $data['store_original']) {
         $fileManager->storeOriginal($file);
         $media->setHasOriginal(true);
     }
     $media->setFilename($file->getStorageName());
     $media->setMediaType($file->getMediaType());
     if (!array_key_exists('o:source', $data)) {
         $media->setSource($uri);
     }
 }
コード例 #5
0
ファイル: CdnTrait.php プロジェクト: hoangpt/nextcms
 protected function appendCdn($href)
 {
     $uri = new Http($href);
     if ($uri->getHost()) {
         return $href;
     }
     $servers = $this->cdnOptions['servers'];
     if (1 == count($servers)) {
         $server = $servers[0];
     } else {
         switch ($this->cdnOptions['method']) {
             case 'respective':
                 if (!isset($servers[static::$serverId])) {
                     static::$serverId = 0;
                 }
                 $server = $servers[static::$serverId];
                 static::$serverId++;
                 break;
                 // Get a random CDN server
             // Get a random CDN server
             case 'random':
             default:
                 $server = $servers[array_rand($servers)];
                 break;
         }
     }
     $href = rtrim($server, '/') . '/' . ltrim($href, '/');
     return $href;
 }
コード例 #6
0
 /**
  * Return the URI for this header
  *
  * @return string
  */
 public function getUri()
 {
     if ($this->uri instanceof HttpUri) {
         return $this->uri->toString();
     }
     return $this->uri;
 }
コード例 #7
0
 /**
  * @param string $uri
  *
  * @return ImageUri
  */
 public function setUri($uri)
 {
     $this->uri = new Http($uri);
     if (!$this->uri->isAbsolute()) {
         throw new \InvalidArgumentException('Invalid image URL: ' . $this->uri->toString());
     }
     return $this;
 }
コード例 #8
0
ファイル: SchemeTest.php プロジェクト: bradley-holt/zf2
 public function testAssembling()
 {
     $uri = new HttpUri();
     $route = new Scheme('https');
     $path = $route->assemble(array(), array('uri' => $uri));
     $this->assertEquals('', $path);
     $this->assertEquals('https', $uri->getScheme());
 }
コード例 #9
0
 protected function isValid($value)
 {
     try {
         $uri = new Http($value);
         return $uri->isValid() && $uri->isAbsolute() && $uri->getFragment() === null;
     } catch (InvalidArgumentException $e) {
         return false;
     }
 }
コード例 #10
0
ファイル: Configuration.php プロジェクト: magium/MagiumMail
 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();
 }
コード例 #11
0
ファイル: HostnameTest.php プロジェクト: haoyanfei/zf2
 /**
  * @dataProvider routeProvider
  * @param        Hostname $route
  * @param        string   $hostname
  * @param        array    $params
  */
 public function testAssembling(Hostname $route, $hostname, array $params = null)
 {
     if ($params === null) {
         // Data which will not match are not tested for assembling.
         return;
     }
     $uri = new HttpUri();
     $path = $route->assemble($params, array('uri' => $uri));
     $this->assertEquals('', $path);
     $this->assertEquals($hostname, $uri->getHost());
 }
コード例 #12
0
 /**
  * @param array  $regexpes
  * @param string $uriPath
  * @param bool   $expectedResult
  * @dataProvider shouldCacheProvider
  */
 public function testShouldCache($regexpes, $uriPath, $expectedResult)
 {
     $this->strategy->setRegexpes($regexpes);
     $mvcEvent = new MvcEvent();
     $request = new HttpRequest();
     $uri = new Http();
     $uri->setPath($uriPath);
     $request->setUri($uri);
     $mvcEvent->setRequest($request);
     $this->assertEquals($expectedResult, $this->strategy->shouldCache($mvcEvent));
 }
コード例 #13
0
 public function testUseRequestBaseUrl()
 {
     $this->configureRoute();
     $httpUri = new HttpUri();
     $httpUri->setScheme('http');
     $httpUri->setHost('use-request-uri.com');
     $request = $this->serviceManager->get('Request');
     $request->setUri($httpUri);
     $request->setBaseUrl('/another/base/url/');
     $baseUrl = $this->factory->getBaseUrl($this->serviceManager);
     $this->assertEquals('http://use-request-uri.com/another/base/url/scn-social-auth/hauth', $baseUrl);
 }
コード例 #14
0
ファイル: IIIF.php プロジェクト: patrova/omeka-s
 public function ingest(Media $media, Request $request, ErrorStore $errorStore)
 {
     $data = $request->getContent();
     if (!isset($data['o:source'])) {
         $errorStore->addError('o:source', 'No IIIF Image URL specified');
         return;
     }
     $source = $data['o:source'];
     //Make a request and handle any errors that might occur.
     $uri = new HttpUri($source);
     if (!($uri->isValid() && $uri->isAbsolute())) {
         $errorStore->addError('o:source', "Invalid url specified");
         return false;
     }
     $client = $this->getServiceLocator()->get('Omeka\\HttpClient');
     $client->setUri($uri);
     $response = $client->send();
     if (!$response->isOk()) {
         $errorStore->addError('o:source', sprintf("Error reading %s: %s (%s)", $type, $response->getReasonPhrase(), $response->getStatusCode()));
         return false;
     }
     $IIIFData = json_decode($response->getBody(), true);
     if (!$IIIFData) {
         $errorStore->addError('o:source', 'Error decoding IIIF JSON');
         return;
     }
     //Check if valid IIIF data
     if ($this->validate($IIIFData)) {
         $media->setData($IIIFData);
         // Not IIIF
     } else {
         $errorStore->addError('o:source', 'URL does not link to IIIF JSON');
         return;
     }
     //Check API version and generate a thumbnail
     //Version 2.0
     if (isset($IIIFData['@context']) && $IIIFData['@context'] == 'http://iiif.io/api/image/2/context.json') {
         $URLString = '/full/full/0/default.jpg';
         // Earlier versions
     } else {
         $URLString = '/full/full/0/native.jpg';
     }
     if (isset($IIIFData['@id'])) {
         $fileManager = $this->getServiceLocator()->get('Omeka\\File\\Manager');
         $file = $this->getServiceLocator()->get('Omeka\\File');
         $this->downloadFile($IIIFData['@id'] . $URLString, $file->getTempPath());
         $hasThumbnails = $fileManager->storeThumbnails($file);
         if ($hasThumbnails) {
             $media->setFilename($file->getStorageName());
             $media->setHasThumbnails(true);
         }
     }
 }
コード例 #15
0
 public function __invoke()
 {
     $request = $this->getController()->getRequest();
     if ('https' === $request->getUri()->getScheme()) {
         return;
     }
     // Not secure, create full url
     $plugin = $this->getController()->url();
     $url = $plugin->fromRoute(null, array(), array('force_canonical' => true), true);
     $url = new HttpUri($url);
     $url->setScheme('https');
     return $this->getController()->redirect()->toUrl($url);
 }
コード例 #16
0
ファイル: QueryTest.php プロジェクト: pnaq57/zf2demo
 /**
  * @param        Query $route
  * @param        string   $path
  * @param        integer  $offset
  * @param        array    $params
  * @param        boolean  $skipAssembling
  */
 public function testAssembling(Query $route, $path, $offset, array $params = null, $skipAssembling = false)
 {
     if ($params === null || $skipAssembling) {
         // Data which will not match are not tested for assembling.
         return;
     }
     $uri = new Http();
     $result = $route->assemble($params, array('uri' => $uri));
     if ($offset !== null) {
         $this->assertEquals($offset, strpos($path, $uri->getQuery(), $offset));
     } else {
         $this->assertEquals($path, $uri->getQuery());
     }
 }
コード例 #17
0
 /**
  * Send request to the proxy server with streaming support
  *
  * @param string        $method
  * @param \Zend\Uri\Http $uri
  * @param string        $http_ver
  * @param array         $headers
  * @param string        $body
  * @return string Request as string
  */
 public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
 {
     // If no proxy is set, throw an error
     if (!$this->config['proxy_host']) {
         throw new Adapter\Exception('No proxy host set!');
     }
     // Make sure we're properly connected
     if (!$this->socket) {
         throw new Adapter\Exception('Trying to write but we are not connected');
     }
     $host = $this->config['proxy_host'];
     $port = $this->config['proxy_port'];
     if ($this->connected_to[0] != $host || $this->connected_to[1] != $port) {
         throw new Adapter\Exception('Trying to write but we are connected to the wrong proxy ' . 'server');
     }
     // Add Proxy-Authorization header
     if ($this->config['proxy_user'] && !isset($headers['proxy-authorization'])) {
         $headers['proxy-authorization'] = \Zend\Http\Client::encodeAuthHeader($this->config['proxy_user'], $this->config['proxy_pass'], $this->config['proxy_auth']);
     }
     // if we are proxying HTTPS, preform CONNECT handshake with the proxy
     if ($uri->getScheme() == 'https' && !$this->negotiated) {
         $this->connectHandshake($uri->getHost(), $uri->getPort(), $http_ver, $headers);
         $this->negotiated = true;
     }
     // Save request method for later
     $this->method = $method;
     // Build request headers
     $request = "{$method} {$uri->__toString()} HTTP/{$http_ver}\r\n";
     // Add all headers to the request string
     foreach ($headers as $k => $v) {
         if (is_string($k)) {
             $v = "{$k}: {$v}";
         }
         $request .= "{$v}\r\n";
     }
     $request .= "\r\n";
     // Send the request headers
     if (!@fwrite($this->socket, $request)) {
         throw new Adapter\Exception('Error writing request to proxy server');
     }
     //read from $body, write to socket
     while ($body->hasData()) {
         if (!@fwrite($this->socket, $body->read(self::CHUNK_SIZE))) {
             throw new Adapter\Exception('Error writing request to server');
         }
     }
     return 'Large upload, request is not cached.';
 }
コード例 #18
0
ファイル: RestClient.php プロジェクト: rexmac/zf2
 /**
  * Method call overload
  *
  * Allows calling REST actions as object methods; however, you must
  * follow-up by chaining the request with a request to an HTTP request
  * method (post, get, delete, put):
  * <code>
  * $response = $rest->sayHello('Foo', 'Manchu')->get();
  * </code>
  *
  * Or use them together, but in sequential calls:
  * <code>
  * $rest->sayHello('Foo', 'Manchu');
  * $response = $rest->get();
  * </code>
  *
  * @param string $method Method name
  * @param array $args Method args
  * @return \Zend\Rest\Client\RestClient_Result|\Zend\Rest\Client\RestClient \Zend\Rest\Client\RestClient if using
  * a remote method, Zend_Rest_Client_Result if using an HTTP request method
  */
 public function __call($method, $args)
 {
     $methods = array('post', 'get', 'delete', 'put');
     if (in_array(strtolower($method), $methods)) {
         if (!isset($args[0])) {
             $args[0] = $this->_uri->getPath();
         }
         $this->_data['rest'] = 1;
         $data = array_slice($args, 1) + $this->_data;
         $response = $this->{'rest' . $method}($args[0], $data);
         $this->_data = array();
         //Initializes for next Rest method.
         return new Result($response->getBody());
     } else {
         // More than one arg means it's definitely a Zend_Rest_Server
         if (sizeof($args) == 1) {
             // Uses first called function name as method name
             if (!isset($this->_data['method'])) {
                 $this->_data['method'] = $method;
                 $this->_data['arg1'] = $args[0];
             }
             $this->_data[$method] = $args[0];
         } else {
             $this->_data['method'] = $method;
             if (sizeof($args) > 0) {
                 foreach ($args as $key => $arg) {
                     $key = 'arg' . $key;
                     $this->_data[$key] = $arg;
                 }
             }
         }
         return $this;
     }
 }
コード例 #19
0
 /**
  * Test create bucket
  *
  * @return void
  */
 public function testCreateBuckets()
 {
     //Valid bucket name
     $bucket = 'iamavalidbucket';
     $location = '';
     $accessKey = 'AKIAIDCZ2WXN6NNB7YZA';
     $secretKey = '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';
     $requestDate = DateTime::createFromFormat(DateTime::RFC1123, 'Tue, 15 May 2012 15:18:31 +0000');
     $this->amazon->setRequestDate($requestDate);
     $this->amazon->setKeys($accessKey, $secretKey);
     //Fake keys
     /**
      * Check of request inside _makeRequest
      *
      */
     $this->uriHttp->expects($this->once())->method('getHost')->with()->will($this->returnValue('s3.amazonaws.com'));
     $this->uriHttp->expects($this->once())->method('setHost')->with('iamavalidbucket.s3.amazonaws.com');
     $this->uriHttp->expects($this->once())->method('setPath')->with('/');
     $this->httpClient->expects($this->once())->method('setUri')->with($this->uriHttp);
     $this->httpClient->expects($this->once())->method('setMethod')->with('PUT');
     $this->httpClient->expects($this->once())->method('setHeaders')->with(array("Date" => "Tue, 15 May 2012 15:18:31 +0000", "Content-Type" => "application/xml", "Authorization" => "AWS " . $accessKey . ":Y+T4nZxI1wBi1Yn1BMnOK9CDiOM="));
     /**
      * Fake response inside _makeRequest
      *
      */
     // Http Response results
     $this->httpResponse->expects($this->any())->method('getStatusCode')->will($this->returnValue(200));
     // Expects to be called only once the method send() then return a Http Response.
     $this->httpClient->expects($this->once())->method('send')->will($this->returnValue($this->httpResponse));
     $response = $this->amazon->createBucket($bucket, $location);
     $this->assertTrue($response);
 }
コード例 #20
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;
 }
コード例 #21
0
    /**
     * assemble(): defined by RouteInterface interface.
     *
     * @see    BaseRoute::assemble()
     * @param  array $params
     * @param  array $options
     * @return mixed
     * @throws Exception\ExceptionInterface
     */
    public function assemble(array $params = array(), array $options = array())
    {
        if (!isset($options['name'])) {
            throw new Exception\InvalidArgumentException('Missing "name" option');
        }

        $names = explode('/', $options['name'], 2);
        $route = $this->routes->get($names[0]);

        if (!$route) {
            throw new Exception\RuntimeException(sprintf('Route with name "%s" not found', $names[0]));
        }

        if (isset($names[1])) {
            $options['name'] = $names[1];
        } else {
            unset($options['name']);
        }

        if (!isset($options['only_return_path']) || !$options['only_return_path']) {
            if (!isset($options['uri'])) {
                $uri = new HttpUri();

                if (isset($options['force_canonical']) && $options['force_canonical']) {
                    if ($this->requestUri === null) {
                        throw new Exception\RuntimeException('Request URI has not been set');
                    }

                    $uri->setScheme($this->requestUri->getScheme())
                        ->setHost($this->requestUri->getHost())
                        ->setPort($this->requestUri->getPort());
                }

                $options['uri'] = $uri;
            } else {
                $uri = $options['uri'];
            }

            $path = $this->baseUrl . $route->assemble(array_merge($this->defaultParams, $params), $options);

            if ((isset($options['force_canonical']) && $options['force_canonical']) || $uri->getHost() !== null) {
                if ($uri->getScheme() === null) {
                    if ($this->requestUri === null) {
                        throw new Exception\RuntimeException('Request URI has not been set');
                    }

                    $uri->setScheme($this->requestUri->getScheme());
                }

                return $uri->setPath($path)->toString();
            } elseif (!$uri->isAbsolute() && $uri->isValidRelative()) {
                return $uri->setPath($path)->toString();
            }
        }

        return $this->baseUrl . $route->assemble(array_merge($this->defaultParams, $params), $options);
    }
コード例 #22
0
ファイル: ZF2.php プロジェクト: solutionDrive/Codeception
 /**
  * @param Request $request
  *
  * @return Response
  * @throws \Exception
  */
 public function doRequest($request)
 {
     $this->createApplication();
     $zendRequest = $this->application->getRequest();
     $uri = new HttpUri($request->getUri());
     $queryString = $uri->getQuery();
     $method = strtoupper($request->getMethod());
     $zendRequest->setCookies(new Parameters($request->getCookies()));
     $query = [];
     $post = [];
     $content = $request->getContent();
     if ($queryString) {
         parse_str($queryString, $query);
     }
     if ($method !== HttpRequest::METHOD_GET) {
         $post = $request->getParameters();
     }
     $zendRequest->setQuery(new Parameters($query));
     $zendRequest->setPost(new Parameters($post));
     $zendRequest->setFiles(new Parameters($request->getFiles()));
     $zendRequest->setContent($content);
     $zendRequest->setMethod($method);
     $zendRequest->setUri($uri);
     $requestUri = $uri->getPath();
     if (!empty($queryString)) {
         $requestUri .= '?' . $queryString;
     }
     $zendRequest->setRequestUri($requestUri);
     $zendRequest->setHeaders($this->extractHeaders($request));
     $this->application->run();
     // get the response *after* the application has run, because other ZF
     //     libraries like API Agility may *replace* the application's response
     //
     $zendResponse = $this->application->getResponse();
     $this->zendRequest = $zendRequest;
     $exception = $this->application->getMvcEvent()->getParam('exception');
     if ($exception instanceof \Exception) {
         throw $exception;
     }
     $response = new Response($zendResponse->getBody(), $zendResponse->getStatusCode(), $zendResponse->getHeaders()->toArray());
     return $response;
 }
コード例 #23
0
ファイル: DotNet.php プロジェクト: razvansividra/pnlzf2-1
 /**
  * Do request proxy method.
  *
  * @param  CommonClient $client   Actual SOAP client.
  * @param  string       $request  The request body.
  * @param  string       $location The SOAP URI.
  * @param  string       $action   The SOAP action to call.
  * @param  integer      $version  The SOAP version to use.
  * @param  integer      $one_way  (Optional) The number 1 if a response is not expected.
  * @return string The XML SOAP response.
  */
 public function _doRequest(CommonClient $client, $request, $location, $action, $version, $one_way = null)
 {
     if (!$this->useNtlm) {
         return parent::_doRequest($client, $request, $location, $action, $version, $one_way);
     }
     $curlClient = $this->getCurlClient();
     $headers = array('Content-Type' => 'text/xml; charset=utf-8', 'Method' => 'POST', 'SOAPAction' => '"' . $action . '"', 'User-Agent' => 'PHP-SOAP-CURL');
     $uri = new HttpUri($location);
     $curlClient->setCurlOption(CURLOPT_HTTPAUTH, CURLAUTH_NTLM)->setCurlOption(CURLOPT_SSL_VERIFYHOST, false)->setCurlOption(CURLOPT_SSL_VERIFYPEER, false)->setCurlOption(CURLOPT_USERPWD, $this->options['login'] . ':' . $this->options['password']);
     // Perform the cURL request and get the response
     $curlClient->connect($uri->getHost(), $uri->getPort());
     $curlClient->write('POST', $uri, 1.1, $headers, $request);
     $response = HttpResponse::fromString($curlClient->read());
     $curlClient->close();
     // Save headers
     $this->lastRequestHeaders = $this->flattenHeaders($headers);
     $this->lastResponseHeaders = $response->getHeaders()->toString();
     // Return only the XML body
     return $response->getBody();
 }
コード例 #24
0
 public function filter($html)
 {
     $baseUri = new Http($this->uri);
     $dom = new Query($html);
     $results = $dom->execute('*[@href],*[@src]');
     foreach ($results as $result) {
         $attributeMap = $result->attributes;
         foreach ($attributeMap as $attribute) {
             $name = $attribute->name;
             if ($name == 'href' || $name == 'src') {
                 $value = $result->getAttribute($name);
                 $uri = new Http($value);
                 $h = $uri->resolve($baseUri);
                 $result->setAttribute($name, $h);
             }
         }
     }
     $document = $results->getDocument();
     $documentHTML = $document->saveHTML();
     return $documentHTML;
 }
コード例 #25
0
ファイル: ZF2.php プロジェクト: alexanderkuz/test-yii2
 /**
  * @param Request $request
  *
  * @return Response
  * @throws \Exception
  */
 public function doRequest($request)
 {
     $zendRequest = $this->application->getRequest();
     $zendResponse = $this->application->getResponse();
     $zendHeaders = $zendRequest->getHeaders();
     if (!$zendHeaders->has('Content-Type')) {
         $server = $request->getServer();
         if (isset($server['CONTENT_TYPE'])) {
             $zendHeaders->addHeaderLine('Content-Type', $server['CONTENT_TYPE']);
         }
     }
     $zendResponse->setStatusCode(200);
     $uri = new HttpUri($request->getUri());
     $queryString = $uri->getQuery();
     $method = strtoupper($request->getMethod());
     $zendRequest->setCookies(new Parameters($request->getCookies()));
     if ($queryString) {
         parse_str($queryString, $query);
         $zendRequest->setQuery(new Parameters($query));
     }
     if ($method == HttpRequest::METHOD_POST) {
         $post = $request->getParameters();
         $zendRequest->setPost(new Parameters($post));
     } elseif ($method == HttpRequest::METHOD_PUT) {
         $zendRequest->setContent($request->getContent());
     }
     $zendRequest->setMethod($method);
     $zendRequest->setUri($uri);
     $this->application->run();
     $this->zendRequest = $zendRequest;
     $exception = $this->application->getMvcEvent()->getParam('exception');
     if ($exception instanceof \Exception) {
         throw $exception;
     }
     $response = new Response($zendResponse->getBody(), $zendResponse->getStatusCode(), $zendResponse->getHeaders()->toArray());
     return $response;
 }
コード例 #26
0
ファイル: SslListener.php プロジェクト: gotcms/gotcms
 /**
  * Check if ssl is forced or not
  *
  * @param EventInterface $event Mvc event
  *
  * @return null|Zend\Http\PhpEnvironment\Response
  */
 public function check(EventInterface $event)
 {
     $coreConfig = $event->getApplication()->getServiceManager()->get('CoreConfig');
     $matchedRouteName = $event->getRouteMatch()->getMatchedRouteName();
     $request = $event->getRequest();
     $uri = $request->getUri();
     if ($matchedRouteName === 'cms') {
         if ($uri->getScheme() === 'https' or $coreConfig->getValue('force_frontend_ssl')) {
             $newUri = new Uri($coreConfig->getValue('secure_frontend_base_path'));
             $newUri->setScheme('https');
         } else {
             $newUri = new Uri($coreConfig->getValue('unsecure_frontend_base_path'));
         }
     } else {
         if ($uri->getScheme() === 'https' or $coreConfig->getValue('force_backend_ssl')) {
             $newUri = new Uri($coreConfig->getValue('secure_backend_base_path'));
             $newUri->setScheme('https');
         } else {
             $newUri = new Uri($coreConfig->getValue('unsecure_backend_base_path'));
         }
     }
     if (!empty($newUri) and $newUri->isValid() and ($newUri->getHost() != '' and $uri->getHost() != $newUri->getHost()) or $newUri->getScheme() != '' and $uri->getScheme() != $newUri->getScheme()) {
         $uri->setPort($newUri->getPort());
         if ($newUri->getHost() != '') {
             $uri->setHost($newUri->getHost());
         }
         if ($newUri->getScheme() != '') {
             $uri->setScheme($newUri->getScheme());
         }
         $response = $event->getResponse();
         $response->setStatusCode(302);
         $response->getHeaders()->addHeaderLine('Location', $request->getUri());
         $event->stopPropagation();
         return $response;
     }
 }
コード例 #27
0
ファイル: Youtube.php プロジェクト: patrova/omeka-s
 public function ingest(Media $media, Request $request, ErrorStore $errorStore)
 {
     $data = $request->getContent();
     if (!isset($data['o:source'])) {
         $errorStore->addError('o:source', 'No YouTube URL specified');
         return;
     }
     $uri = new HttpUri($data['o:source']);
     if (!($uri->isValid() && $uri->isAbsolute())) {
         $errorStore->addError('o:source', 'Invalid YouTube URL specified');
         return;
     }
     switch ($uri->getHost()) {
         case 'www.youtube.com':
             if ('/watch' !== $uri->getPath()) {
                 $errorStore->addError('o:source', 'Invalid YouTube URL specified, missing "/watch" path');
                 return;
             }
             $query = $uri->getQueryAsArray();
             if (!isset($query['v'])) {
                 $errorStore->addError('o:source', 'Invalid YouTube URL specified, missing "v" parameter');
                 return;
             }
             $youtubeId = $query['v'];
             break;
         case 'youtu.be':
             $youtubeId = substr($uri->getPath(), 1);
             break;
         default:
             $errorStore->addError('o:source', 'Invalid YouTube URL specified, not a YouTube URL');
             return;
     }
     $fileManager = $this->getServiceLocator()->get('Omeka\\File\\Manager');
     $file = $this->getServiceLocator()->get('Omeka\\File');
     $url = sprintf('http://img.youtube.com/vi/%s/0.jpg', $youtubeId);
     $this->downloadFile($url, $file->getTempPath());
     $hasThumbnails = $fileManager->storeThumbnails($file);
     $media->setData(['id' => $youtubeId, 'start' => $request->getValue('start'), 'end' => $request->getValue('end')]);
     if ($hasThumbnails) {
         $media->setFilename($file->getStorageName());
         $media->setHasThumbnails(true);
     }
 }
コード例 #28
0
 /**
  * Send request to the remote server with streaming support.
  *
  * @param string        $method
  * @param \Zend\Uri\Http $uri
  * @param string        $http_ver
  * @param array         $headers
  * @param string        $body
  * @return string Request as string
  */
 public function write($method, $uri, $http_ver = '1.1', $headers = array(), $body = '')
 {
     // Make sure we're properly connected
     if (!$this->socket) {
         throw new Adapter\Exception('Trying to write but we are not connected');
     }
     $host = $uri->getHost();
     $host = (strtolower($uri->getScheme()) == 'https' ? $this->config['ssltransport'] : 'tcp') . '://' . $host;
     if ($this->connected_to[0] != $host || $this->connected_to[1] != $uri->getPort()) {
         throw new Adapter\Exception('Trying to write but we are connected to the wrong host');
     }
     // Save request method for later
     $this->method = $method;
     // Build request headers
     $path = $uri->getPath();
     if ($uri->getQuery()) {
         $path .= '?' . $uri->getQuery();
     }
     $request = "{$method} {$path} HTTP/{$http_ver}\r\n";
     foreach ($headers as $k => $v) {
         if (is_string($k)) {
             $v = ucfirst($k) . ": {$v}";
         }
         $request .= "{$v}\r\n";
     }
     // Send the headers over
     $request .= "\r\n";
     if (!@fwrite($this->socket, $request)) {
         throw new Adapter\Exception('Error writing request to server');
     }
     //read from $body, write to socket
     $chunk = $body->read(self::CHUNK_SIZE);
     while ($chunk !== FALSE) {
         if (!@fwrite($this->socket, $chunk)) {
             throw new Adapter\Exception('Error writing request to server');
         }
         $chunk = $body->read(self::CHUNK_SIZE);
     }
     $body->closeFileHandle();
     return 'Large upload, request is not cached.';
 }
コード例 #29
0
ファイル: UrlBuilder.php プロジェクト: hoangpt/nextcms
 public function __invoke($routeName, $params = [], $excludedParams = [])
 {
     /** @var \Zend\View\HelperPluginManager $helperManager */
     $helperManager = $this->serviceLocator;
     /** @var \Zend\ServiceManager\ServiceManager $locator */
     $locator = $helperManager->getServiceLocator();
     /** @var \Zend\Mvc\Router\SimpleRouteStack $router */
     $router = $locator->get('Router');
     $assembledParams = [];
     if ($router->hasRoute($routeName)) {
         /** @var \Zend\Mvc\Router\Http\RouteInterface $route */
         $route = $router->getRoute($routeName);
         $assembledParams = $route->getAssembledParams();
     }
     /** @var \Zend\Http\PhpEnvironment\Request $request */
     $request = $locator->get('request');
     $uri = clone $request->getUri();
     $query = [];
     foreach (array_merge($uri->getQueryAsArray(), $params) as $key => $value) {
         if ($value != '') {
             $query[$key] = $value;
         }
     }
     $uri->setQuery($query);
     /** @var \Zend\View\Helper\Url $urlViewHelper */
     $urlViewHelper = $this->view->plugin('url');
     $return = $urlViewHelper->__invoke($routeName, $query);
     $query = $uri->getQueryAsArray();
     foreach ($uri->getQueryAsArray() as $key => $value) {
         if (in_array($key, $assembledParams) || in_array($key, $excludedParams)) {
             unset($query[$key]);
         }
     }
     $uri->setQuery($query);
     return count($query) == 0 ? $return : $return . '?' . Http::encodeQueryFragment($uri->getQuery());
 }
コード例 #30
0
 public function testAssembleCanonicalUriWithHostnameRouteAndRequestUriWithoutScheme()
 {
     $uri = new HttpUri();
     $uri->setScheme('http');
     $stack = new TreeRouteStack();
     $stack->setRequestUri($uri);
     $stack->addRoute('foo', new Hostname('example.com'));
     $this->assertEquals('http://example.com', $stack->assemble(array(), array('name' => 'foo')));
 }