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
30d70be0
Commit
30d70be0
authored
Mar 10, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finished Html helper.
parent
d2fcc69b
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
118 additions
and
43 deletions
+118
-43
Application.php
framework/base/Application.php
+11
-2
ActiveRelation.php
framework/db/ActiveRelation.php
+8
-8
ArrayHelper.php
framework/util/ArrayHelper.php
+33
-7
Html.php
framework/util/Html.php
+0
-0
Application.php
framework/web/Application.php
+41
-6
Controller.php
framework/web/Controller.php
+5
-0
Request.php
framework/web/Request.php
+19
-20
todo.md
todo.md
+1
-0
No files found.
framework/base/Application.php
View file @
30d70be0
...
...
@@ -382,6 +382,15 @@ class Application extends Module
}
/**
* Returns the URL manager for this application.
* @return \yii\web\UrlManager the URL manager for this application.
*/
public
function
getUrlManager
()
{
return
$this
->
getComponent
(
'urlManager'
);
}
/**
* Returns the internationalization (i18n) component
* @return \yii\i18n\I18N the internationalization component
*/
...
...
@@ -411,8 +420,8 @@ class Application extends Module
'i18n'
=>
array
(
'class'
=>
'yii\i18n\I18N'
,
),
'
security
Manager'
=>
array
(
'class'
=>
'yii\
base\Security
Manager'
,
'
url
Manager'
=>
array
(
'class'
=>
'yii\
web\Url
Manager'
,
),
));
}
...
...
framework/db/ActiveRelation.php
View file @
30d70be0
...
...
@@ -55,16 +55,16 @@ class ActiveRelation extends ActiveQuery
/**
* Specifies the relation associated with the pivot table.
* @param string $relationName the relation name. This refers to a relation declared in [[primaryModel]].
* @param call
back $callback
a PHP callback for customizing the relation associated with the pivot table.
* @param call
able $callable
a PHP callback for customizing the relation associated with the pivot table.
* Its signature should be `function($query)`, where `$query` is the query to be customized.
* @return ActiveRelation the relation object itself.
*/
public
function
via
(
$relationName
,
$call
back
=
null
)
public
function
via
(
$relationName
,
$call
able
=
null
)
{
$relation
=
$this
->
primaryModel
->
getRelation
(
$relationName
);
$this
->
via
=
array
(
$relationName
,
$relation
);
if
(
$call
back
!==
null
)
{
call_user_func
(
$call
back
,
$relation
);
if
(
$call
able
!==
null
)
{
call_user_func
(
$call
able
,
$relation
);
}
return
$this
;
}
...
...
@@ -75,11 +75,11 @@ class ActiveRelation extends ActiveQuery
* @param array $link the link between the pivot table and the table associated with [[primaryModel]].
* The keys of the array represent the columns in the pivot table, and the values represent the columns
* in the [[primaryModel]] table.
* @param call
back $callback
a PHP callback for customizing the relation associated with the pivot table.
* @param call
able $callable
a PHP callback for customizing the relation associated with the pivot table.
* Its signature should be `function($query)`, where `$query` is the query to be customized.
* @return ActiveRelation
*/
public
function
viaTable
(
$tableName
,
$link
,
$call
back
=
null
)
public
function
viaTable
(
$tableName
,
$link
,
$call
able
=
null
)
{
$relation
=
new
ActiveRelation
(
array
(
'modelClass'
=>
get_class
(
$this
->
primaryModel
),
...
...
@@ -89,8 +89,8 @@ class ActiveRelation extends ActiveQuery
'asArray'
=>
true
,
));
$this
->
via
=
$relation
;
if
(
$call
back
!==
null
)
{
call_user_func
(
$call
back
,
$relation
);
if
(
$call
able
!==
null
)
{
call_user_func
(
$call
able
,
$relation
);
}
return
$this
;
}
...
...
framework/util/ArrayHelper.php
View file @
30d70be0
...
...
@@ -281,33 +281,59 @@ class ArrayHelper
call_user_func_array
(
'array_multisort'
,
$args
);
}
/**
* Encodes special characters in an array of strings into HTML entities.
* Both the array keys and values will be encoded
if needed
.
* Both the array keys and values will be encoded.
* If a value is an array, this method will also encode it recursively.
* @param array $data data to be encoded
* @param boolean $valuesOnly whether to encode array values only. If false,
* both the array keys and array values will be encoded.
* @param string $charset the charset that the data is using. If not set,
* [[\yii\base\Application::charset]] will be used.
* @return array the encoded data
* @see http://www.php.net/manual/en/function.htmlspecialchars.php
*/
public
static
function
htmlEncode
(
$data
,
$charset
=
null
)
public
static
function
htmlEncode
(
$data
,
$
valuesOnly
=
false
,
$
charset
=
null
)
{
if
(
$charset
===
null
)
{
$charset
=
Yii
::
$app
->
charset
;
}
$d
=
array
();
foreach
(
$data
as
$key
=>
$value
)
{
if
(
is_string
(
$key
))
{
if
(
!
$valuesOnly
&&
is_string
(
$key
))
{
$key
=
htmlspecialchars
(
$key
,
ENT_QUOTES
,
$charset
);
}
if
(
is_string
(
$value
))
{
$value
=
htmlspecialchars
(
$value
,
ENT_QUOTES
,
$charset
);
$d
[
$key
]
=
htmlspecialchars
(
$value
,
ENT_QUOTES
,
$charset
);
}
elseif
(
is_array
(
$value
))
{
$d
[
$key
]
=
static
::
htmlEncode
(
$value
,
$charset
);
}
}
return
$d
;
}
/**
* Decodes HTML entities into the corresponding characters in an array of strings.
* Both the array keys and values will be decoded.
* If a value is an array, this method will also decode it recursively.
* @param array $data data to be decoded
* @param boolean $valuesOnly whether to decode array values only. If false,
* both the array keys and array values will be decoded.
* @return array the decoded data
* @see http://www.php.net/manual/en/function.htmlspecialchars-decode.php
*/
public
static
function
htmlDecode
(
$data
,
$valuesOnly
=
false
)
{
$d
=
array
();
foreach
(
$data
as
$key
=>
$value
)
{
if
(
!
$valuesOnly
&&
is_string
(
$key
))
{
$key
=
htmlspecialchars_decode
(
$key
,
ENT_QUOTES
);
}
if
(
is_string
(
$value
))
{
$d
[
$key
]
=
htmlspecialchars_decode
(
$value
,
ENT_QUOTES
);
}
elseif
(
is_array
(
$value
))
{
$
value
=
static
::
htmlEn
code
(
$value
);
$
d
[
$key
]
=
static
::
htmlDe
code
(
$value
);
}
$d
[
$key
]
=
$value
;
}
return
$d
;
}
...
...
framework/util/Html.php
View file @
30d70be0
This diff is collapsed.
Click to expand it.
framework/web/Application.php
View file @
30d70be0
...
...
@@ -6,6 +6,7 @@
*/
namespace
yii\web
;
use
yii\base\InvalidParamException
;
/**
* Application is the base class for all application classes.
...
...
@@ -62,11 +63,48 @@ class Application extends \yii\base\Application
}
/**
* @return UrlManager
* Creates a URL using the given route and parameters.
*
* This method first normalizes the given route by converting a relative route into an absolute one.
* A relative route is a route without slash. If the route is an empty string, it stands for
* the route of the currently active [[controller]]. If the route is not empty, it stands for
* an action ID of the [[controller]].
*
* After normalizing the route, this method calls [[\yii\web\UrlManager::createUrl()]]
* to create a relative URL.
*
* @param string $route the route. This can be either an absolute or a relative route.
* @param array $params the parameters (name-value pairs) to be included in the generated URL
* @return string the created URL
* @throws InvalidParamException if a relative route is given and there is no active controller.
* @see createAbsoluteUrl
*/
public
function
getUrlManager
(
)
public
function
createUrl
(
$route
,
$params
=
array
()
)
{
return
$this
->
getComponent
(
'urlManager'
);
if
(
strpos
(
$route
,
'/'
)
===
false
)
{
// a relative route
if
(
$this
->
controller
!==
null
)
{
$route
=
$route
===
''
?
$this
->
controller
->
route
:
$this
->
controller
->
uniqueId
.
'/'
.
$route
;
}
else
{
throw
new
InvalidParamException
(
'No active controller exists for resolving a relative route.'
);
}
}
return
$this
->
getUrlManager
()
->
createUrl
(
$route
,
$params
);
}
/**
* Creates an absolute URL using the given route and parameters.
* This method first calls [[createUrl()]] to create a relative URL.
* It then prepends [[\yii\web\UrlManager::hostInfo]] to the URL to form an absolute one.
* @param string $route the route. This can be either an absolute or a relative route.
* See [[createUrl()]] for more details.
* @param array $params the parameters (name-value pairs)
* @return string the created URL
* @see createUrl
*/
public
function
createAbsoluteUrl
(
$route
,
$params
=
array
())
{
return
$this
->
getUrlManager
()
->
getHostInfo
()
.
$this
->
createUrl
(
$route
,
$params
);
}
/**
...
...
@@ -86,9 +124,6 @@ class Application extends \yii\base\Application
'session'
=>
array
(
'class'
=>
'yii\web\Session'
,
),
'urlManager'
=>
array
(
'class'
=>
'yii\web\UrlManager'
,
),
));
}
}
framework/web/Controller.php
View file @
30d70be0
...
...
@@ -16,4 +16,8 @@ namespace yii\web;
*/
class
Controller
extends
\yii\base\Controller
{
public
function
createUrl
(
$route
,
$params
=
array
())
{
}
}
\ No newline at end of file
framework/web/Request.php
View file @
30d70be0
...
...
@@ -368,7 +368,7 @@ class Request extends \yii\base\Request
*/
protected
function
resolvePathInfo
()
{
$pathInfo
=
$this
->
get
RequestUri
();
$pathInfo
=
$this
->
get
Url
();
if
((
$pos
=
strpos
(
$pathInfo
,
'?'
))
!==
false
)
{
$pathInfo
=
substr
(
$pathInfo
,
0
,
$pos
);
...
...
@@ -407,42 +407,41 @@ class Request extends \yii\base\Request
}
/**
* Returns the currently requested URL.
* This is a shortcut to the concatenation of [[hostInfo]] and [[
requestUri
]].
* @return string the currently requested URL.
* Returns the currently requested
absolute
URL.
* This is a shortcut to the concatenation of [[hostInfo]] and [[
url
]].
* @return string the currently requested
absolute
URL.
*/
public
function
getUrl
()
public
function
get
Absolute
Url
()
{
return
$this
->
getHostInfo
()
.
$this
->
get
RequestUri
();
return
$this
->
getHostInfo
()
.
$this
->
get
Url
();
}
private
$_
requestUri
;
private
$_
url
;
/**
* Returns the portion after [[hostInfo]] for the currently requested URL.
* This refers to the portion that is after the [[hostInfo]] part. It includes the [[queryString]] part if any.
* The implementation of this method referenced Zend_Controller_Request_Http in Zend Framework.
* @return string the request URI portion for the currently requested URL.
* Note that the URI returned is URL-encoded.
* @throws InvalidConfigException if the request URI cannot be determined due to unusual server configuration
* Returns the currently requested relative URL.
* This refers to the portion of the URL that is after the [[hostInfo]] part.
* It includes the [[queryString]] part if any.
* @return string the currently requested relative URL. Note that the URI returned is URL-encoded.
* @throws InvalidConfigException if the URL cannot be determined due to unusual server configuration
*/
public
function
get
RequestUri
()
public
function
get
Url
()
{
if
(
$this
->
_
requestUri
===
null
)
{
$this
->
_
requestUri
=
$this
->
resolveRequestUri
();
if
(
$this
->
_
url
===
null
)
{
$this
->
_
url
=
$this
->
resolveRequestUri
();
}
return
$this
->
_
requestUri
;
return
$this
->
_
url
;
}
/**
* Sets the currently requested
URI
.
* Sets the currently requested
relative URL
.
* The URI must refer to the portion that is after [[hostInfo]].
* Note that the URI should be URL-encoded.
* @param string $value the request URI to be set
*/
public
function
set
RequestUri
(
$value
)
public
function
set
Url
(
$value
)
{
$this
->
_
requestUri
=
$value
;
$this
->
_
url
=
$value
;
}
/**
...
...
todo.md
View file @
30d70be0
...
...
@@ -18,6 +18,7 @@
*
backend-specific unit tests
*
dependency unit tests
-
validators
*
Refactor validators to add validateValue() for every validator, if possible. Check if value is an array.
*
FileValidator: depends on CUploadedFile
*
CaptchaValidator: depends on CaptchaAction
*
DateValidator: should we use CDateTimeParser, or simply use strtotime()?
...
...
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