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
4c2fcd76
Commit
4c2fcd76
authored
Apr 10, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactored application.
parent
55e8db9b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
36 deletions
+42
-36
Application.php
framework/base/Application.php
+10
-20
Module.php
framework/base/Module.php
+0
-1
Application.php
framework/web/Application.php
+4
-10
Request.php
framework/web/Request.php
+28
-5
No files found.
framework/base/Application.php
View file @
4c2fcd76
...
...
@@ -113,29 +113,27 @@ class Application extends Module
if
(
isset
(
$config
[
'basePath'
]))
{
$this
->
setBasePath
(
$config
[
'basePath'
]);
unset
(
$config
[
'basePath'
]);
Yii
::
$aliases
[
'@app'
]
=
$this
->
getBasePath
();
}
else
{
throw
new
InvalidConfigException
(
'The "basePath" configuration is required.'
);
}
if
(
YII_ENABLE_ERROR_HANDLER
)
{
ini_set
(
'display_errors'
,
0
);
set_exception_handler
(
array
(
$this
,
'handleException'
));
set_error_handler
(
array
(
$this
,
'handleError'
),
error_reporting
());
}
$this
->
registerDefaultAliases
();
$this
->
registerErrorHandlers
();
$this
->
registerCoreComponents
();
Compon
ent
::
__construct
(
$config
);
par
ent
::
__construct
(
$config
);
}
/**
* Initializes the application by loading components declared in [[preload]].
* If you override this method, make sure the parent implementation is invoked.
* Registers error handlers.
*/
public
function
init
()
public
function
registerErrorHandlers
()
{
$this
->
preloadComponents
();
if
(
YII_ENABLE_ERROR_HANDLER
)
{
ini_set
(
'display_errors'
,
0
);
set_exception_handler
(
array
(
$this
,
'handleException'
));
set_error_handler
(
array
(
$this
,
'handleError'
),
error_reporting
());
}
}
/**
...
...
@@ -339,14 +337,6 @@ class Application extends Module
}
/**
* Sets default path aliases.
*/
public
function
registerDefaultAliases
()
{
Yii
::
$aliases
[
'@app'
]
=
$this
->
getBasePath
();
}
/**
* Registers the core application components.
* @see setComponents
*/
...
...
framework/base/Module.php
View file @
4c2fcd76
...
...
@@ -170,7 +170,6 @@ abstract class Module extends Component
*/
public
function
init
()
{
Yii
::
setAlias
(
'@'
.
$this
->
id
,
$this
->
getBasePath
());
$this
->
preloadComponents
();
}
...
...
framework/web/Application.php
View file @
4c2fcd76
...
...
@@ -23,21 +23,15 @@ class Application extends \yii\base\Application
public
$defaultRoute
=
'site'
;
/**
* Sets default path aliases.
*/
public
function
registerDefaultAliases
()
{
parent
::
registerDefaultAliases
();
Yii
::
$aliases
[
'@webroot'
]
=
dirname
(
$_SERVER
[
'SCRIPT_FILENAME'
]);
}
/**
* Processes the request.
* @return integer the exit status of the controller action (0 means normal, non-zero values mean abnormal)
*/
public
function
processRequest
()
{
list
(
$route
,
$params
)
=
$this
->
getRequest
()
->
resolve
();
$request
=
$this
->
getRequest
();
Yii
::
setAlias
(
'@wwwroot'
,
dirname
(
$request
->
getScriptFile
()));
Yii
::
setAlias
(
'@www'
,
$request
->
getBaseUrl
());
list
(
$route
,
$params
)
=
$request
->
resolve
();
return
$this
->
runAction
(
$route
,
$params
);
}
...
...
framework/web/Request.php
View file @
4c2fcd76
...
...
@@ -43,8 +43,6 @@ class Request extends \yii\base\Request
*/
public
function
resolve
()
{
Yii
::
setAlias
(
'@www'
,
$this
->
getBaseUrl
());
$result
=
Yii
::
$app
->
getUrlManager
()
->
parseRequest
(
$this
);
if
(
$result
!==
false
)
{
list
(
$route
,
$params
)
=
$result
;
...
...
@@ -301,7 +299,8 @@ class Request extends \yii\base\Request
public
function
getScriptUrl
()
{
if
(
$this
->
_scriptUrl
===
null
)
{
$scriptName
=
basename
(
$_SERVER
[
'SCRIPT_FILENAME'
]);
$scriptFile
=
$this
->
getScriptFile
();
$scriptName
=
basename
(
$scriptFile
);
if
(
basename
(
$_SERVER
[
'SCRIPT_NAME'
])
===
$scriptName
)
{
$this
->
_scriptUrl
=
$_SERVER
[
'SCRIPT_NAME'
];
}
elseif
(
basename
(
$_SERVER
[
'PHP_SELF'
])
===
$scriptName
)
{
...
...
@@ -310,8 +309,8 @@ class Request extends \yii\base\Request
$this
->
_scriptUrl
=
$_SERVER
[
'ORIG_SCRIPT_NAME'
];
}
elseif
((
$pos
=
strpos
(
$_SERVER
[
'PHP_SELF'
],
'/'
.
$scriptName
))
!==
false
)
{
$this
->
_scriptUrl
=
substr
(
$_SERVER
[
'SCRIPT_NAME'
],
0
,
$pos
)
.
'/'
.
$scriptName
;
}
elseif
(
isset
(
$_SERVER
[
'DOCUMENT_ROOT'
])
&&
strpos
(
$
_SERVER
[
'SCRIPT_FILENAME'
]
,
$_SERVER
[
'DOCUMENT_ROOT'
])
===
0
)
{
$this
->
_scriptUrl
=
str_replace
(
'\\'
,
'/'
,
str_replace
(
$_SERVER
[
'DOCUMENT_ROOT'
],
''
,
$
_SERVER
[
'SCRIPT_FILENAME'
]
));
}
elseif
(
isset
(
$_SERVER
[
'DOCUMENT_ROOT'
])
&&
strpos
(
$
scriptFile
,
$_SERVER
[
'DOCUMENT_ROOT'
])
===
0
)
{
$this
->
_scriptUrl
=
str_replace
(
'\\'
,
'/'
,
str_replace
(
$_SERVER
[
'DOCUMENT_ROOT'
],
''
,
$
scriptFile
));
}
else
{
throw
new
InvalidConfigException
(
'Unable to determine the entry script URL.'
);
}
...
...
@@ -330,6 +329,30 @@ class Request extends \yii\base\Request
$this
->
_scriptUrl
=
'/'
.
trim
(
$value
,
'/'
);
}
private
$_scriptFile
;
/**
* Returns the entry script file path.
* The default implementation will simply return `$_SERVER['SCRIPT_FILENAME']`.
* @return string the entry script file path
*/
public
function
getScriptFile
()
{
return
isset
(
$this
->
_scriptFile
)
?
$this
->
_scriptFile
:
$_SERVER
[
'SCRIPT_FILENAME'
];
}
/**
* Sets the entry script file path.
* The entry script file path normally can be obtained from `$_SERVER['SCRIPT_FILENAME']`.
* If your server configuration does not return the correct value, you may configure
* this property to make it right.
* @param string $value the entry script file path.
*/
public
function
setScriptFile
(
$value
)
{
$this
->
_scriptFile
=
$value
;
}
private
$_pathInfo
;
/**
...
...
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