本文整理汇总了PHP中Nette\Http\Url::getBaseUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP Url::getBaseUrl方法的具体用法?PHP Url::getBaseUrl怎么用?PHP Url::getBaseUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Nette\Http\Url
的用法示例。
在下文中一共展示了Url::getBaseUrl方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: constructUrl
public function constructUrl(Request $appRequest, Url $refUrl)
{
// Module prefix not match.
if ($this->module && !Strings::startsWith($appRequest->getPresenterName(), $this->module)) {
return null;
}
$params = $appRequest->getParameters();
$urlStack = [];
// Module prefix
$moduleFrags = explode(":", Strings::lower($appRequest->getPresenterName()));
$resourceName = array_pop($moduleFrags);
$urlStack += $moduleFrags;
// Resource
$urlStack[] = Strings::lower($resourceName);
// Id
if (isset($params['id']) && is_scalar($params['id'])) {
$urlStack[] = $params['id'];
unset($params['id']);
}
// Set custom action
if (isset($params['action']) && $this->_isApiAction($params['action'])) {
unset($params['action']);
}
$url = $refUrl->getBaseUrl() . implode('/', $urlStack);
// Add query parameters
if (!empty($params)) {
$url .= "?" . http_build_query($params);
}
return $url;
}
示例2: constructUrl
/**
* Constructs absolute URL from Request object.
*
* @return string|NULL
*/
public function constructUrl(AppRequest $appRequest, Url $refUrl)
{
if ($this->flags & self::ONE_WAY) {
return NULL;
}
$params = $appRequest->getParameters();
if (!isset($params['action']) || !is_string($params['action'])) {
return NULL;
}
$key = $appRequest->getPresenterName() . ':' . $params['action'];
if (!isset($this->tableOut[$key])) {
return NULL;
}
if ($this->lastRefUrl !== $refUrl) {
$this->lastBaseUrl = $refUrl->getBaseUrl();
$this->lastRefUrl = $refUrl;
}
unset($params['action']);
$slug = $this->tableOut[$key];
$query = ($tmp = http_build_query($params)) ? '?' . $tmp : '';
$url = $this->lastBaseUrl . $slug . $query;
return $url;
}
示例3: constructUrl
/**
* Constructs absolute URL from Request object.
*
* @param \Nette\Application\Request $appRequest
* @param \Nette\Http\Url $refUrl
* @throws \Nette\InvalidStateException
* @return string|NULL
*/
public function constructUrl(Request $appRequest, Url $refUrl)
{
// Module prefix not match.
if ($this->module && !Strings::startsWith($appRequest->getPresenterName(), $this->module)) {
return null;
}
$parameters = $appRequest->getParameters();
$urlStack = array();
// Module prefix.
$moduleFrags = explode(":", $appRequest->getPresenterName());
if (count($moduleFrags)) {
foreach ($moduleFrags as &$fragment) {
$fragment = $this->presenter2path($fragment);
}
}
$resourceName = array_pop($moduleFrags);
$urlStack += $moduleFrags;
if (isset($parameters['associations']) && is_array($parameters['associations'])) {
$associations =& $parameters['associations'];
foreach ($associations as $key => $value) {
$urlStack[] = $key;
$urlStack[] = $value;
}
}
$urlStack[] = $resourceName;
if (isset($parameters['specific_action']) && $parameters['specific_action']) {
$urlStack[] = $this->action2path($parameters['specific_action']);
}
if (isset($parameters['id']) && is_scalar($parameters['id'])) {
$urlStack[] = $parameters['id'];
}
$url = $q = $refUrl->getBaseUrl() . implode('/', $urlStack);
if (isset($parameters['query']) && count($parameters['query'])) {
$sep = ini_get('arg_separator.input');
$query = http_build_query($parameters['query'], '', $sep ? $sep[0] : '&');
$url .= '?' . $query;
}
return $url;
}
示例4: constructUrl
/**
* Constructs absolute URL from Request object.
* @param \Nette\Application\Request $appRequest
* @param \Nette\Http\Url $refUrl
* @throws \Nette\InvalidStateException
* @return string|NULL
*/
public function constructUrl(Request $appRequest, Url $refUrl)
{
// Module prefix not match.
if ($this->module && !Strings::startsWith($appRequest->getPresenterName(), $this->module)) {
return NULL;
}
$parameters = $appRequest->getParameters();
$url = $refUrl->getBaseUrl();
$urlStack = [];
// Module prefix.
$moduleFrags = explode(":", $appRequest->getPresenterName());
$moduleFrags = array_map('\\AdamStipak\\Support\\Inflector::spinalCase', $moduleFrags);
$resourceName = array_pop($moduleFrags);
$urlStack += $moduleFrags;
// Associations.
if (isset($parameters['associations']) && Validators::is($parameters['associations'], 'array')) {
$associations = $parameters['associations'];
unset($parameters['associations']);
foreach ($associations as $key => $value) {
$urlStack[] = $key;
$urlStack[] = $value;
}
}
// Resource.
$urlStack[] = $resourceName;
// Id.
if (isset($parameters['id']) && Validators::is($parameters['id'], 'scalar')) {
$urlStack[] = $parameters['id'];
unset($parameters['id']);
}
$url = $url . implode('/', $urlStack);
$sep = ini_get('arg_separator.input');
if (isset($parameters['query'])) {
$query = http_build_query($parameters['query'], '', $sep ? $sep[0] : '&');
if ($query != '') {
$url .= '?' . $query;
}
}
return $url;
}
示例5: constructUrl
/**
* Constructs absolute URL from Request object.
* @param \Nette\Application\Request $appRequest
* @param \Nette\Http\Url $refUrl
* @throws \Nette\InvalidStateException
* @return string|NULL
*/
public function constructUrl(Request $appRequest, Url $refUrl)
{
// Module prefix not match.
if ($this->module && !Strings::startsWith($appRequest->getPresenterName(), $this->module)) {
return NULL;
}
$parameters = $appRequest->getParameters();
$url = $refUrl->getBaseUrl();
$urlStack = array();
// Module prefix.
$moduleFrags = explode(":", Strings::lower($appRequest->getPresenterName()));
$resourceName = array_pop($moduleFrags);
$urlStack += $moduleFrags;
// Associations.
if (isset($parameters['associations']) && Validators::is($parameters['associations'], 'array')) {
$associations =& $parameters['associations'];
if (count($associations) % 2 !== 0) {
throw new InvalidStateException("Number of associations is not even");
}
foreach ($associations as $key => $value) {
$urlStack[] = $key;
$urlStack[] = $value;
}
}
// Resource.
$urlStack[] = Strings::lower($resourceName);
// Id.
if (isset($parameters['id']) && Validators::is($parameters['id'], 'scalar')) {
$urlStack[] = $parameters['id'];
}
return $url . implode('/', $urlStack);
}
示例6: constructUrl
/**
* Constructs absolute URL from Request object.
* @return string|NULL
*/
public function constructUrl(Request $request, Nette\Http\Url $url)
{
if ($this->presenter != $request->getPresenterName()) {
return NULL;
}
$base_url = $url->getBaseUrl();
$action = $request->getParameter('action');
$parameters = $request->getParameters();
unset($parameters['action']);
$path = ltrim($this->getPath(), '/');
if (FALSE === array_search($action, $this->actions)) {
return NULL;
}
foreach ($parameters as $name => $value) {
if (strpos($path, "<{$name}>") !== FALSE && $value !== NULL) {
$path = str_replace("<{$name}>", $value, $path);
unset($parameters[$name]);
}
}
$path = preg_replace_callback('/\\[.+?\\]/', function ($item) {
if (strpos(end($item), '<')) {
return '';
}
return end($item);
}, $path);
/**
* There are still some required parameters in url mask
*/
if (preg_match('/<\\w+>/', $path)) {
return NULL;
}
$path = str_replace(['[', ']'], '', $path);
$query = http_build_query($parameters);
return $base_url . $path . ($query ? '?' . $query : '');
}