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


PHP Http\Uri类代码示例

本文整理汇总了PHP中Slim\Http\Uri的典型用法代码示例。如果您正苦于以下问题:PHP Uri类的具体用法?PHP Uri怎么用?PHP Uri使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: dispatch

 protected function dispatch($path, $method = 'GET', $data = array(), $cookies = array())
 {
     $container = $this->app->getContainer();
     // seperate the path from the query string so we can set in the environment
     @(list($path, $queryString) = explode('?', $path));
     // Prepare a mock environment
     $env = Environment::mock(array('REQUEST_URI' => $path, 'REQUEST_METHOD' => $method, 'QUERY_STRING' => is_null($queryString) ? '' : $queryString));
     // Prepare request and response objects
     $uri = Uri::createFromEnvironment($env);
     $headers = Headers::createFromEnvironment($env);
     $cookies = $cookies;
     $serverParams = $env->all();
     $body = new RequestBody();
     // create request, and set params
     $req = new $container['request']($method, $uri, $headers, $cookies, $serverParams, $body);
     if (!empty($data)) {
         $req = $req->withParsedBody($data);
     }
     $res = new $container['response']();
     // // Fix for body, but breaks POST params in tests - http://stackoverflow.com/questions/34823328/response-getbody-is-empty-when-testing-slim-3-routes-with-phpunit
     // $body = new RequestBody();
     // if (!empty($data))
     //    $body->write(json_encode($data));
     //
     // // create request, and set params
     // $req = new $container['request']($method, $uri, $headers, $cookies, $serverParams, $body);
     // $res = new $container['response']();
     $this->headers = $headers;
     $this->request = $req;
     $this->response = call_user_func_array($this->app, array($req, $res));
 }
开发者ID:martynbiz,项目名称:slim3-controller,代码行数:31,代码来源:TestCase.php

示例2: request

 private function request($method, $path, $data = array(), $optionalHeaders = array())
 {
     //Make method uppercase
     $method = strtoupper($method);
     $options = array('REQUEST_METHOD' => $method, 'REQUEST_URI' => $path);
     if ($method === 'GET') {
         $options['QUERY_STRING'] = http_build_query($data);
     } else {
         $params = json_encode($data);
     }
     // Prepare a mock environment
     $env = Environment::mock(array_merge($options, $optionalHeaders));
     $uri = Uri::createFromEnvironment($env);
     $headers = Headers::createFromEnvironment($env);
     $cookies = $this->cookies;
     $serverParams = $env->all();
     $body = new RequestBody();
     // Attach JSON request
     if (isset($params)) {
         $headers->set('Content-Type', 'application/json;charset=utf8');
         $body->write($params);
     }
     $this->request = new Request($method, $uri, $headers, $cookies, $serverParams, $body);
     $response = new Response();
     // Invoke request
     $app = $this->app;
     $this->response = $app($this->request, $response);
     // Return the application output.
     return (string) $this->response->getBody();
 }
开发者ID:there4,项目名称:slim-test-helpers,代码行数:30,代码来源:WebTestClient.php

示例3: requestFactory

 /**
  * @param $method
  * @param $path
  * @param $body
  * @param $options
  * @return Request
  */
 protected function requestFactory($method, $path, $body = [], $options = [])
 {
     $uri = Uri::createFromString($path);
     $headers = new Headers();
     $cookies = [];
     $_POST['_METHOD'] = $method;
     if (strtolower($method) != 'get' && is_array($body)) {
         foreach ($body as $key => $value) {
             $_POST[$key] = $value;
         }
     }
     $envMethod = 'POST';
     if (strtolower($method) == 'get') {
         $envMethod = 'GET';
     }
     $env = Environment::mock(['REQUEST_URI' => $path, 'REQUEST_METHOD' => $envMethod, 'HTTP_CONTENT_TYPE' => 'multipart/form-data; boundary=---foo']);
     $serverParams = $env->all();
     $body = $this->buildBody($body);
     //echo $body->getContents();
     // @todo
     // $request = new Request($method, $uri, $headers, $cookies, $serverParams, $body, []);
     $request = Request::createFromEnvironment($env);
     unset($_POST);
     return $request;
 }
开发者ID:SharkIng,项目名称:ss-panel,代码行数:32,代码来源:TestCase.php

示例4: testAbsoluteUrlGetsRouteAndAppendsPortWhenNotStandard

 public function testAbsoluteUrlGetsRouteAndAppendsPortWhenNotStandard()
 {
     $uri = SlimUri::createFromString('http://host:8443/path/page?query=1');
     $this->router->shouldReceive('relativePathFor')->with('route.name', ['param1' => '1'], [])->andReturn('/test-route-page');
     $url = new URI($this->router);
     $actual = $url->absoluteURIFor($uri, 'route.name', ['param1' => '1']);
     $this->assertSame('http://host:8443/test-route-page', $actual);
 }
开发者ID:quickenloans-mcp,项目名称:mcp-panthor,代码行数:8,代码来源:URITest.php

示例5: requestFactory

 public function requestFactory()
 {
     $uri = Uri::createFromString('https://example.com:443/foo/bar?abc=123');
     $headers = new Headers();
     $cookies = [];
     $serverParams = [];
     $body = new Body(fopen('php://temp', 'r+'));
     return new Request('GET', $uri, $headers, $cookies, $serverParams, $body);
 }
开发者ID:aodkrisda,项目名称:slim-3-framework-app,代码行数:9,代码来源:CacheTest.php

示例6: createRequest

 protected function createRequest($env)
 {
     $method = $env["REQUEST_METHOD"];
     $uri = Uri::createFromEnvironment($env);
     $headers = Headers::createFromEnvironment($env);
     $cookies = Cookies::parseHeader($headers->get("Cookie", []));
     $serverParams = $env->all();
     $body = new Body(fopen("php://input", "r"));
     return new Request($method, $uri, $headers, $cookies, $serverParams, $body);
 }
开发者ID:zither,项目名称:memo,代码行数:10,代码来源:RouterTest.php

示例7: createUri

 /**
  * {@inheritdoc}
  */
 public function createUri($uri)
 {
     if ($uri instanceof UriInterface) {
         return $uri;
     }
     if (is_string($uri)) {
         return Uri::createFromString($uri);
     }
     throw new \InvalidArgumentException('URI must be a string or UriInterface');
 }
开发者ID:php-http,项目名称:message,代码行数:13,代码来源:SlimUriFactory.php

示例8: makeRequest

 /**
  * @param $method
  * @param string $url
  *
  * @return Request
  */
 public function makeRequest($method, $url = '/')
 {
     $env = Environment::mock();
     $uri = Uri::createFromString('http://example.com' . $url);
     $headers = Headers::createFromEnvironment($env);
     $serverParams = $env->all();
     $body = new RequestBody();
     $uploadedFiles = UploadedFile::createFromEnvironment($env);
     $request = new Request($method, $uri, $headers, [], $serverParams, $body, $uploadedFiles);
     return $request;
 }
开发者ID:ChrisBrenton,项目名称:recipes,代码行数:17,代码来源:RequestFactory.php

示例9: requestFactory

 public function requestFactory($acceptType = 'application/json')
 {
     $env = Environment::mock(['HTTP_ACCEPT' => $acceptType]);
     $uri = Uri::createFromString('https://example.com:443/foo/bar?abc=123');
     $headers = Headers::createFromEnvironment($env);
     $serverParams = $env->all();
     $body = new RequestBody();
     $uploadedFiles = UploadedFile::createFromEnvironment($env);
     $request = new Request('GET', $uri, $headers, [], $serverParams, $body, $uploadedFiles);
     return $request;
 }
开发者ID:slimphp-api,项目名称:slim-json,代码行数:11,代码来源:JsonTest.php

示例10: setUp

 /**
  * Run before each test.
  */
 public function setUp()
 {
     $uri = Uri::createFromString('https://example.com:443/foo/bar');
     $headers = new Headers();
     $cookies = [];
     $env = Environment::mock();
     $serverParams = $env->all();
     $body = new Body(fopen('php://temp', 'r+'));
     $this->request = new Request('GET', $uri, $headers, $cookies, $serverParams, $body);
     $this->response = new Response();
 }
开发者ID:davidepastore,项目名称:slim-config,代码行数:14,代码来源:ConfigTest.php

示例11: createRequest

 protected function createRequest()
 {
     $env = (new Environment())->mock(["PATH_INFO" => "/index/hello/", "SCRIPT_NAME" => "/index.php"]);
     $method = $env["REQUEST_METHOD"];
     $uri = Uri::createFromEnvironment($env);
     $headers = Headers::createFromEnvironment($env);
     $cookies = Cookies::parseHeader($headers->get("Cookie", []));
     $serverParams = $env->all();
     $body = new Body(fopen("php://input", "r"));
     return new Request($method, $uri, $headers, $cookies, $serverParams, $body);
 }
开发者ID:zither,项目名称:memo,代码行数:11,代码来源:ControllerTest.php

示例12: setUp

 /**
  * Run before each test
  */
 public function setUp()
 {
     $uri = \Slim\Http\Uri::createFromString('https://example.com:443/foo/bar?abc=123');
     $headers = new \Slim\Http\Headers();
     $cookies = new \Slim\Collection();
     $env = \Slim\Http\Environment::mock();
     $serverParams = new \Slim\Collection($env->all());
     $body = new \Slim\Http\Body(fopen('php://temp', 'r+'));
     $this->request = new \Slim\Http\Request('GET', $uri, $headers, $cookies, $serverParams, $body);
     $this->response = new \Slim\Http\Response();
 }
开发者ID:elbajuri,项目名称:ketupat,代码行数:14,代码来源:CsrfTest.php

示例13: requestFactory

 public function requestFactory($requestUrl)
 {
     $uri = Uri::createFromString($requestUrl);
     $headers = new Headers();
     $cookies = [];
     $env = Slim\Http\Environment::mock();
     $serverParams = $env->all();
     $body = new Body(fopen('php://temp', 'r+'));
     $request = new Request('GET', $uri, $headers, $cookies, $serverParams, $body);
     return $request;
 }
开发者ID:mrmoneyc,项目名称:slim-mvc-skeleton,代码行数:11,代码来源:bootstrap.php

示例14: requestFactory

 public function requestFactory($queryString = '')
 {
     $env = Environment::mock();
     $uri = Uri::createFromString('https://example.com:443/foo/bar' . $queryString);
     $headers = Headers::createFromEnvironment($env);
     $cookies = ['user' => 'john', 'id' => '123'];
     $serverParams = $env->all();
     $body = new RequestBody();
     $uploadedFiles = UploadedFile::createFromEnvironment($env);
     $request = new Request('GET', $uri, $headers, $cookies, $serverParams, $body, $uploadedFiles);
     return $request;
 }
开发者ID:geggleto,项目名称:sessionmiddleware,代码行数:12,代码来源:SessionMiddlewareTest.php

示例15: requestFactory

 private function requestFactory($endpoint)
 {
     // Request
     $uri = Uri::createFromString('https://example.com:443/' . $endpoint);
     $headers = new Headers();
     $cookies = [];
     $serverParams = [];
     $body = new Body(fopen('php://temp', 'r+'));
     $request = new Request('GET', $uri, $headers, $cookies, $serverParams, $body);
     $request = $request->withAttribute('route', new Route(['get'], '/' . $endpoint, 'CallableFunction'));
     return $request;
 }
开发者ID:kanellov,项目名称:slim-acl,代码行数:12,代码来源:GuardTest.php


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