本文整理汇总了PHP中Nette\Http\IRequest::getUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP IRequest::getUrl方法的具体用法?PHP IRequest::getUrl怎么用?PHP IRequest::getUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Http\IRequest
的用法示例。
在下文中一共展示了IRequest::getUrl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: generateImage
public function generateImage(ImageRequest $request)
{
$width = $request->getWidth();
$height = $request->getHeight();
$format = $request->getFormat();
if (!$this->validator->validate($width, $height)) {
throw new Application\BadRequestException();
}
$image = NULL;
foreach ($this->providers as $provider) {
$image = $provider->getImage($request);
if ($image) {
break;
}
}
if (!$image) {
$this->httpResponse->setHeader('Content-Type', 'image/jpeg');
$this->httpResponse->setCode(Http\IResponse::S404_NOT_FOUND);
exit;
}
$destination = $this->wwwDir . '/' . $this->httpRequest->getUrl()->getRelativeUrl();
$dirname = dirname($destination);
if (!is_dir($dirname)) {
$success = @mkdir($dirname, 0777, TRUE);
if (!$success) {
throw new Application\BadRequestException();
}
}
$success = $image->save($destination, 90, $format);
if (!$success) {
throw new Application\BadRequestException();
}
$image->send();
exit;
}
示例2: createTemplate
/**
* @return Template
*/
public function createTemplate(UI\Control $control = NULL)
{
$latte = $this->latteFactory->create();
$template = new Template($latte);
$presenter = $control ? $control->getPresenter(FALSE) : NULL;
if ($control instanceof UI\Presenter) {
$latte->setLoader(new Loader($control));
}
if ($latte->onCompile instanceof \Traversable) {
$latte->onCompile = iterator_to_array($latte->onCompile);
}
array_unshift($latte->onCompile, function ($latte) use($control, $template) {
$latte->getCompiler()->addMacro('cache', new Nette\Bridges\CacheLatte\CacheMacro($latte->getCompiler()));
UIMacros::install($latte->getCompiler());
if (class_exists(Nette\Bridges\FormsLatte\FormMacros::class)) {
Nette\Bridges\FormsLatte\FormMacros::install($latte->getCompiler());
}
if ($control) {
$control->templatePrepareFilters($template);
}
});
$latte->addFilter('url', 'rawurlencode');
// back compatiblity
foreach (['normalize', 'toAscii', 'webalize', 'padLeft', 'padRight', 'reverse'] as $name) {
$latte->addFilter($name, 'Nette\\Utils\\Strings::' . $name);
}
$latte->addFilter('null', function () {
});
$latte->addFilter('modifyDate', function ($time, $delta, $unit = NULL) {
return $time == NULL ? NULL : Nette\Utils\DateTime::from($time)->modify($delta . $unit);
// intentionally ==
});
if (!isset($latte->getFilters()['translate'])) {
$latte->addFilter('translate', function (Latte\Runtime\FilterInfo $fi) {
throw new Nette\InvalidStateException('Translator has not been set. Set translator using $template->setTranslator().');
});
}
// default parameters
$template->user = $this->user;
$template->baseUri = $template->baseUrl = $this->httpRequest ? rtrim($this->httpRequest->getUrl()->getBaseUrl(), '/') : NULL;
$template->basePath = preg_replace('#https?://[^/]+#A', '', $template->baseUrl);
$template->flashes = [];
if ($control) {
$template->control = $control;
$template->presenter = $presenter;
$latte->addProvider('uiControl', $control);
$latte->addProvider('uiPresenter', $presenter);
$latte->addProvider('snippetBridge', new Nette\Bridges\ApplicationLatte\SnippetBridge($control));
}
$latte->addProvider('cacheStorage', $this->cacheStorage);
// back compatibility
$template->_control = $control;
$template->_presenter = $presenter;
$template->netteCacheStorage = $this->cacheStorage;
if ($presenter instanceof UI\Presenter && $presenter->hasFlashSession()) {
$id = $control->getParameterId('flash');
$template->flashes = (array) $presenter->getFlashSession()->{$id};
}
return $template;
}
示例3: match
/**
* Maps HTTP request to a Request object.
*
* @param Nette\Http\IRequest $httpRequest
* @return Request|NULL
*/
public function match(Nette\Http\IRequest $httpRequest)
{
$relativeUrl = trim($httpRequest->getUrl()->relativeUrl, "/");
$path = trim($httpRequest->getUrl()->path, "/");
if ($relativeUrl == "") {
$target = $this->defaultRoute;
$this->currentTarget->setCurrentTarget($this->targetDao->findTarget($target->presenter, $target->action, $target->id));
} elseif ($relativeUrl == "sitemap.xml") {
$target = new Target("Seo:Meta", "sitemap");
} elseif ($relativeUrl == "robots.txt") {
$target = new Target("Seo:Meta", "robots");
} elseif (substr($relativeUrl, 0, 6) == "google" && $this->settingsDao->getWebmasterToolsName() == $relativeUrl) {
$target = new Target("Seo:Meta", "googleWebmasterTools");
} else {
$route = $this->routeDao->findRouteBySlug($relativeUrl, TRUE);
if (!$route) {
$route = $this->routeDao->findRouteBySlug($path, TRUE);
if (!$route) {
return NULL;
}
}
$this->currentTarget->setCurrentTarget($route->getTarget());
$target = new Target($route->target->targetPresenter, $route->target->targetAction, $route->target->targetId);
}
$params = array();
$params["action"] = $target->action;
if ($target->id) {
$params["id"] = $target->id;
}
$params += $httpRequest->getQuery();
return new Request($target->presenter, $httpRequest->getMethod(), $params, $httpRequest->getPost(), $httpRequest->getFiles(), array(Request::SECURED => $httpRequest->isSecured()));
}
示例4: getPanel
/**
* Renders panel.
* @return string
*/
public function getPanel()
{
ob_start();
$request = $this->request;
$routers = $this->routers;
$source = $this->source;
$url = $this->httpRequest->getUrl();
require __DIR__ . '/templates/RoutingPanel.panel.phtml';
return ob_get_clean();
}
示例5: checkAllowedMethods
/**
* Check allowed methods
*
* @throws BadRequestException If method is not supported but another one can be used
*/
protected function checkAllowedMethods()
{
$availableMethods = $this->methods->getOptions($this->request->getUrl());
if (!$availableMethods || in_array($this->request->method, $availableMethods)) {
return;
}
$allow = implode(', ', $availableMethods);
$this->response->setHeader('Allow', $allow);
throw BadRequestException::methodNotSupported('Method not supported. Available methods: ' . $allow);
}
示例6: getResourceId
/**
* {@inheritdoc}
*/
public function getResourceId()
{
$refUrl = $this->httpRequest->getUrl();
$url = $this->router->constructUrl($this->request, $refUrl);
if ($url === NULL) {
throw new \Nette\Application\UI\InvalidLinkException();
}
$hostUrl = $refUrl->getHostUrl() . '/';
if (strncmp($url, $hostUrl, strlen($hostUrl)) === 0) {
$url = substr($url, strlen($hostUrl) - 1);
}
return $url;
}
示例7: getPanel
/**
* Renders panel.
* @return string
*/
public function getPanel()
{
ob_start();
$request = $this->request;
$routers = $this->routers;
$source = $this->source;
$hasModule = (bool) array_filter($routers, function ($rq) {
return $rq['module'];
});
$url = $this->httpRequest->getUrl();
require __DIR__ . '/templates/RoutingPanel.panel.phtml';
return ob_get_clean();
}
示例8: createTemplate
/**
* @return Template
*/
public function createTemplate(UI\Control $control = NULL)
{
$latte = $this->latteFactory->create();
$template = new Template($latte);
$presenter = $control ? $control->getPresenter(FALSE) : NULL;
if ($control instanceof UI\Presenter) {
$latte->setLoader(new Loader($control));
}
if ($latte->onCompile instanceof \Traversable) {
$latte->onCompile = iterator_to_array($latte->onCompile);
}
array_unshift($latte->onCompile, function ($latte) use($control, $template) {
$latte->getParser()->shortNoEscape = TRUE;
$latte->getCompiler()->addMacro('cache', new Nette\Bridges\CacheLatte\CacheMacro($latte->getCompiler()));
UIMacros::install($latte->getCompiler());
if (class_exists('Nette\\Bridges\\FormsLatte\\FormMacros')) {
Nette\Bridges\FormsLatte\FormMacros::install($latte->getCompiler());
}
if ($control) {
$control->templatePrepareFilters($template);
}
});
$latte->addFilter('url', 'rawurlencode');
// back compatiblity
foreach (array('normalize', 'toAscii', 'webalize', 'padLeft', 'padRight', 'reverse') as $name) {
$latte->addFilter($name, 'Nette\\Utils\\Strings::' . $name);
}
$latte->addFilter('null', function () {
});
$latte->addFilter('length', function ($var) {
return is_string($var) ? Nette\Utils\Strings::length($var) : count($var);
});
$latte->addFilter('modifyDate', function ($time, $delta, $unit = NULL) {
return $time == NULL ? NULL : Nette\Utils\DateTime::from($time)->modify($delta . $unit);
// intentionally ==
});
// default parameters
$template->control = $template->_control = $control;
$template->presenter = $template->_presenter = $presenter;
$template->user = $this->user;
$template->netteHttpResponse = $this->httpResponse;
$template->netteCacheStorage = $this->cacheStorage;
$template->baseUri = $template->baseUrl = $this->httpRequest ? rtrim($this->httpRequest->getUrl()->getBaseUrl(), '/') : NULL;
$template->basePath = preg_replace('#https?://[^/]+#A', '', $template->baseUrl);
$template->flashes = array();
if ($presenter instanceof UI\Presenter && $presenter->hasFlashSession()) {
$id = $control->getParameterId('flash');
$template->flashes = (array) $presenter->getFlashSession()->{$id};
}
return $template;
}
示例9: redirectToRequest
/**
* Restores request from session.
* @param string $key
*/
public function redirectToRequest($key)
{
$request = $this->requestStorage->loadRequest($key);
if (!$request) {
return;
}
$parameters = $request->getParameters();
$parameters[Presenter::FLASH_KEY] = $this->getParameter(Presenter::FLASH_KEY);
$parameters[RequestStorage::REQUEST_KEY] = $key;
$request->setParameters($parameters);
$refUrl = new Url($this->httpRequest->getUrl());
$refUrl->setPath($this->httpRequest->getUrl()->getScriptPath());
$url = $this->router->constructUrl($request, $refUrl);
$this->redirectUrl($url);
}
示例10: send
public function send(HttpRequest $request, HttpResponse $response)
{
$width = null;
$height = null;
$quality = null;
try {
$url = $request->getUrl();
$name = Strings::after($url->getPath(), '/', -1);
try {
// only for case, when all images expected response from application and not from existing images
$thumb = $this->repository->fetchThumbnail($name);
} catch (\Imager\NotExistsException $e) {
// thumbnail must be generate, because not exists
$id = $url->getQueryParameter('id');
$width = $url->getQueryParameter('width');
$height = $url->getQueryParameter('height');
$quality = $url->getQueryParameter('quality');
$source = $this->repository->fetch($id);
$thumb = $this->factory->create($source)->resize($width, $height, $quality);
$thumb = $this->repository->save($thumb);
}
$response->setContentType($thumb->getMime());
$response->setHeader('Content-Length', $thumb->getSize());
echo $thumb->getContent();
} catch (\Exception $e) {
$width = $width ?: 200;
$height = $height ?: 200;
$this->sendError($response, $e, $width, $height);
}
exit(0);
}
示例11: match
/**
* Maps HTTP request to a Request object.
* @return Nette\Application\Request|NULL
*/
public function match(Nette\Http\IRequest $httpRequest)
{
if ($httpRequest->getUrl()->getPathInfo() !== '') {
return NULL;
}
// combine with precedence: get, (post,) defaults
$params = $httpRequest->getQuery();
$params += $this->defaults;
if (!isset($params[self::PRESENTER_KEY]) || !is_string($params[self::PRESENTER_KEY])) {
return NULL;
}
$presenter = $this->module . $params[self::PRESENTER_KEY];
unset($params[self::PRESENTER_KEY]);
return new Application\Request(
$presenter,
$httpRequest->getMethod(),
$params,
$httpRequest->getPost(),
$httpRequest->getFiles(),
array(Application\Request::SECURED => $httpRequest->isSecured())
);
}
示例12: match
/**
* Maps HTTP request to a Request object.
* @return Nette\Application\Request|NULL
*/
public function match(Nette\Http\IRequest $httpRequest)
{
// combine with precedence: mask (params in URL-path), fixity, query, (post,) defaults
// 1) URL MASK
$url = $httpRequest->getUrl();
$re = $this->re;
if ($this->type === self::HOST) {
$path = '//' . $url->getHost() . $url->getPath();
$host = array_reverse(explode('.', $url->getHost()));
$re = strtr($re, array('/%basePath%/' => preg_quote($url->getBasePath(), '#'), '%tld%' => $host[0], '%domain%' => isset($host[1]) ? "{$host['1']}\\.{$host['0']}" : $host[0]));
} elseif ($this->type === self::RELATIVE) {
$basePath = $url->getBasePath();
if (strncmp($url->getPath(), $basePath, strlen($basePath)) !== 0) {
return NULL;
}
$path = (string) substr($url->getPath(), strlen($basePath));
} else {
$path = $url->getPath();
}
if ($path !== '') {
$path = rtrim($path, '/') . '/';
}
if (!($matches = Strings::match($path, $re))) {
// stop, not matched
return NULL;
}
if (!$this->manager->isAMFRequest()) {
return null;
}
return $this->manager->createApplicationRequest();
}
示例13: process
private function process($url, string $directory, string $parameter, array &$dependencies = []) : string
{
$url = new Nette\Http\Url($url);
$time = NULL;
if ($url->getHost() && (!$this->request || $url->getHost() !== $this->request->getUrl()->getHost())) {
$headers = @get_headers($url, TRUE);
if (is_array($headers) && isset($headers['Last-Modified'])) {
$time = (new DateTime($headers['Last-Modified']))->getTimestamp();
}
} elseif (is_file($filename = implode(DIRECTORY_SEPARATOR, [rtrim($directory, '\\/'), ltrim($url->getPath(), '\\/')]))) {
$time = filemtime($filename);
unset($dependencies[Nette\Caching\Cache::EXPIRE]);
$dependencies[Nette\Caching\Cache::FILES] = $filename;
}
$url->setQueryParameter($parameter, $time ?: ($this->time ?: ($this->time = time())));
return preg_replace($pattern = '#^(\\+|/+)#', preg_match($pattern, $url->getPath()) ? DIRECTORY_SEPARATOR : NULL, $url);
}
示例14: match
/**
* Maps HTTP request to a Request object.
*
* @param Nette\Http\IRequest $httpRequest
* @return NULL|Request
*/
public function match(Nette\Http\IRequest $httpRequest)
{
$path = ltrim($httpRequest->getUrl()->getPath(), '/');
if (Nette\Utils\Strings::match($path, '~^' . preg_quote($this->mask, '~') . '/*($|\\?)~')) {
header("Location: {$this->target}", TRUE, 301);
die;
}
return NULL;
}
示例15: getLastPageUrl
/**
* Get last page URL
* @param Paginator $paginator
* @return Link
*/
private function getLastPageUrl(Paginator $paginator)
{
$url = clone $this->request->getUrl();
parse_str($url->getQuery(), $query);
$query['offset'] = $paginator->getLastPage() * $paginator->getItemsPerPage() - $paginator->getItemsPerPage();
$query['limit'] = $paginator->getItemsPerPage();
$url->appendQuery($query);
return new Link($url, Link::LAST);
}