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
a5b3932a
Commit
a5b3932a
authored
Jul 23, 2011
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
m
parent
07c86e58
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
72 deletions
+58
-72
YiiBase.php
framework/YiiBase.php
+19
-3
Event.php
framework/base/Event.php
+6
-1
Module.php
framework/base/Module.php
+33
-68
No files found.
framework/YiiBase.php
View file @
a5b3932a
...
...
@@ -189,10 +189,12 @@ class YiiBase
/**
* Translates a path alias into an actual path.
*
* The path alias can be either a root alias registered via [[setAlias]] or an
* alias starting with a root alias (e.g. `@yii/base/Component.php`).
* In the latter case, the root alias will be replaced by the corresponding registered path
* and the remaining part will be appended to it.
*
* Note, this method does not ensure the existence of the resulting path.
* @param string $alias alias
* @return mixed path corresponding to the alias, false if the root alias is not previously registered.
...
...
@@ -214,12 +216,20 @@ class YiiBase
/**
* Registers a path alias.
*
* A path alias is a short name representing a path (a file path, a URL, etc.)
* A path alias must start with '@' (e.g. '@yii').
*
* Note that this method neither checks the existence of the path nor normalizes the path.
* Any trailing '/' and '\' characters in the path will be trimmed.
*
* @param string $alias alias to the path. The alias must start with '@'.
* @param string $path the path corresponding to the alias. If this is null, the corresponding
* path alias will be removed. The path can be a file path (e.g. `/tmp`) or a URL (e.g. `http://www.yiiframework.com`).
* @param string $path the path corresponding to the alias. This can be
*
* - a directory or a file path (e.g. `/tmp`, `/tmp/main.txt`)
* - a URL (e.g. `http://www.yiiframework.com`)
* - a path alias (e.g. `@yii/base`). In this case, the path alias will be converted into the
* actual path first by calling [[getAlias]].
* @see getAlias
*/
public
static
function
setAlias
(
$alias
,
$path
)
...
...
@@ -227,9 +237,15 @@ class YiiBase
if
(
$path
===
null
)
{
unset
(
self
::
$aliases
[
$alias
]);
}
else
{
else
if
(
$path
[
0
]
!==
'@'
)
{
self
::
$aliases
[
$alias
]
=
rtrim
(
$path
,
'\\/'
);
}
elseif
((
$p
=
self
::
getAlias
(
$path
))
!==
false
)
{
self
::
$aliases
[
$alias
]
=
$p
;
}
else
{
throw
new
\yii\base\Exception
(
'Invalid path: '
.
$path
);
}
}
/**
...
...
framework/base/Event.php
View file @
a5b3932a
...
...
@@ -16,7 +16,8 @@ namespace yii\base;
* The [[sender]] property describes who raises the event.
* And the [[handled]] property indicates if the event is handled.
* If an event handler sets [[handled]] to be true, the rest of the
* uninvoked handlers will be canceled.
* uninvoked handlers will no longer be called to handle the event.
* Additionally, an event may specify extra parameters via the [[params]] property.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
...
...
@@ -32,6 +33,10 @@ class Event extends Component
* When a handler sets this to be true, the rest of the uninvoked event handlers will be canceled.
*/
public
$handled
=
false
;
/**
* @var mixed extra parameters associated with the event.
*/
public
$params
;
/**
* Constructor.
...
...
framework/base/Module.php
View file @
a5b3932a
...
...
@@ -21,17 +21,24 @@ namespace yii\base;
abstract
class
Module
extends
Component
{
/**
* @var string the ID of this module. This should follow the same rule as naming PHP variables.
*/
public
$id
;
/**
* @var array custom module parameters (name => value).
*/
public
$params
=
array
();
/**
* @var array the IDs of the application components that should be preloaded.
*/
public
$preload
=
array
();
/**
* @var array the behaviors that should be attached to the module.
* The behaviors will be attached to the module when
{@link init}
is called.
* Please refer to
{@link CModel::behaviors}
on how to specify the value of this property.
* The behaviors will be attached to the module when
[[init]]
is called.
* Please refer to
[[Model::behaviors]]
on how to specify the value of this property.
*/
public
$behaviors
=
array
();
private
$_id
;
private
$_parentModule
;
private
$_basePath
;
private
$_modulePath
;
...
...
@@ -104,32 +111,13 @@ abstract class Module extends Component
}
/**
* Returns the module ID.
* @return string the module ID.
*/
public
function
getId
()
{
return
$this
->
_id
;
}
/**
* Sets the module ID.
* @param string $id the module ID
*/
public
function
setId
(
$id
)
{
$this
->
_id
=
$id
;
}
/**
* Returns the root directory of the module.
* @return string the root directory of the module. Defaults to the directory containing the module class.
*/
public
function
getBasePath
()
{
if
(
$this
->
_basePath
===
null
)
{
$class
=
new
ReflectionClass
(
get_class
(
$this
));
if
(
$this
->
_basePath
===
null
)
{
$class
=
new
ReflectionClass
(
$this
);
$this
->
_basePath
=
dirname
(
$class
->
getFileName
());
}
return
$this
->
_basePath
;
...
...
@@ -139,74 +127,51 @@ abstract class Module extends Component
* Sets the root directory of the module.
* This method can only be invoked at the beginning of the constructor.
* @param string $path the root directory of the module.
* @throws
C
Exception if the directory does not exist.
* @throws Exception if the directory does not exist.
*/
public
function
setBasePath
(
$path
)
{
if
((
$this
->
_basePath
=
realpath
(
$path
))
===
false
||
!
is_dir
(
$this
->
_basePath
))
throw
new
CException
(
Yii
::
t
(
'yii'
,
'Base path "{path}" is not a valid directory.'
,
array
(
'{path}'
=>
$path
)));
}
/**
* Returns user-defined parameters.
* @return CAttributeCollection the list of user-defined parameters
*/
public
function
getParams
()
{
if
(
$this
->
_params
!==
null
)
return
$this
->
_params
;
else
{
$this
->
_params
=
new
CAttributeCollection
;
$this
->
_params
->
caseSensitive
=
true
;
return
$this
->
_params
;
if
((
$this
->
_basePath
=
realpath
(
$path
))
===
false
||
!
is_dir
(
$this
->
_basePath
))
{
throw
new
Exception
(
'Invalid base path: '
.
$path
);
}
}
/**
* Sets user-defined parameters.
* @param array $value user-defined parameters. This should be in name-value pairs.
*/
public
function
setParams
(
$value
)
{
$params
=
$this
->
getParams
();
foreach
(
$value
as
$k
=>
$v
)
$params
->
add
(
$k
,
$v
);
}
/**
* Returns the directory that contains the application modules.
* @return string the directory that contains the application modules. Defaults to the 'modules' subdirectory of {@link basePath}.
* Returns the directory that contains child modules.
* @return string the directory that contains child modules. Defaults to the `modules` subdirectory under [[basePath]].
*/
public
function
getModulePath
()
{
if
(
$this
->
_modulePath
!==
null
)
if
(
$this
->
_modulePath
!==
null
)
{
return
$this
->
_modulePath
;
else
}
else
{
return
$this
->
_modulePath
=
$this
->
getBasePath
()
.
DIRECTORY_SEPARATOR
.
'modules'
;
}
}
/**
* Sets the directory that contains
the application
modules.
* @param string $value the directory that contains
the application
modules.
* @throws
C
Exception if the directory is invalid
* Sets the directory that contains
child
modules.
* @param string $value the directory that contains
child
modules.
* @throws Exception if the directory is invalid
*/
public
function
setModulePath
(
$value
)
{
if
((
$this
->
_modulePath
=
realpath
(
$value
))
===
false
||
!
is_dir
(
$this
->
_modulePath
))
throw
new
CException
(
Yii
::
t
(
'yii'
,
'The module path "{path}" is not a valid directory.'
,
array
(
'{path}'
=>
$value
)));
if
((
$this
->
_modulePath
=
realpath
(
$value
))
===
false
||
!
is_dir
(
$this
->
_modulePath
))
{
throw
new
Exception
(
'Invalid module path: '
.
$value
);
}
}
/**
* Sets the aliases that are used in the module.
* @param array $aliases list of aliases to be imported
* Imports the specified path aliases.
* This method is provided so that you can import a set of path aliases by module configuration.
* @param array $aliases list of path aliases to be imported
*/
public
function
setImport
(
$aliases
)
{
foreach
(
$aliases
as
$alias
)
Yii
::
import
(
$alias
);
foreach
(
$aliases
as
$alias
)
{
\Yii
::
import
(
$alias
);
}
}
/**
...
...
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