Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
577f8a5c
Commit
577f8a5c
authored
Mar 10, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added separate schema and absolute parameters
parent
2b842ecc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
29 deletions
+39
-29
BaseUrl.php
framework/helpers/BaseUrl.php
+39
-29
No files found.
framework/helpers/BaseUrl.php
View file @
577f8a5c
...
@@ -36,11 +36,12 @@ class BaseUrl
...
@@ -36,11 +36,12 @@ class BaseUrl
*
*
* In case there is no controller, [[\yii\web\UrlManager::createUrl()]] will be used.
* In case there is no controller, [[\yii\web\UrlManager::createUrl()]] will be used.
*
*
* @param string $schema URI schema to use. If specified absolute URL with the schema specified is returned.
* @param boolean $absolute if absolute URL should be created.
* @param string $schema URI schema to use. Schema to use for absolute URL. If not specified current schema will be used.
* @return string the normalized URL
* @return string the normalized URL
* @throws InvalidParamException if the parameter is invalid.
* @throws InvalidParamException if the parameter is invalid.
*/
*/
public
static
function
toRoute
(
$route
,
$schema
=
null
)
public
static
function
toRoute
(
$route
,
$
absolute
=
false
,
$
schema
=
null
)
{
{
$route
=
(
array
)
$route
;
$route
=
(
array
)
$route
;
if
(
!
isset
(
$route
[
0
]))
{
if
(
!
isset
(
$route
[
0
]))
{
...
@@ -49,7 +50,7 @@ class BaseUrl
...
@@ -49,7 +50,7 @@ class BaseUrl
if
(
Yii
::
$app
->
controller
instanceof
\yii\web\Controller
)
{
if
(
Yii
::
$app
->
controller
instanceof
\yii\web\Controller
)
{
$route
[
0
]
=
static
::
getNormalizedRoute
(
$route
[
0
]);
$route
[
0
]
=
static
::
getNormalizedRoute
(
$route
[
0
]);
}
}
return
$
schema
===
null
?
Yii
::
$app
->
getUrlManager
()
->
createUrl
(
$route
)
:
Yii
::
$app
->
getUrlManager
()
->
createAbsoluteUrl
(
$route
,
$schema
);
return
$
absolute
?
Yii
::
$app
->
getUrlManager
()
->
createAbsoluteUrl
(
$route
,
$schema
)
:
Yii
::
$app
->
getUrlManager
()
->
createUrl
(
$route
);
}
}
/**
/**
...
@@ -95,45 +96,49 @@ class BaseUrl
...
@@ -95,45 +96,49 @@ class BaseUrl
*
*
* @param array|string $url the parameter to be used to generate a valid URL
* @param array|string $url the parameter to be used to generate a valid URL
* @param string $schema URI schema to use. If specified absolute URL with the schema specified is returned.
* @param boolean $absolute if absolute URL should be created.
* @param string $schema URI schema to use. Schema to use for absolute URL. If not specified current schema will be used.
* @return string the normalized URL
* @return string the normalized URL
* @throws InvalidParamException if the parameter is invalid.
* @throws InvalidParamException if the parameter is invalid.
*/
*/
public
static
function
to
(
$url
=
''
,
$schema
=
null
)
public
static
function
to
(
$url
=
''
,
$
absolute
=
false
,
$
schema
=
null
)
{
{
if
(
is_array
(
$url
))
{
if
(
is_array
(
$url
))
{
return
static
::
toRoute
(
$url
,
$schema
);
return
static
::
toRoute
(
$url
,
$
absolute
,
$
schema
);
}
elseif
(
$url
===
''
)
{
}
elseif
(
$url
===
''
)
{
if
(
$schema
===
null
)
{
if
(
$absolute
)
{
return
Yii
::
$app
->
request
->
getUrl
();
}
else
{
$url
=
Yii
::
$app
->
request
->
getAbsoluteUrl
();
$url
=
Yii
::
$app
->
request
->
getAbsoluteUrl
();
$pos
=
strpos
(
$url
,
'://'
);
$pos
=
strpos
(
$url
,
'://'
);
return
$schema
.
substr
(
$url
,
$pos
);
$url
=
$schema
.
substr
(
$url
,
$pos
);
}
else
{
$url
=
Yii
::
$app
->
request
->
getUrl
();
}
}
}
else
{
}
else
{
$url
=
Yii
::
getAlias
(
$url
);
$url
=
Yii
::
getAlias
(
$url
);
$pos
=
strpos
(
$url
,
'://'
);
$pos
=
strpos
(
$url
,
'://'
);
if
(
$pos
!==
null
)
{
if
(
$pos
!==
null
)
{
// URI is already absolute, adjust schema if specified
if
(
$schema
!==
null
)
{
if
(
$schema
!==
null
)
{
$url
=
$schema
.
substr
(
$url
,
$pos
);
$url
=
$schema
.
substr
(
$url
,
$pos
);
}
}
return
$url
;
}
if
(
$url
!==
''
&&
(
$url
[
0
]
===
'/'
||
$url
[
0
]
===
'#'
||
!
strncmp
(
$url
,
'./'
,
2
)))
{
$url
=
Yii
::
$app
->
getRequest
()
->
getHostInfo
()
.
$url
;
}
else
{
}
else
{
$url
=
Yii
::
$app
->
getRequest
()
->
getBaseUrl
()
.
'/'
.
$url
;
// URI is relative
}
if
(
$url
===
''
||
(
$url
[
0
]
!==
'/'
&&
$url
[
0
]
!==
'#'
&&
strncmp
(
$url
,
'./'
,
2
)))
{
if
(
$schema
!==
null
)
{
// URL is relative need to adjust it to be absolute
$pos
=
strpos
(
$url
,
'://'
);
$url
=
Yii
::
$app
->
getRequest
()
->
getBaseUrl
()
.
'/'
.
$url
;
if
(
$pos
!==
null
)
{
}
$url
=
$schema
.
substr
(
$url
,
$pos
);
if
(
$absolute
)
{
$url
=
Yii
::
$app
->
getRequest
()
->
getHostInfo
()
.
$url
;
if
(
$schema
!==
null
)
{
$pos
=
strpos
(
$url
,
'://'
);
if
(
$pos
!==
null
)
{
$url
=
$schema
.
substr
(
$url
,
$pos
);
}
}
}
}
}
}
return
$url
;
}
}
return
$url
;
}
}
/**
/**
...
@@ -192,18 +197,22 @@ class BaseUrl
...
@@ -192,18 +197,22 @@ class BaseUrl
/**
/**
* Returns home URL
* Returns home URL
*
*
* @param string $schema URI schema to use. If specified absolute URL with the schema specified is returned.
* @param boolean $absolute if absolute URL should be created.
* @param string $schema URI schema to use. Schema to use for absolute URL. If not specified current schema will be used.
* @return string home URL
* @return string home URL
*/
*/
public
static
function
home
(
$schema
=
null
)
public
static
function
home
(
$
absolute
=
false
,
$
schema
=
null
)
{
{
if
(
$schema
===
null
)
{
if
(
$absolute
)
{
return
Yii
::
$app
->
getHomeUrl
();
}
else
{
$url
=
Yii
::
$app
->
getRequest
()
->
getHostInfo
()
.
Yii
::
$app
->
getHomeUrl
();
$url
=
Yii
::
$app
->
getRequest
()
->
getHostInfo
()
.
Yii
::
$app
->
getHomeUrl
();
$pos
=
strpos
(
$url
,
'://'
);
if
(
$schema
!==
null
)
{
return
$schema
.
substr
(
$url
,
$pos
);
$pos
=
strpos
(
$url
,
'://'
);
$url
=
$schema
.
substr
(
$url
,
$pos
);
}
}
else
{
$url
=
Yii
::
$app
->
getHomeUrl
();
}
}
return
$url
;
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment