当前位置: 首页>>代码示例>>PHP>>正文


PHP Request::setUri方法代码示例

本文整理汇总了PHP中Zend\Http\Request::setUri方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::setUri方法的具体用法?PHP Request::setUri怎么用?PHP Request::setUri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Zend\Http\Request的用法示例。


在下文中一共展示了Request::setUri方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: forwardAction

 public function forwardAction()
 {
     $alias = $this->params('alias');
     $instance = $this->getInstanceManager()->getInstanceFromRequest();
     try {
         $location = $this->aliasManager->findCanonicalAlias($alias, $instance);
         $this->redirect()->toUrl($location);
         $this->getResponse()->setStatusCode(301);
         return false;
     } catch (CanonicalUrlNotFoundException $e) {
     }
     try {
         $source = $this->aliasManager->findSourceByAlias($alias);
     } catch (AliasNotFoundException $e) {
         $this->getResponse()->setStatusCode(404);
         return false;
     }
     $router = $this->getServiceLocator()->get('Router');
     $request = new Request();
     $request->setMethod(Request::METHOD_GET);
     $request->setUri($source);
     $routeMatch = $router->match($request);
     if ($routeMatch === null) {
         $this->getResponse()->setStatusCode(404);
         return false;
     }
     $this->getEvent()->setRouteMatch($routeMatch);
     $params = $routeMatch->getParams();
     $controller = $params['controller'];
     $return = $this->forward()->dispatch($controller, ArrayUtils::merge($params, ['forwarded' => true]));
     return $return;
 }
开发者ID:andreas-serlo,项目名称:athene2,代码行数:32,代码来源:AliasController.php

示例2: findRegion

 public function findRegion($country, $query)
 {
     $request = new Request();
     $request->setMethod(Request::METHOD_GET);
     foreach ($query as $key => $value) {
         $request->getQuery()->set($key, $value);
     }
     $request->getHeaders()->addHeaderLine('Accept', 'application/json');
     switch ($country) {
         case 'CH':
             $request->setUri($this->config['url'] . '/ch-region');
             break;
         default:
             $request->setUri($this->config['url'] . '/ch-region');
             break;
     }
     $client = new Client();
     $response = $client->send($request);
     $body = $response->getBody();
     $result = json_decode($body, true);
     if ($result) {
         return $result['_embedded']['ch_region'];
     }
     /*echo "<textarea cols='100' rows='30' style='position:relative; z-index:10000; width:inherit; height:200px;'>";
       print_r($body);
       echo "</textarea>";
       die();*/
     return null;
 }
开发者ID:omusico,项目名称:casawp,代码行数:29,代码来源:GeoService.php

示例3: testQuery

 /**
  * @covers JmlHelpers\View\Helper\QueryParams
  */
 public function testQuery()
 {
     $helper = new QueryParams();
     $helper->setServiceLocator($this->pluginManager);
     $this->request->setUri('http://example.com');
     $values = $helper->__invoke();
     $this->assertEquals($values, array());
     $this->request->setUri('http://example.com?foo=bar&snafu=baz');
     $values = $helper->__invoke();
     $this->assertEquals($values, array('foo' => 'bar', 'snafu' => 'baz'));
     $this->request->setUri('http://example.com?foo=&snafu=baz');
     $values = $helper->__invoke();
     $this->assertEquals($values, array('foo' => '', 'snafu' => 'baz'));
 }
开发者ID:jmleroux,项目名称:jmlzf-helpers,代码行数:17,代码来源:QueryParamsTest.php

示例4: getIpInfo

 /**
  * @param $ipString
  * @return IdentityInformation
  * @throws \Zend\Validator\Exception\InvalidArgumentException
  */
 public function getIpInfo($ipString)
 {
     $ipValidator = new Ip();
     if (!$ipValidator->isValid($ipString)) {
         throw new InvalidArgumentException();
     }
     // creating request object
     $request = new Request();
     $request->setUri($this->endPoint . $ipString . '/json');
     $client = new Client();
     $adapter = new Client\Adapter\Curl();
     $adapter->setCurlOption(CURLOPT_TIMEOUT_MS, 500);
     $client->setAdapter($adapter);
     $response = $client->send($request);
     $data = $response->getBody();
     $dataArray = json_decode($data);
     $identityInformation = new IdentityInformation();
     $identityInformation->setCountry(isset($dataArray->country) ? $dataArray->country : '');
     $identityInformation->setRegion(isset($dataArray->region) ? $dataArray->region : '');
     $identityInformation->setCity(isset($dataArray->city) ? $dataArray->city : '');
     $identityInformation->setLocation(isset($dataArray->loc) ? $dataArray->loc : '');
     $identityInformation->setProvider(isset($dataArray->org) ? $dataArray->org : '');
     $identityInformation->setHostName(isset($dataArray->hostname) ? $dataArray->hostname : '');
     return $identityInformation;
 }
开发者ID:arbi,项目名称:MyCode,代码行数:30,代码来源:IpInfo.php

示例5: request

 /**
  * @inheritdoc
  */
 public function request(array $params)
 {
     try {
         $request = new Request();
         $headers = $request->getHeaders();
         $request->setUri($params['url']);
         $headers->addHeaderLine('Accept-Encoding', 'gzip,deflate');
         if ($params['config']->isAuthenticationPossible() === true && $this->option['keys']['public'] !== null && $this->option['keys']['private'] !== null) {
             /**
              * Note: DATE_RFC1123 my not be RFC 1123 compliant, depending on your platform.
              * @link http://www.php.net/manual/de/function.gmdate.php#25031
              */
             $date = gmdate('D, d M Y H:i:s \\G\\M\\T');
             $path = $request->getUri()->getPath();
             $headers->addHeaderLine('Date', $date);
             $headers->addHeaderLine('Authorization', $this->signRequest('GET', $date, $path));
         }
         if (isset($params['lastmodified'])) {
             $headers->addHeaderLine('If-Modified-Since', $params['lastmodified']);
         }
         $response = $this->client->send($request);
         $body = $response->getBody();
         $headers = null;
         if ($this->option['responseheader']) {
             $headers = $response->getHeaders()->toArray();
             $this->lastResponseHeaders = $headers;
         }
     } catch (\Exception $e) {
         throw new ClientException('Client exception catched, use getPrevious().', 0, $e);
     }
     return $this->createResponse($params['config']->isJson(), $response->getStatusCode(), $body, $headers);
 }
开发者ID:coss,项目名称:bnetlib,代码行数:35,代码来源:ZendFramework.php

示例6: matchUri

 public function matchUri($uri)
 {
     $request = new Request();
     $request->setUri($uri);
     $request->setMethod('post');
     return $this->getRouter()->match($request);
 }
开发者ID:andreas-serlo,项目名称:athene2,代码行数:7,代码来源:Router.php

示例7: testMatching

 /**
  * @dataProvider routeProvider
  * @param        Query $route
  * @param        string   $path
  * @param        integer  $offset
  * @param        array    $params
  */
 public function testMatching(Query $route, $path, $offset, array $params = null)
 {
     $request = new Request();
     $request->setUri('http://example.com?' . $path);
     $match = $route->match($request, $offset);
     $this->assertInstanceOf('Zend\Mvc\Router\RouteMatch', $match);
 }
开发者ID:benivaldo,项目名称:zf2-na-pratica,代码行数:14,代码来源:QueryTest.php

示例8: pharAction

 public function pharAction()
 {
     $client = $this->serviceLocator->get('zendServerClient');
     $client = new Client();
     if (defined('PHAR')) {
         // the file from which the application was started is the phar file to replace
         $file = $_SERVER['SCRIPT_FILENAME'];
     } else {
         $file = dirname($_SERVER['SCRIPT_FILENAME']) . '/zs-client.phar';
     }
     $request = new Request();
     $request->setMethod(Request::METHOD_GET);
     $request->setHeaders(Headers::fromString('If-Modified-Since: ' . gmdate('D, d M Y H:i:s T', filemtime($file))));
     $request->setUri('https://github.com/zendtech/ZendServerSDK/raw/master/bin/zs-client.phar');
     //$client->getAdapter()->setOptions(array('sslcapath' => __DIR__.'/../../../certs/'));
     $client->setAdapter(new Curl());
     $response = $client->send($request);
     if ($response->getStatusCode() == 304) {
         return 'Already up-to-date.';
     } else {
         ErrorHandler::start();
         rename($file, $file . '.' . date('YmdHi') . '.backup');
         $handler = fopen($file, 'w');
         fwrite($handler, $response->getBody());
         fclose($handler);
         ErrorHandler::stop(true);
         return 'The phar file was updated successfully.';
     }
 }
开发者ID:alexb-uk,项目名称:ZendServerSDK,代码行数:29,代码来源:UpdateController.php

示例9: makeRequestByOperation

 /**
  * Prepare a Zend Request by Operation with $parameters
  *
  * @param Operation $operation
  * @param array $parameters
  * @param int $options BitMask of options to skip or something else
  * @return Request
  * @throws \InvalidArgumentException
  * @throws \RuntimeException
  */
 public function makeRequestByOperation(Operation $operation, array $parameters = [], $options = 0)
 {
     $request = new Request();
     $path = $operation->path;
     if ($operation->parameters) {
         foreach ($operation->parameters as $parameter) {
             if (isset($parameters[$parameter->name])) {
                 switch ($parameter->in) {
                     case 'path':
                         $path = str_replace('{' . $parameter->name . '}', $parameters[$parameter->name], $path);
                         break;
                     case 'query':
                         $request->getQuery()->set($parameter->name, $parameters[$parameter->name]);
                         break;
                     case 'formData':
                         $request->getPost()->set($parameter->name, $parameters[$parameter->name]);
                         break;
                     default:
                         throw new RuntimeException(sprintf('Parameter "%s" with ->in = "%s" is not supported', $parameter->parameter, $parameter->in));
                 }
             } elseif ($parameter->required && !($options & SwaggerWrapper::SKIP_REQUIRED)) {
                 throw new InvalidArgumentException(sprintf('Parameter "%s" is required, please pass value for this in $parameters', $parameter->name));
             }
         }
     }
     $request->setUri($path);
     $request->setMethod($operation->method);
     return $request;
 }
开发者ID:ovr,项目名称:swagger-assert-helper,代码行数:39,代码来源:ZendTrait.php

示例10: sendRequest

 /**
  * {@inheritdoc}
  */
 public function sendRequest(RequestInterface $request)
 {
     $request = $this->sanitizeRequest($request);
     $headers = new Headers();
     foreach ($request->getHeaders() as $key => $value) {
         $headers->addHeader(new GenericHeader($key, $request->getHeaderLine($key)));
     }
     $zendRequest = new Request();
     $zendRequest->setMethod($request->getMethod());
     $zendRequest->setUri((string) $request->getUri());
     $zendRequest->setHeaders($headers);
     $zendRequest->setContent($request->getBody()->getContents());
     $options = ['httpversion' => $request->getProtocolVersion()];
     if (extension_loaded('curl')) {
         $options['curloptions'] = [CURLOPT_HTTP_VERSION => $this->getProtocolVersion($request->getProtocolVersion())];
     }
     $this->client->setOptions($options);
     if ($this->client->getAdapter() instanceof ZendClient\Adapter\Curl && $request->getMethod()) {
         $request = $request->withHeader('Content-Length', '0');
     }
     try {
         $zendResponse = $this->client->send($zendRequest);
     } catch (RuntimeException $exception) {
         throw new NetworkException($exception->getMessage(), $request, $exception);
     }
     return $this->responseFactory->createResponse($zendResponse->getStatusCode(), $zendResponse->getReasonPhrase(), $zendResponse->getHeaders()->toArray(), $zendResponse->getContent(), $zendResponse->getVersion());
 }
开发者ID:php-http,项目名称:zend-adapter,代码行数:30,代码来源:Client.php

示例11: callServer

 public function callServer($method, $params)
 {
     // Get the URI and Url Elements
     $apiUrl = $this->generateUrl($method);
     $requestUri = $apiUrl['uri'];
     // Convert the params to something MC can understand
     $params = $this->processParams($params);
     $params["apikey"] = $this->getConfig('apiKey');
     $request = new Request();
     $request->setMethod(Request::METHOD_POST);
     $request->setUri($requestUri);
     $request->getHeaders()->addHeaders(array('Host' => $apiUrl['host'], 'User-Agent' => 'MCAPI/' . $this->getConfig('apiVersion'), 'Content-type' => 'application/x-www-form-urlencoded'));
     $client = new Client();
     $client->setRequest($request);
     $client->setParameterPost($params);
     $result = $client->send();
     if ($result->getHeaders()->get('X-MailChimp-API-Error-Code')) {
         $error = unserialize($result->getBody());
         if (isset($error['error'])) {
             throw new MailchimpException('The mailchimp API has returned an error (' . $error['code'] . ': ' . $error['error'] . ')');
             return false;
         } else {
             throw new MailchimpException('There was an unspecified error');
             return false;
         }
     }
     return $result->getBody();
 }
开发者ID:aaron4m,项目名称:zf2-mailchimp,代码行数:28,代码来源:Mailchimp.php

示例12: sendRequest

 /**
  * Send request elasticsearch like this :
  * curl -X{$httpMethod} http://host/type/index/{$elasticMethod} -d '{json_decode($content)}'
  * @param int $httpMethod
  * @param string $elasticMethod
  * @param string $content
  *
  * @return Stdlib\ResponseInterface
  */
 public function sendRequest($httpMethod = Request::METHOD_GET, $elasticMethod = null, $content = null)
 {
     $request = new Request();
     $request->setUri($this->url . $elasticMethod)->setMethod($httpMethod)->setContent($content);
     $client = new Client();
     return $client->dispatch($request);
 }
开发者ID:Edencia,项目名称:GeonamesServer,代码行数:16,代码来源:Elasticsearch.php

示例13: PlanJSONManager

 function PlanJSONManager($action, $url, $requestjson, $uid)
 {
     $request = new Request();
     $request->getHeaders()->addHeaders(array('Content-Type' => 'application/json; charset=UTF-8'));
     //$url="";
     try {
         $request->setUri($url);
         $request->setMethod($action);
         $client = new Client();
         if ($action == 'PUT' || $action == 'POST') {
             $client->setUri($url);
             $client->setMethod($action);
             $client->setRawBody($requestjson);
             $client->setEncType('application/json');
             $response = $client->send();
             return $response;
         } else {
             $response = $client->dispatch($request);
             //var_dump(json_decode($response->getBody(),true));
             return $response;
         }
     } catch (\Exception $e) {
         $e->getTrace();
     }
     return null;
 }
开发者ID:shivap87,项目名称:cost,代码行数:26,代码来源:RESTJSONManager.php

示例14: testToUriStringMultiQueryOverwrite

 public function testToUriStringMultiQueryOverwrite()
 {
     $request = new Request();
     $request->setUri('http://google.ca/test.html?foo=bar');
     $request->getQuery()->set('foo', 'value');
     $this->assertEquals('http://google.ca/test.html?foo=value', RequestUtils::toUriString($request));
 }
开发者ID:51systems,项目名称:zf2-extensions,代码行数:7,代码来源:RequestUtilsTest.php

示例15: testNoMatchingOnDifferentScheme

 public function testNoMatchingOnDifferentScheme()
 {
     $request = new Request();
     $request->setUri('http://example.com/');
     $route = new Scheme('https');
     $match = $route->match($request);
     $this->assertNull($match);
 }
开发者ID:bradley-holt,项目名称:zf2,代码行数:8,代码来源:SchemeTest.php


注:本文中的Zend\Http\Request::setUri方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。