本文整理汇总了PHP中Slim\Http\Uri::createFromString方法的典型用法代码示例。如果您正苦于以下问题:PHP Uri::createFromString方法的具体用法?PHP Uri::createFromString怎么用?PHP Uri::createFromString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slim\Http\Uri
的用法示例。
在下文中一共展示了Uri::createFromString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: 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);
}
示例4: 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');
}
示例5: 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;
}
示例6: 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();
}
示例7: 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;
}
示例8: 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();
}
示例9: 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;
}
示例10: 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;
}
示例11: 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;
}
示例12: makeRequest
/**
* @param string $method
* @param string $uri
* @return Request
*/
public function makeRequest($method = 'GET', $uri = '')
{
$env = Environment::mock([]);
$uri = Uri::createFromString($uri);
$headers = Headers::createFromEnvironment($env);
$cookies = [];
$serverParams = $env->all();
$body = new RequestBody();
$uploadedFiles = UploadedFile::createFromEnvironment($env);
$request = new Request($method, $uri, $headers, $cookies, $serverParams, $body, $uploadedFiles);
$request = $request->withHeader("Content-Type", "application/x-www-form-urlencoded");
return $request;
}
示例13: setUpXmlPost
/**
* Setup for the XML POST requests.
*
* @param string $xml The XML to use to mock the body of the request.
*/
public function setUpXmlPost($xml)
{
$uri = Uri::createFromString('https://example.com:443/foo');
$headers = new Headers();
$headers->set('Content-Type', 'application/xml;charset=utf8');
$cookies = [];
$env = Environment::mock(['SCRIPT_NAME' => '/index.php', 'REQUEST_URI' => '/foo', 'REQUEST_METHOD' => 'POST']);
$serverParams = $env->all();
$body = new RequestBody();
$body->write($xml);
$this->request = new Request('POST', $uri, $headers, $cookies, $serverParams, $body);
$this->response = new Response();
}
示例14: runPost
/**
* run application with POST method.
* adds C.S.R.F. token if $post is set.
*
* @param string $path
* @param array $post
*/
protected function runPost($path = '', $post = [])
{
if (!empty($post)) {
// add csrf tokens.
$key = 'unit-csrf';
$val = 'unit-csrf-value';
$_SESSION['csrf'][$key] = $val;
$post['csrf_name'] = $key;
$post['csrf_value'] = $val;
}
$uri = Uri::createFromString($this->root_url . $path);
$this->runApp('POST', $uri, $post);
}
示例15: setUp
/**
* Run before each test.
*/
public function setUp()
{
parent::setUp();
$uri = Uri::createFromString('https://example.com:443/foo/bar?abc=123');
$this->request = new Request('GET', $uri, new Headers(), [], Environment::mock()->all(), new Body(fopen('php://temp', 'r+')));
$this->response = new Response();
// Prepare container and populate it with Slim services that are needed for further tests
$this->addToContainer('callableResolver', function ($c) {
return new CallableResolver($c);
});
$this->addToContainer('foundHandler', function ($c) {
return new RequestResponse();
});
}