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
b2662c0c
Commit
b2662c0c
authored
Feb 02, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean up help command.
parent
2d7f048b
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
118 additions
and
60 deletions
+118
-60
Action.php
framework/base/Action.php
+9
-0
Controller.php
framework/base/Controller.php
+1
-1
Application.php
framework/console/Application.php
+4
-4
Controller.php
framework/console/Controller.php
+18
-11
Exception.php
framework/console/Exception.php
+4
-4
Request.php
framework/console/Request.php
+4
-2
HelpController.php
framework/console/controllers/HelpController.php
+0
-0
MigrateController.php
framework/console/controllers/MigrateController.php
+78
-38
No files found.
framework/base/Action.php
View file @
b2662c0c
...
@@ -56,6 +56,15 @@ class Action extends Component
...
@@ -56,6 +56,15 @@ class Action extends Component
}
}
/**
/**
* Returns the unique ID of this action among the whole application.
* @return string the unique ID of this action among the whole application.
*/
public
function
getUniqueId
()
{
return
$this
->
controller
->
getUniqueId
()
.
'/'
.
$this
->
id
;
}
/**
* Runs this action with the specified parameters.
* Runs this action with the specified parameters.
* This method is mainly invoked by the controller.
* This method is mainly invoked by the controller.
* @param array $params the parameters to be bound to the action's run() method.
* @param array $params the parameters to be bound to the action's run() method.
...
...
framework/base/Controller.php
View file @
b2662c0c
...
@@ -250,7 +250,7 @@ class Controller extends Component
...
@@ -250,7 +250,7 @@ class Controller extends Component
*/
*/
public
function
getRoute
()
public
function
getRoute
()
{
{
return
$this
->
action
!==
null
?
$this
->
getUniqueId
()
.
'/'
.
$this
->
action
->
id
:
$this
->
getUniqueId
();
return
$this
->
action
!==
null
?
$this
->
action
->
getUniqueId
()
:
$this
->
getUniqueId
();
}
}
/**
/**
...
...
framework/console/Application.php
View file @
b2662c0c
...
@@ -9,7 +9,6 @@
...
@@ -9,7 +9,6 @@
namespace
yii\console
;
namespace
yii\console
;
use
yii\base\Exception
;
use
yii\base\InvalidRouteException
;
use
yii\base\InvalidRouteException
;
/**
/**
...
@@ -85,6 +84,7 @@ class Application extends \yii\base\Application
...
@@ -85,6 +84,7 @@ class Application extends \yii\base\Application
* Processes the request.
* Processes the request.
* The request is represented in terms of a controller route and action parameters.
* The request is represented in terms of a controller route and action parameters.
* @return integer the exit status of the controller action (0 means normal, non-zero values mean abnormal)
* @return integer the exit status of the controller action (0 means normal, non-zero values mean abnormal)
* @throws Exception if the script is not running from the command line
*/
*/
public
function
processRequest
()
public
function
processRequest
()
{
{
...
@@ -93,7 +93,7 @@ class Application extends \yii\base\Application
...
@@ -93,7 +93,7 @@ class Application extends \yii\base\Application
if
(
$request
->
getIsConsoleRequest
())
{
if
(
$request
->
getIsConsoleRequest
())
{
return
$this
->
runAction
(
$request
->
route
,
$request
->
params
);
return
$this
->
runAction
(
$request
->
route
,
$request
->
params
);
}
else
{
}
else
{
throw
new
BadUsage
Exception
(
\Yii
::
t
(
'yii'
,
'this script must be run from the command line.'
));
throw
new
Exception
(
\Yii
::
t
(
'yii'
,
'this script must be run from the command line.'
));
}
}
}
}
...
@@ -105,14 +105,14 @@ class Application extends \yii\base\Application
...
@@ -105,14 +105,14 @@ class Application extends \yii\base\Application
* @param string $route the route that specifies the action.
* @param string $route the route that specifies the action.
* @param array $params the parameters to be passed to the action
* @param array $params the parameters to be passed to the action
* @return integer the status code returned by the action execution. 0 means normal, and other values mean abnormal.
* @return integer the status code returned by the action execution. 0 means normal, and other values mean abnormal.
* @throws
BadUsage
Exception if the route is invalid
* @throws Exception if the route is invalid
*/
*/
public
function
runAction
(
$route
,
$params
=
array
())
public
function
runAction
(
$route
,
$params
=
array
())
{
{
try
{
try
{
return
parent
::
runAction
(
$route
,
$params
);
return
parent
::
runAction
(
$route
,
$params
);
}
catch
(
InvalidRouteException
$e
)
{
}
catch
(
InvalidRouteException
$e
)
{
throw
new
BadUsage
Exception
(
\Yii
::
t
(
'yii'
,
'Unknown command "{command}".'
,
array
(
'{command}'
=>
$route
)));
throw
new
Exception
(
\Yii
::
t
(
'yii'
,
'Unknown command "{command}".'
,
array
(
'{command}'
=>
$route
)));
}
}
}
}
...
...
framework/console/Controller.php
View file @
b2662c0c
...
@@ -48,14 +48,11 @@ class Controller extends \yii\base\Controller
...
@@ -48,14 +48,11 @@ class Controller extends \yii\base\Controller
public
function
runAction
(
$id
,
$params
=
array
())
public
function
runAction
(
$id
,
$params
=
array
())
{
{
if
(
$params
!==
array
())
{
if
(
$params
!==
array
())
{
$
class
=
new
\ReflectionClass
(
$this
);
$
options
=
$this
->
globalOptions
(
);
foreach
(
$params
as
$name
=>
$value
)
{
foreach
(
$params
as
$name
=>
$value
)
{
if
(
$class
->
hasProperty
(
$name
))
{
if
(
in_array
(
$name
,
$options
,
true
))
{
$property
=
$class
->
getProperty
(
$name
);
$this
->
$name
=
$value
;
if
(
$property
->
isPublic
()
&&
!
$property
->
isStatic
()
&&
$property
->
getDeclaringClass
()
->
getName
()
===
get_class
(
$this
))
{
unset
(
$params
[
$name
]);
$this
->
$name
=
$value
;
unset
(
$params
[
$name
]);
}
}
}
}
}
}
}
...
@@ -69,16 +66,19 @@ class Controller extends \yii\base\Controller
...
@@ -69,16 +66,19 @@ class Controller extends \yii\base\Controller
* @param Action $action the currently requested action
* @param Action $action the currently requested action
* @param array $missingParams the names of the missing parameters
* @param array $missingParams the names of the missing parameters
* @param array $unknownParams the unknown parameters (name=>value)
* @param array $unknownParams the unknown parameters (name=>value)
* @throws
BadUsage
Exception if there are missing or unknown parameters
* @throws Exception if there are missing or unknown parameters
*/
*/
public
function
validateActionParams
(
$action
,
$missingParams
,
$unknownParams
)
public
function
validateActionParams
(
$action
,
$missingParams
,
$unknownParams
)
{
{
unset
(
$missingParams
[
Request
::
ANONYMOUS_PARAMS
],
$unknownParams
[
Request
::
ANONYMOUS_PARAMS
]);
if
(
!
empty
(
$missingParams
))
{
if
(
!
empty
(
$missingParams
))
{
throw
new
BadUsage
Exception
(
Yii
::
t
(
'yii'
,
'Missing required options: {params}'
,
array
(
throw
new
Exception
(
Yii
::
t
(
'yii'
,
'Missing required options: {params}'
,
array
(
'{params}'
=>
implode
(
', '
,
$missingParams
),
'{params}'
=>
implode
(
', '
,
$missingParams
),
)));
)));
}
elseif
(
!
empty
(
$unknownParams
))
{
}
throw
new
BadUsageException
(
Yii
::
t
(
'yii'
,
'Unknown options: {params}'
,
array
(
if
(
!
empty
(
$unknownParams
))
{
throw
new
Exception
(
Yii
::
t
(
'yii'
,
'Unknown options: {params}'
,
array
(
'{params}'
=>
implode
(
', '
,
$unknownParams
),
'{params}'
=>
implode
(
', '
,
$unknownParams
),
)));
)));
}
}
...
@@ -102,6 +102,13 @@ class Controller extends \yii\base\Controller
...
@@ -102,6 +102,13 @@ class Controller extends \yii\base\Controller
}
}
}
}
/**
* Returns the names of the global options for this command.
* A global option requires the existence of a global member variable whose
* name is the option name.
* Child classes may override this method to specify possible global options.
* @return array the names of the global options for this command.
*/
public
function
globalOptions
()
public
function
globalOptions
()
{
{
return
array
();
return
array
();
...
...
framework/console/
BadUsage
Exception.php
→
framework/console/Exception.php
View file @
b2662c0c
<?php
<?php
/**
/**
*
BadUsage
Exception class file.
* Exception class file.
*
*
* @link http://www.yiiframework.com/
* @link http://www.yiiframework.com/
* @copyright Copyright © 2008 Yii Software LLC
* @copyright Copyright © 2008 Yii Software LLC
...
@@ -10,12 +10,12 @@
...
@@ -10,12 +10,12 @@
namespace
yii\console
;
namespace
yii\console
;
/**
/**
*
BadUsageException represents an exception caused by incorrect usage of the end user
.
*
Exception represents an exception caused by incorrect usage of a console command
.
*
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
* @since 2.0
*/
*/
class
BadUsage
Exception
extends
\yii\base\Exception
class
Exception
extends
\yii\base\Exception
{
{
/**
/**
* @var boolean whether this exception is caused by end user's mistake (e.g. wrong URL)
* @var boolean whether this exception is caused by end user's mistake (e.g. wrong URL)
...
@@ -27,7 +27,7 @@ class BadUsageException extends \yii\base\Exception
...
@@ -27,7 +27,7 @@ class BadUsageException extends \yii\base\Exception
*/
*/
public
function
getName
()
public
function
getName
()
{
{
return
\Yii
::
t
(
'yii'
,
'
Bad Usage
'
);
return
\Yii
::
t
(
'yii'
,
'
Error
'
);
}
}
}
}
framework/console/Request.php
View file @
b2662c0c
...
@@ -15,6 +15,8 @@ namespace yii\console;
...
@@ -15,6 +15,8 @@ namespace yii\console;
*/
*/
class
Request
extends
\yii\base\Request
class
Request
extends
\yii\base\Request
{
{
const
ANONYMOUS_PARAMS
=
'args'
;
/**
/**
* @var string the controller route specified by this request. If this is an empty string,
* @var string the controller route specified by this request. If this is an empty string,
* it means the [[Application::defaultRoute|default route]] will be used.
* it means the [[Application::defaultRoute|default route]] will be used.
...
@@ -50,13 +52,13 @@ class Request extends \yii\base\Request
...
@@ -50,13 +52,13 @@ class Request extends \yii\base\Request
$this
->
route
=
''
;
$this
->
route
=
''
;
}
}
$this
->
params
=
array
();
$this
->
params
=
array
(
self
::
ANONYMOUS_PARAMS
=>
array
()
);
foreach
(
$rawParams
as
$param
)
{
foreach
(
$rawParams
as
$param
)
{
if
(
preg_match
(
'/^--(\w+)(=(.*))?$/'
,
$param
,
$matches
))
{
if
(
preg_match
(
'/^--(\w+)(=(.*))?$/'
,
$param
,
$matches
))
{
$name
=
$matches
[
1
];
$name
=
$matches
[
1
];
$this
->
params
[
$name
]
=
isset
(
$matches
[
3
])
?
$matches
[
3
]
:
true
;
$this
->
params
[
$name
]
=
isset
(
$matches
[
3
])
?
$matches
[
3
]
:
true
;
}
else
{
}
else
{
$this
->
params
[
'args'
][]
=
$param
;
$this
->
params
[
self
::
ANONYMOUS_PARAMS
][]
=
$param
;
}
}
}
}
}
}
...
...
framework/console/controllers/HelpController.php
View file @
b2662c0c
This diff is collapsed.
Click to expand it.
framework/console/controllers/MigrateController.php
View file @
b2662c0c
This diff is collapsed.
Click to expand it.
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