php Zend-Uri-Http类(方法)实例源码

下面列出了php Zend-Uri-Http 类(方法)源码代码实例,从而了解它的用法。

作者:utrenkne    项目:YAWI   
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);
 }

作者:Naszvadi    项目:ImageCM   
/**
  * @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;
 }

作者:namnv60    项目:Codeceptio   
/**
  * @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;
 }

作者:patrov    项目:omeka-   
/**
  * 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);
     }
 }

作者:hoangp    项目:nextcm   
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;
 }

作者:robertodormepoc    项目:zf   
/**
  * Return the URI for this header
  *
  * @return string
  */
 public function getUri()
 {
     if ($this->uri instanceof HttpUri) {
         return $this->uri->toString();
     }
     return $this->uri;
 }

作者:danielcost    项目:sellercenter-sd   
/**
  * @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;
 }

作者:bradley-hol    项目:zf   
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());
 }

作者:rstgrou    项目:oauth2-clien   
protected function isValid($value)
 {
     try {
         $uri = new Http($value);
         return $uri->isValid() && $uri->isAbsolute() && $uri->getFragment() === null;
     } catch (InvalidArgumentException $e) {
         return false;
     }
 }

作者:magiu    项目:MagiumMai   
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();
 }

作者:haoyanfe    项目:zf   
/**
  * @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());
 }

作者:stefanor    项目:zf2-fullpage-cach   
/**
  * @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));
 }

作者:aapth    项目:video-collection   
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);
 }

作者:patrov    项目:omeka-   
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);
         }
     }
 }

作者:JonathanConne    项目:SocialNe   
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);
 }

作者:pnaq5    项目:zf2dem   
/**
  * @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());
     }
 }

作者:rexma    项目:zf   
/**
  * 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.';
 }

作者:robborock    项目:ZendService_Amazo   
/**
  * 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);
 }

作者:patrov    项目:omeka-   
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;
 }

作者:solutionDriv    项目:Codeceptio   
/**
  * @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;
 }


问题


面经


文章

微信
公众号

扫码关注公众号