本文整理汇总了PHP中Request::getUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getUrl方法的具体用法?PHP Request::getUrl怎么用?PHP Request::getUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Request
的用法示例。
在下文中一共展示了Request::getUrl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: request
/**
* @param Request $request
* @return RawResponse
* @throws \Exception
*/
public function request(Request $request)
{
$res = $this->client->request('GET', $request->getUrl());
if ($res->getStatusCode() == 200) {
return new RawResponse((string) $res->getBody());
}
throw new \Exception('Error code', $res->getStatusCode());
}
示例2: cleanupCheck
/**
* Cleanup the cookie support check
*/
public function cleanupCheck()
{
if ($this->request->getUrl()->hasParam('_checkCookie') && isset($_COOKIE[self::CHECK_COOKIE])) {
$requestUri = $this->request->getUrl()->without('_checkCookie');
$this->request->getResponse()->redirectAndExit($requestUri);
}
}
示例3: initCurl
private function initCurl()
{
$this->curl = curl_init($this->request->getUrl());
foreach ($this->request->getOptions() as $option) {
curl_setopt($this->curl, $option[0], $option[1]);
}
$this->curlResponse = curl_exec($this->curl);
}
示例4: match
/**
* Matches Request to one of defined routes
*
* @param Request $request
* @return array
* @throws NoRouteFound
*/
public function match(Request $request)
{
$method = $request->getMethod();
if (isset($this->routes[$method])) {
foreach ((array) $this->routes[$method] as $routePattern => $routeSettings) {
if ($this->matchRoute($request->getUrl(), $routePattern, $routeSettings) === TRUE) {
return $routeSettings;
}
}
}
http_response_code(404);
throw new NoRouteFound('No routed found for method "' . $method . '" and URL "' . $request->getUrl() . '"');
}
示例5: call
/**
* @param Request $request
* @return Response
*/
public function call(Request $request)
{
// Create cURL
$ch = curl_init();
// Set-up URL
curl_setopt($ch, CURLOPT_URL, $request->getUrl());
// Set-up headers
$headers = $request->getHeaders();
array_walk($headers, function (&$item, $key) {
$item = "{$key}: {$item}";
});
curl_setopt($ch, CURLOPT_HTTPHEADER, array_values($headers));
// Set-up others
curl_setopt_array($ch, $request->getOpts());
// Receive result
$result = curl_exec($ch);
// Parse response
$response = new Response();
if ($result === FALSE) {
$response->setError(curl_strerror(curl_errno($ch)));
$response->setData(FALSE);
$response->setCode(curl_errno($ch));
$response->setHeaders(curl_getinfo($ch));
} else {
$response->setData(json_decode($result));
$response->setCode(curl_getinfo($ch, CURLINFO_HTTP_CODE));
$response->setHeaders(curl_getinfo($ch));
}
// Close cURL
curl_close($ch);
return $response;
}
示例6: testConstruct
function testConstruct()
{
$request = new Request('GET', '/foo', ['User-Agent' => 'Evert']);
$this->assertEquals('GET', $request->getMethod());
$this->assertEquals('/foo', $request->getUrl());
$this->assertEquals(['User-Agent' => ['Evert']], $request->getHeaders());
}
示例7: testGetUrlFormatsAUrl
public function testGetUrlFormatsAUrl()
{
$request = new Request();
$request->setHost('http://example.com');
$request->setResource('/resource/123');
$this->assertEquals($request->getUrl(), 'http://example.com/resource/123');
}
示例8: execute
public function execute(Request $request)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $request->getUrl());
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
$username = $request->getUsername();
$password = $request->getPassword();
if ($username && $password) {
curl_setopt($ch, CURLOPT_USERPWD, $username . ':' . $password);
}
switch ($request->getMethod()) {
case self::POST:
case self::PUT:
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($request->getParameters()));
break;
case self::DELETE:
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
break;
case self::GET:
default:
break;
}
$result = curl_exec($ch);
if (!$result) {
$errorNumber = curl_errno($ch);
$error = curl_error($ch);
curl_close($ch);
throw new \Exception($errorNumer . ': ' . $error);
}
curl_close($ch);
return $request->getResponseTransformerImpl()->transform($result);
}
示例9: redirect
/**
* @param $destination
*/
public function redirect($destination)
{
if (!isset($_SESSION)) {
session_start();
}
$_SESSION['referrer'] = Request::getUrl();
header('Location: ' . $destination, true);
exit;
}
示例10: handle
public function handle(Request $req, Response $res) : Response
{
if ($this->startTime) {
$endTime = microtime(true);
$message = date(\DateTime::ATOM, $this->startTime) . ' ' . $req->getUrl()->getFull() . ' ' . ($endTime - $this->startTime);
file_put_contents($this->logfile, $message, \FILE_APPEND | \LOCK_EX);
} else {
$this->startTime = microtime(true);
}
}
示例11: construct
/**
* Verify basic functionality of the request object.
*
* @test
* @covers ::__construct
* @covers ::getUrl
* @covers ::getBody
* @covers ::getMethod
* @covers ::getHeaders
*
* @return void
*/
public function construct()
{
$url = 'a url';
$method = 'a method';
$body = ['some' => 'data'];
$headers = ['key' => 'value'];
$request = new Request($url, $method, $headers, $body);
$this->assertSame($url, $request->getUrl());
$this->assertSame($method, $request->getMethod());
$this->assertSame($headers, $request->getHeaders());
$this->assertSame($body, $request->getBody());
}
示例12: handle
/**
* Handle Request.
*
* Determines which router should be executed and hand over job to it
*
* @param Request $request
*
* @return Response
*/
public function handle(Request $request)
{
$router = $this->findRouter($request->getUrl());
if (is_null($router)) {
return $this->getNotFoundResponse('Cannot found Controller');
}
/** @var Controller $controller */
$controller = new $router['class']();
$controller->setService('octrine', $this->configureOctrineService());
$controller->setService('session', $this->configureSession());
return call_user_func_array([$controller, $router['method']], [$request]);
}
示例13: __construct
public function __construct(\Request $request, \Http\ErrorResponse $response)
{
$vars = array();
$vars['url'] = $request->getUrl();
$vars['method'] = $request->getMethod();
$vars['module'] = $request->getModule();
$vars['code'] = $response->getCode();
$vars['phrase'] = $response->getPhrase();
$vars['backtrace'] = $response->getBacktrace();
$vars['exception'] = $response->getException();
$this->code = $vars['code'];
parent::__construct($vars, PHPWS_SOURCE_DIR . 'Global/Templates/Http/HtmlError.html', false);
}
示例14: parser
/**
* 解析路由规则表
*+--------------
* @param Void
* @return Self
*/
public function parser()
{
$url = $this->request->getUrl();
if ($url) {
//如果$uri不为空,遍历路由规则表,将$uri与每条规则表进行正则匹配,直到找到相匹配的规则信息;否则抛出异常
foreach ($this->routes as $key => $route) {
if (empty($route)) {
continue;
}
if (preg_match($this->matchs($route), $url, $this->matchs)) {
$this->active = $key;
break;
}
}
} else {
//获取默认路由规则,路由表最后一个
$route = $this->routes[count($this->routes) - 1];
if (isset($route[2])) {
$this->matchs = $route[2];
}
}
return $this;
}
示例15: passThrough
public function passThrough(Request $request)
{
$params = $request->getParameters();
if (array_key_exists('api_key', $params)) {
throw new \ErrorException('Request contains parameter with a reserved name: \'api_key\'');
}
if (array_key_exists('api_sig', $params)) {
throw new \ErrorException('Request contains parameter with a reserved name: \'api_sig\'');
}
$params['api_key'] = $this->consumerKey;
$baseString = BaseString::compute($request->getMethod(), $request->getUrl(), $params);
$signature = base64_encode(hash_hmac('sha1', $baseString, rawurlencode($this->consumerSecret), true));
$request->setParameter('api_key', $this->consumerKey);
$request->setParameter('api_sig', $signature);
}