本文整理汇总了PHP中Request::getUri方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getUri方法的具体用法?PHP Request::getUri怎么用?PHP Request::getUri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Request
的用法示例。
在下文中一共展示了Request::getUri方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onRequest
/**
* Handles an incoming HTTP request and dispatches it to the appropriate action.
*
* @param Request $request The HTTP request message.
* @param Socket $socket The client socket connection.
*
* @return \Generator
*
* @resolve \Icicle\Http\Message\Response The appropriate HTTP response.
*/
public function onRequest(Request $request, Socket $socket) : \Generator
{
$dispatched = $this->app->getDispatcher()->dispatch($request->getMethod(), $request->getUri()->getPath());
switch ($dispatched[0]) {
case FastRoute\Dispatcher::NOT_FOUND:
// no route found
$randomStr = '';
for ($i = 0; $i < 1000; ++$i) {
$char = chr(mt_rand(32, 126));
if ($char !== '<') {
$randomStr .= $char;
}
}
$html = $this->app->getRenderer()->render('404', ['randomStr' => $randomStr]);
$sink = new MemorySink();
yield from $sink->end($html);
return new BasicResponse(404, ['Content-Type' => 'text/html', 'Content-Length' => $sink->getLength()], $sink);
case FastRoute\Dispatcher::METHOD_NOT_ALLOWED:
// HTTP request method not allowed
$sink = new MemorySink();
yield from $sink->end('405 Method Not Allowed');
return new BasicResponse(405, ['Content-Type' => 'text/plain', 'Content-Length' => $sink->getLength()], $sink);
case FastRoute\Dispatcher::FOUND:
// route was found
$action = new $dispatched[1]($this->app);
$response = (yield from $action->handle($request, $dispatched[2]));
return $response;
default:
throw new \RuntimeException('Invalid router state');
}
}
示例2: _default
protected function _default(Request $request)
{
$route = new Route();
$uri = $request->getUri();
$uri = strpos($uri, "?") !== false ? substr($uri, 0, strpos($uri, "?")) : $uri;
$parts = explode("/", $uri);
$parts = $this->_filter($parts);
switch (count($parts)) {
case 0:
$route->setControllerName("index");
$route->setActionName("index");
break;
case 1:
$route->setControllerName($parts[0]);
$route->setActionName("index");
array_shift($parts);
break;
default:
$route->setControllerName($parts[0]);
$route->setActionName($parts[1]);
array_shift($parts);
array_shift($parts);
break;
}
count($parts) % 2 !== 0 ? array_pop($parts) : false;
if (count($parts)) {
for ($i = 0; $i < count($parts); $i = $i + 2) {
$request->addParam($parts[$i], $parts[$i + 1]);
}
}
return $route;
}
示例3: feed
public function feed($data)
{
$this->buffer .= $data;
if (!$this->request && false !== strpos($this->buffer, "\r\n\r\n")) {
// Extract the header from the buffer
// in case the content isn't complete
list($headers, $this->buffer) = explode("\r\n\r\n", $this->buffer, 2);
// Fail before parsing if the
if (strlen($headers) > $this->maxSize) {
$this->headerSizeExceeded();
return;
}
$this->request = gPsr\parse_request($headers . "\r\n\r\n");
}
// if there is a request (meaning the headers are parsed) and
// we have the right content size, we can finish the parsing
if ($this->request && $this->isRequestComplete()) {
$body = substr($this->buffer, 0, $this->length);
// create a stream for the body.
$stream = new BufferedStream();
$stream->write($body);
// add stream to the request.
$this->request = $this->request->withBody($stream);
// create server request object
$this->request = new ServerRequest($this->request);
// todo this should really belong in the header parsing. clean this up.
$parsedQuery = [];
$queryString = $this->request->getUri()->getQuery();
if ($queryString) {
parse_str($queryString, $parsedQuery);
if (!empty($parsedQuery)) {
$this->request = $this->request->withQueryParams($parsedQuery);
}
}
// add server request information to the request object.
$this->request = $this->parseBody($body, $this->request);
$this->emit('headers', array($this->request));
$this->removeAllListeners();
$this->request = null;
return;
}
// fail if the header hasn't finished but it is already too large
if (!$this->request && strlen($this->buffer) > $this->maxSize) {
$this->headerSizeExceeded();
return;
}
}
示例4: match
/**
* Thank's Symfony :)
*/
public function match(Request $request_)
{
$matches = $variables = $tokens = array();
$defaultSeparator = '/';
$uri = $request_->getUri();
preg_match_all('#\\{\\w+\\}#', $this->path, $matches, PREG_OFFSET_CAPTURE | PREG_SET_ORDER);
if (!empty($matches)) {
// Use of {} variables
$pos = 0;
foreach ($matches as $match) {
$varName = substr($match[0][0], 1, -1);
$precedingText = substr($this->path, $pos, $match[0][1] - $pos);
$pos = $match[0][1] + strlen($match[0][0]);
$precedingChar = strlen($precedingText) > 0 ? substr($precedingText, -1) : '';
$isSeparator = $precedingChar !== '' && strpos(static::SEPARATORS, $precedingChar) !== false;
if (is_numeric($varName)) {
throw new \Exception(sprintf('Variable name "%s" cannot be numeric in route pattern "%s". Please use a different name.', $varName, $this->path));
}
if (in_array($varName, $variables)) {
throw new \Exception(sprintf('Route pattern "%s" cannot reference variable name "%s" more than once.', $this->path, $varName));
}
if ($isSeparator && strlen($precedingText) > 1) {
$tokens[] = array('text', substr($precedingText, 0, -1));
} else {
if (!$isSeparator && strlen($precedingText) > 0) {
$tokens[] = array('text', $precedingText);
}
}
$followingPattern = (string) substr($this->path, $pos);
$nextSeparator = self::findNextSeparator($followingPattern);
$regexp = sprintf('[^%s%s]+', preg_quote($defaultSeparator, self::REGEX_DELIMITER), $defaultSeparator !== $nextSeparator && '' !== $nextSeparator ? preg_quote($nextSeparator, self::REGEX_DELIMITER) : '');
if ($nextSeparator !== '' && !preg_match('#^\\{\\w+\\}#', $followingPattern) || $followingPattern === '') {
$regexp .= '+';
}
$variables[] = $varName;
$tokens[] = array('variable', $isSeparator ? $precedingChar : '', $regexp, $varName);
}
if ($pos < strlen($this->path)) {
$tokens[] = array('text', substr($this->path, $pos));
}
// compute the matching regexp
$regexp = '';
for ($i = 0, $nbToken = count($tokens); $i < $nbToken; ++$i) {
$regexp .= self::computeRegexp($tokens, $i, PHP_INT_MAX);
}
$regex = self::REGEX_DELIMITER . '^' . $regexp . '$' . self::REGEX_DELIMITER . 's';
$matchingValues = array();
$res = preg_match($regex, $uri, $matchingValues);
if ($res) {
foreach ($variables as $k => $v) {
$request_->setParam($v, $matchingValues[$v]);
}
return true;
}
return false;
}
return $this->path === $request_->getUri();
}
示例5: match
public function match(Request $request, $route = false)
{
if ($request->getUri() == $this->_path) {
$static = new Route();
$static->setControllerName($this->_controller);
$static->setActionName($this->_action);
$static->merge($route);
return parent::match($request, $static);
}
}
示例6: doRequest
/**
* Makes a request.
*
* @param Request $request A Request instance
*
* @return Response A Response instance
*/
protected function doRequest($request)
{
curl_setopt($this->curl, CURLOPT_URL, $request->getUri());
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $request->getParameters());
curl_setopt($this->curl, CURLOPT_CUSTOMREQUEST, $request->getMethod());
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);
$content = curl_exec($this->curl);
$this->assertCurlError();
$requestInfo = curl_getinfo($this->curl);
return new Response($content, $requestInfo['http_code']);
}
示例7: __invoke
public function __invoke(array $record)
{
$record['context']['app'] = $this->appName;
$record['context']['environement'] = $this->environment;
$record['context']['Hostname'] = gethostname();
try {
if (null === $this->request) {
$this->request = $this->container->get('request');
}
$record['request']['base_url'] = $this->request->getBaseUrl();
$record['request']['scheme'] = $this->request->getScheme();
$record['request']['port'] = $this->request->getPort();
$record['request']['request_uri'] = $this->request->getRequestUri();
$record['request']['uri'] = $this->request->getUri();
$record['request']['query_string'] = $this->request->getQueryString();
$record['request']['_route'] = $this->request->get('_route');
} catch (\Exception $e) {
// This stops errors occuring in the CLI
}
return $record;
}
示例8: Delete
public function Delete(Request $request)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $request->getUri());
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$response = curl_exec($ch);
$r = $this->ConvertCurlResponse($response, $ch);
curl_close($ch);
return $r;
}
示例9: handle
/**
* Handle the incoming HTTP request and return a
* Response object.
*
* @param Request $request
* @throws InvalidHttpResponseException
* @return Response
*/
public function handle(Request $request)
{
$route_params = $this->_router->match($request->getUri());
$route = $route_params['route'];
$params = $route_params['params'];
$func = reset($route) . self::CONTROLLER_METHOD_SUFIX;
$class_name = key($route);
$controller = new $class_name($request);
$response = call_user_func_array([$controller, $func], [$params]);
if ($response instanceof Response) {
return $response;
} else {
throw new InvalidHttpResponseException();
}
}
示例10: __construct
public function __construct($owner, &$item, $user = null, $parent = null, $depth = 0)
{
$this->item = $item;
$this->user = $user;
$this->parent = $parent;
$this->owner = $owner;
$uri_to_match = Request::getUri();
if ($this->owner->ignorePrefix()) {
$uri_to_match = @preg_replace('#^' . $owner->ignorePrefix() . '#', '', $uri_to_match);
if ($uri_to_match === null) {
throw new BakedCarrotException('Invalid parameter: "ignore_prefix"');
}
}
if ($uri_to_match == '/') {
$this->item['active'] = isset($this->item['uri']) && $this->item['uri'] == $uri_to_match;
$this->item['selected'] = $this->item['active'];
} else {
$request_uri_parts = $this->splitUri($uri_to_match);
$uri_parts = array();
if (isset($this->item['uri']) && strlen($this->item['uri']) > 0) {
$uri_parts = $this->splitUri($this->item['uri']);
}
$matched = false;
foreach ($uri_parts as $num => $uri_part) {
$matched = isset($request_uri_parts[$num]) && $request_uri_parts[$num] == $uri_part;
if (!$matched) {
break;
}
}
$this->item['active'] = $matched;
$this->item['selected'] = $matched && count($uri_parts) == count($request_uri_parts);
}
$this->item['depth'] = $depth;
$this->item['access'] = true;
if (is_object($this->user) && isset($this->item['uri'])) {
if (!method_exists($this->user, 'hasRole')) {
throw new BakedCarrotException(get_class($this->user) . '::hasRole() is not defined');
}
if (($menu_item_route = Router::getRouteByUri($this->item['uri'])) && $menu_item_route->acl) {
$this->item['access'] = $this->user->hasRole($menu_item_route->acl);
}
}
$this->getChildren();
}
示例11: send
/**
* (non-PHPdoc)
* @see HttpClient::send()
*/
public function send(Request $request)
{
$ch = $this->curlAdapter->init($request->getUri());
$this->curlAdapter->setOption($ch, $this->curlAdapter->getOptConstant('CUSTOMREQUEST'), $request->getMethod());
$headers = array();
foreach ($request->getHeader() as $name => $value) {
$headers[] = $request->getHeader()->joinField($name, $value);
}
$this->curlAdapter->setOption($ch, $this->curlAdapter->getOptConstant('HTTPHEADER'), $headers);
$this->curlAdapter->setOption($ch, $this->curlAdapter->getOptConstant('POSTFIELDS'), $request->getPayload());
$this->curlAdapter->setOption($ch, $this->curlAdapter->getOptConstant('RETURNTRANSFER'), 1);
$this->curlAdapter->setOption($ch, $this->curlAdapter->getOptConstant('HEADERFUNCTION'), array($this, 'headerCallback'));
$this->response->flush();
$content = $this->curlAdapter->exec($ch);
if (false === $content) {
throw new \RuntimeException($this->curlAdapter->getError($ch), $this->curlAdapter->getErrno($ch));
}
$this->response->setContent($content);
$this->response->setStatusCode($this->curlAdapter->getInfo($ch, $this->curlAdapter->getInfoConstant('HTTP_CODE')));
$this->curlAdapter->close($ch);
return clone $this->response;
}
示例12: route
/**
* Given the request data and the loaded resource metadata, pick the best matching
* resource to handle the request based on URI and priority.
*
* @param Request $request
* @return ResourceMetadata
*/
public function route($request = NULL)
{
$matchedResource = NULL;
if (!$request) {
$request = new Request();
}
foreach ($this->resources as $className => $resourceMetadata) {
foreach ($resourceMetadata->getUri() as $index => $uri) {
$uriRegex = '|^' . $uri . '$|';
if (($matchedResource == NULL || $matchedResource[0]->getPriority() < $resourceMetadata->getPriority()) && preg_match($uriRegex, $request->getUri(), $params)) {
array_shift($params);
$uriParams = $resourceMetadata->getUriParams($index);
if ($uriParams) {
// has params within URI
foreach ($uriParams as $key => $name) {
$params[$name] = $params[$key];
}
}
$matchedResource = array($resourceMetadata, $params);
}
}
}
if ($matchedResource) {
$request->setParams($matchedResource[1]);
return $matchedResource[0];
} else {
throw new NotFoundException(sprintf('Resource matching URI "%s" not found', $request->uri));
}
}
示例13: onAfterDispatch
/**
* This method adds alternate meta tags for associated menu items
*
* @return nothing
* @since 1.7
*/
public function onAfterDispatch()
{
if (App::isSite() && $this->params->get('alternate_meta') && Document::getType() == 'html') {
// Get active menu item
$active = App::get('menu')->getActive();
if (!$active) {
return;
}
// Get menu item link
if (Config::get('sef')) {
$active_link = Route::url('index.php?Itemid=' . $active->id, false);
} else {
$active_link = Route::url($active->link . '&Itemid=' . $active->id, false);
}
if ($active_link == JUri::base(true) . '/') {
$active_link .= 'index.php';
}
// Get current link
$current_link = Request::getUri();
if ($current_link == Request::base(true) . '/') {
$current_link .= 'index.php';
}
// Check the exact menu item's URL
if ($active_link == $current_link) {
// Get menu item associations
JLoader::register('MenusHelper', PATH_CORE . '/components/com_menus/admin/helpers/menus.php');
$associations = MenusHelper::getAssociations($active->id);
// Remove current menu item
unset($associations[$active->language]);
// Associated menu items in other languages
if ($associations && $this->params->get('menu_associations')) {
$menu = App::get('menu');
$server = JURI::getInstance()->toString(array('scheme', 'host', 'port'));
foreach (JLanguageHelper::getLanguages() as $language) {
if (isset($associations[$language->lang_code])) {
$item = $menu->getItem($associations[$language->lang_code]);
if ($item && Lang::exists($language->lang_code)) {
if (Config::get('sef')) {
$link = Route::url('index.php?Itemid=' . $associations[$language->lang_code] . '&lang=' . $language->sef);
} else {
$link = Route::url($item->link . '&Itemid=' . $associations[$language->lang_code] . '&lang=' . $language->sef);
}
// Check if language is the default site language and remove url language code is on
if ($language->sef == self::$default_sef && $this->params->get('remove_default_prefix') == '1') {
$relLink = preg_replace('|/' . $language->sef . '/|', '/', $link, 1);
Document::addHeadLink($server . $relLink, 'alternate', 'rel', array('hreflang' => $language->lang_code));
} else {
Document::addHeadLink($server . $link, 'alternate', 'rel', array('hreflang' => $language->lang_code));
}
}
}
}
} elseif ($active->home) {
$menu = App::get('menu');
$server = JURI::getInstance()->toString(array('scheme', 'host', 'port'));
foreach (JLanguageHelper::getLanguages() as $language) {
$item = $menu->getDefault($language->lang_code);
if ($item && $item->language != $active->language && $item->language != '*' && JLanguage::exists($language->lang_code)) {
if (Config::get('sef')) {
$link = Route::url('index.php?Itemid=' . $item->id . '&lang=' . $language->sef);
} else {
$link = Route::url($item->link . '&Itemid=' . $item->id . '&lang=' . $language->sef);
}
// Check if language is the default site language and remove url language code is on
if ($language->sef == self::$default_sef && $this->params->get('remove_default_prefix') == '1') {
$relLink = preg_replace('|/' . $language->sef . '/|', '/', $link, 1);
Document::addHeadLink($server . $relLink, 'alternate', 'rel', array('hreflang' => $language->lang_code));
} else {
Document::addHeadLink($server . $link, 'alternate', 'rel', array('hreflang' => $language->lang_code));
}
}
}
}
}
}
}
示例14: full
/**
* Get the full URI including the query string.
*
* @return string
*/
public static function full()
{
return Request::getUri();
}
示例15: setReadyAction
public function setReadyAction()
{
$response['error'] = 0;
$response['target_h']['#battle'] = '';
$response['blocked'] = false;
if (Request::getUri()[0]) {
$mid = Request::getUri()[0];
$assets = getSession('myAssets' . $mid, false);
if ($assets) {
$assets = json_decode($assets);
if ($assets && is_object($assets) && count($assets) > 0) {
$model = new ProfileModel();
$myAssets = $model->getMatchAssets(Request::getParam('user')->id, $mid);
if ($myAssets && count($myAssets) > 0) {
foreach ($myAssets as $asset) {
if (!$asset->oldAssetId) {
$response['error'] = Lang::translate("MATCH_ONE_EMPTY");
break;
}
}
if (!$response['error']) {
$match = $model->getMatchByID($mid);
if ($match && !$match->blocked) {
if (Request::getParam('user')->id == $match->uid) {
if ($match->uready == '0') {
$data['uready'] = '1';
$status = Lang::translate("MATCH_READY");
} else {
$data['uready'] = '0';
$status = Lang::translate("MATCH_NOT_READY");
}
} else {
if ($match->pready == '0') {
$data['pready'] = '1';
$status = Lang::translate("MATCH_READY");
} else {
$data['pready'] = '0';
$status = Lang::translate("MATCH_NOT_READY");
}
}
if ($model->setMatchReady($mid, $data)) {
$response['target_h']['#readyBtn'] = $status;
$match = $model->getMatchByID($mid);
if ($match->uready && $match->pready) {
if ($model->setMatchBlocked($match->id)) {
$response['target_h']['#battle'] = Lang::translate("MATCH_BLOCKED_WAIT_FOR_REQUEST") . " 0%";
$response['blocked'] = true;
} else {
$response['tradeOffer'] = Lang::translate("MATCH_DB_ERROR");
}
}
} else {
$response['error'] = Lang::translate("MATCH_DB_ERROR");
}
} else {
$response['blocked'] = true;
$response['error'] = Lang::translate("MATCH_WRONG_OR_BLOCKED");
}
}
} else {
$response['error'] = Lang::translate("MATCH_EMPTY_MY_ASSETS");
}
} else {
$response['error'] = Lang::translate("MATCH_WRONG_ASSETS");
}
} else {
$response['error'] = Lang::translate("MATCH_EMPTY_ASSETS");
}
}
echo json_encode($response);
exit;
}