本文整理汇总了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));
}
示例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();
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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');
}
示例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;
}
示例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;
}
示例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();
}
示例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);
}
示例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();
}
示例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;
}
示例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;
}
示例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;
}