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
fadfdf69
Commit
fadfdf69
authored
Sep 04, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactored help system. [skip ci]
parent
7efb47bf
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
126 deletions
+40
-126
Action.php
framework/console/Action.php
+0
-48
Controller.php
framework/console/Controller.php
+19
-33
HelpController.php
framework/console/controllers/HelpController.php
+18
-42
BaseConsole.php
framework/helpers/BaseConsole.php
+3
-3
No files found.
framework/console/Action.php
deleted
100644 → 0
View file @
7efb47bf
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\console
;
use
Yii
;
use
yii\helpers\Console
;
/**
* Action is the base class for all controller action classes.
*
* @inheritdoc
* @property \yii\console\Controller $controller
*
* @author Carsten Brandt <mail@cebe.cc>
* @since 2.0
*/
class
Action
extends
\yii\base\Action
{
/**
* Returns one-line short summary describing this action.
*
* You may override this method to return customized summary.
* The default implementation returns first line from the PHPDoc comment.
*
* @return string
*/
public
function
getHelpSummary
()
{
return
HelpParser
::
getSummary
(
new
\ReflectionClass
(
$this
));
}
/**
* Returns help information for this action.
*
* You may override this method to return customized help.
* The default implementation returns help information retrieved from the PHPDoc comment.
* @return string
*/
public
function
getHelp
()
{
return
HelpParser
::
getDetail
(
new
\ReflectionClass
(
$this
));
}
}
framework/console/Controller.php
View file @
fadfdf69
...
...
@@ -289,27 +289,6 @@ class Controller extends \yii\base\Controller
}
/**
* Returns one-line short summary describing this controller action.
*
* You may override this method to return customized summary.
* The default implementation returns first line from the PHPDoc comment.
*
* @param string $actionID action to get summary for
* @return string
*/
public
function
getActionHelpSummary
(
$actionID
)
{
$action
=
$this
->
createAction
(
$actionID
);
if
(
$action
instanceof
InlineAction
)
{
$class
=
new
\ReflectionMethod
(
$this
,
$action
->
actionMethod
);
}
else
{
$class
=
new
\ReflectionClass
(
$action
);
}
return
HelpParser
::
getSummary
(
$class
);
}
/**
* Returns help information for this controller.
*
* You may override this method to return customized help.
...
...
@@ -322,23 +301,30 @@ class Controller extends \yii\base\Controller
}
/**
* Returns help information for this controller action.
*
* You may override this method to return customized help.
* The default implementation returns help information retrieved from the PHPDoc comment.
* @param string $actionID action to get help for
* @return string
* Returns a one-line short summary describing the specified action.
* @param \yii\base\Action $action action to get summary for
* @return string a one-line short summary describing the specified action.
*/
public
function
getActionHelp
(
$actionID
)
public
function
getActionHelp
Summary
(
$action
)
{
$action
=
$this
->
createAction
(
$actionID
);
if
(
$action
instanceof
InlineAction
)
{
$class
=
new
\ReflectionMethod
(
$this
,
$action
->
actionMethod
);
return
HelpParser
::
getSummary
(
new
\ReflectionMethod
(
$this
,
$action
->
actionMethod
)
);
}
else
{
$class
=
new
\ReflectionClass
(
$action
);
return
HelpParser
::
getSummary
(
new
\ReflectionMethod
(
$action
,
'run'
)
);
}
}
return
HelpParser
::
getDetail
(
$class
);
/**
* Returns the detailed help information for the specified action.
* @param \yii\base\Action $action action to get help for
* @return string the detailed help information for the specified action.
*/
public
function
getActionHelp
(
$action
)
{
if
(
$action
instanceof
InlineAction
)
{
return
HelpParser
::
getDetail
(
new
\ReflectionMethod
(
$this
,
$action
->
actionMethod
));
}
else
{
return
HelpParser
::
getDetail
(
new
\ReflectionMethod
(
$action
,
'run'
));
}
}
}
framework/console/controllers/HelpController.php
View file @
fadfdf69
...
...
@@ -62,12 +62,12 @@ class HelpController extends Controller
$actions
=
$this
->
getActions
(
$controller
);
if
(
$actionID
!==
''
||
count
(
$actions
)
===
1
&&
$actions
[
0
]
===
$controller
->
defaultAction
)
{
$this
->
get
ControllerAction
Help
(
$controller
,
$actionID
);
$this
->
get
SubCommand
Help
(
$controller
,
$actionID
);
}
else
{
$this
->
getCo
ntroller
Help
(
$controller
);
$this
->
getCo
mmand
Help
(
$controller
);
}
}
else
{
$this
->
get
Global
Help
();
$this
->
get
Default
Help
();
}
}
...
...
@@ -182,7 +182,7 @@ class HelpController extends Controller
/**
* Displays all available commands.
*/
protected
function
get
Global
Help
()
protected
function
get
Default
Help
()
{
$commands
=
$this
->
getCommandDescriptions
();
if
(
!
empty
(
$commands
))
{
...
...
@@ -211,7 +211,7 @@ class HelpController extends Controller
* Displays the overall information of the command.
* @param Controller $controller the controller instance
*/
protected
function
getCo
ntroller
Help
(
$controller
)
protected
function
getCo
mmand
Help
(
$controller
)
{
$controller
->
color
=
$this
->
color
;
...
...
@@ -230,7 +230,7 @@ class HelpController extends Controller
if
(
$action
===
$controller
->
defaultAction
)
{
$this
->
stdout
(
' (default)'
,
Console
::
FG_GREEN
);
}
$summary
=
$
this
->
getActionSummary
(
$controller
,
$action
);
$summary
=
$
controller
->
getActionHelpSummary
(
$controller
->
createAction
(
$action
)
);
if
(
$summary
!==
''
)
{
echo
': '
.
$summary
;
}
...
...
@@ -244,32 +244,12 @@ class HelpController extends Controller
}
/**
* Returns the short summary of the action.
* @param Controller $controller the controller instance
* @param string $actionID action ID
* @return string the summary about the action
*/
protected
function
getActionSummary
(
$controller
,
$actionID
)
{
$description
=
null
;
$action
=
$controller
->
createAction
(
$actionID
);
if
(
$action
instanceof
Action
)
{
$description
=
$action
->
getHelpSummary
();
}
if
(
$description
===
null
)
{
$description
=
$controller
->
getActionHelpSummary
(
$actionID
);
}
return
$description
;
}
/**
* Displays the detailed information of a command action.
* @param Controller $controller the controller instance
* @param string $actionID action ID
* @throws Exception if the action does not exist
*/
protected
function
get
ControllerAction
Help
(
$controller
,
$actionID
)
protected
function
get
SubCommand
Help
(
$controller
,
$actionID
)
{
$action
=
$controller
->
createAction
(
$actionID
);
if
(
$action
===
null
)
{
...
...
@@ -277,22 +257,9 @@ class HelpController extends Controller
'command'
=>
rtrim
(
$controller
->
getUniqueId
()
.
'/'
.
$actionID
,
'/'
),
]));
}
$description
=
null
;
if
(
$action
instanceof
InlineAction
)
{
$method
=
new
\ReflectionMethod
(
$controller
,
$action
->
actionMethod
);
}
else
{
/** @var Action $action */
$description
=
$action
->
getHelp
();
$method
=
new
\ReflectionMethod
(
$action
,
'run'
);
}
$tags
=
$this
->
parseComment
(
$method
->
getDocComment
());
$options
=
$this
->
getOptionHelps
(
$controller
,
$actionID
);
if
(
$description
===
null
)
{
$description
=
$controller
->
getActionHelp
(
$actionID
);
}
if
(
$description
!==
''
)
{
$description
=
$controller
->
getActionHelp
(
$action
);
if
(
$description
!=
''
)
{
$this
->
stdout
(
"
\n
DESCRIPTION
\n
"
,
Console
::
BOLD
);
$this
->
stdout
(
"
\n
$description
\n\n
"
);
}
...
...
@@ -304,6 +271,15 @@ class HelpController extends Controller
}
else
{
echo
$scriptName
.
' '
.
$this
->
ansiFormat
(
$action
->
getUniqueId
(),
Console
::
FG_YELLOW
);
}
if
(
$action
instanceof
InlineAction
)
{
$method
=
new
\ReflectionMethod
(
$controller
,
$action
->
actionMethod
);
}
else
{
$method
=
new
\ReflectionMethod
(
$action
,
'run'
);
}
$tags
=
$this
->
parseComment
(
$method
->
getDocComment
());
$options
=
$this
->
getOptionHelps
(
$controller
,
$actionID
);
list
(
$required
,
$optional
)
=
$this
->
getArgHelps
(
$method
,
isset
(
$tags
[
'param'
])
?
$tags
[
'param'
]
:
[]);
foreach
(
$required
as
$arg
=>
$description
)
{
$this
->
stdout
(
' <'
.
$arg
.
'>'
,
Console
::
FG_CYAN
);
...
...
framework/helpers/BaseConsole.php
View file @
fadfdf69
...
...
@@ -491,15 +491,15 @@ class BaseConsole
* </pre>
* First param is the string to convert, second is an optional flag if
* colors should be used. It defaults to true, if set to false, the
* colorcodes will just be removed (And %% will be transformed into %)
* color
codes will just be removed (And %% will be transformed into %)
*
* @param string $string String to convert
* @param boolean $colored Should the string be colored?
* @return string
*/
// TODO rework/refactor according to https://github.com/yiisoft/yii2/issues/746
public
static
function
renderColoredString
(
$string
,
$colored
=
true
)
{
// TODO rework/refactor according to https://github.com/yiisoft/yii2/issues/746
static
$conversions
=
[
'%y'
=>
[
self
::
FG_YELLOW
],
'%g'
=>
[
self
::
FG_GREEN
],
...
...
@@ -562,9 +562,9 @@ class BaseConsole
* @access public
* @return string
*/
// TODO rework/refactor according to https://github.com/yiisoft/yii2/issues/746
public
static
function
escape
(
$string
)
{
// TODO rework/refactor according to https://github.com/yiisoft/yii2/issues/746
return
str_replace
(
'%'
,
'%%'
,
$string
);
}
...
...
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