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
dbac35b1
Commit
dbac35b1
authored
Sep 04, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Removed description and help code duplication
parent
d74e89a1
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
73 additions
and
40 deletions
+73
-40
Action.php
framework/console/Action.php
+16
-15
Controller.php
framework/console/Controller.php
+32
-8
InlineAction.php
framework/console/InlineAction.php
+16
-15
HelpController.php
framework/console/controllers/HelpController.php
+9
-2
No files found.
framework/console/Action.php
View file @
dbac35b1
...
...
@@ -14,32 +14,33 @@ 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 a short description (one line) of information about the action.
*
* The default implementation returns help information retrieved from the PHPDoc comments.
*
* @return string
*/
public
function
getDescription
()
{
$class
=
new
\ReflectionClass
(
$this
);
$docLines
=
preg_split
(
'~(\n|\r|\r\n)~'
,
$class
->
getDocComment
());
if
(
isset
(
$docLines
[
1
]))
{
return
trim
(
$docLines
[
1
],
' *'
);
}
return
''
;
return
null
;
}
/**
* Returns help information for the action.
*
* The default implementation returns help information retrieved from the PHPDoc comments.
* @return string
*/
public
function
getHelp
()
{
$class
=
new
\ReflectionClass
(
$this
);
$comment
=
strtr
(
trim
(
preg_replace
(
'/^\s*\**( |\t)?/m'
,
''
,
trim
(
$class
->
getDocComment
(),
'/'
))),
"
\r
"
,
''
);
if
(
preg_match
(
'/^\s*@\w+/m'
,
$comment
,
$matches
,
PREG_OFFSET_CAPTURE
))
{
$comment
=
trim
(
substr
(
$comment
,
0
,
$matches
[
0
][
1
]));
}
if
(
$comment
!==
''
)
{
return
rtrim
(
Console
::
renderColoredString
(
Console
::
markdownToAnsi
(
$comment
)));
}
return
''
;
return
null
;
}
}
framework/console/Controller.php
View file @
dbac35b1
...
...
@@ -284,18 +284,30 @@ class Controller extends \yii\base\Controller
}
/**
* Returns a short description (one line) of information about this controller or
an action
.
* Returns a short description (one line) of information about this controller or
it's action (if specified)
.
*
* You may override this method to return customized
help information for this controller
.
* You may override this method to return customized
description
.
* The default implementation returns help information retrieved from the PHPDoc comments
* of the controller class.
*
* @param string $actionID action to get description for. null means overall controller description.
* @return string
*/
public
function
getDescription
()
public
function
getDescription
(
$actionID
=
null
)
{
$class
=
new
\ReflectionClass
(
$this
);
$docLines
=
preg_split
(
'~(\n|\r|\r\n)~'
,
$class
->
getDocComment
());
$action
=
null
;
if
(
$actionID
===
null
)
{
$class
=
new
\ReflectionClass
(
$this
);
}
else
{
$action
=
$this
->
createAction
(
$actionID
);
$class
=
new
\ReflectionClass
(
$action
);
}
if
(
$action
instanceof
InlineAction
)
{
$class
=
new
\ReflectionMethod
(
$this
,
$action
->
actionMethod
);
}
$docLines
=
preg_split
(
'~\R~'
,
$class
->
getDocComment
());
if
(
isset
(
$docLines
[
1
]))
{
return
trim
(
$docLines
[
1
],
' *'
);
}
...
...
@@ -303,15 +315,27 @@ class Controller extends \yii\base\Controller
}
/**
* Returns help information for this controller.
* Returns help information for this controller
or it's action (if specified)
.
*
* You may override this method to return customized help.
* The default implementation returns help information retrieved from the PHPDoc comments
* of the controller class.
* @param string $actionID action to get help for. null means overall controller help.
* @return string
*/
public
function
getHelp
()
public
function
getHelp
(
$actionID
=
null
)
{
$class
=
new
\ReflectionClass
(
$this
);
$action
=
null
;
if
(
$actionID
===
null
)
{
$class
=
new
\ReflectionClass
(
$this
);
}
else
{
$class
=
new
\ReflectionClass
(
$this
->
createAction
(
$actionID
));
}
if
(
$action
instanceof
InlineAction
)
{
$class
=
new
\ReflectionMethod
(
$this
,
$action
->
actionMethod
);
}
$comment
=
strtr
(
trim
(
preg_replace
(
'/^\s*\**( |\t)?/m'
,
''
,
trim
(
$class
->
getDocComment
(),
'/'
))),
"
\r
"
,
''
);
if
(
preg_match
(
'/^\s*@\w+/m'
,
$comment
,
$matches
,
PREG_OFFSET_CAPTURE
))
{
$comment
=
trim
(
substr
(
$comment
,
0
,
$matches
[
0
][
1
]));
...
...
framework/console/InlineAction.php
View file @
dbac35b1
...
...
@@ -20,26 +20,27 @@ use yii\helpers\Console;
*/
class
InlineAction
extends
\yii\base\InlineAction
{
/**
* Returns a short description (one line) of information about the action.
*
* The default implementation returns help information retrieved from the PHPDoc comments.
*
* @return string
*/
public
function
getDescription
()
{
$class
=
new
\ReflectionMethod
(
$this
->
controller
,
$this
->
actionMethod
);
$docLines
=
preg_split
(
'~(\n|\r|\r\n)~'
,
$class
->
getDocComment
());
if
(
isset
(
$docLines
[
1
]))
{
return
trim
(
$docLines
[
1
],
' *'
);
}
return
''
;
return
null
;
}
/**
* Returns help information for the action.
*
* The default implementation returns help information retrieved from the PHPDoc comments.
* @return string
*/
public
function
getHelp
()
{
$class
=
new
\ReflectionMethod
(
$this
->
controller
,
$this
->
actionMethod
);
$comment
=
strtr
(
trim
(
preg_replace
(
'/^\s*\**( |\t)?/m'
,
''
,
trim
(
$class
->
getDocComment
(),
'/'
))),
"
\r
"
,
''
);
if
(
preg_match
(
'/^\s*@\w+/m'
,
$comment
,
$matches
,
PREG_OFFSET_CAPTURE
))
{
$comment
=
trim
(
substr
(
$comment
,
0
,
$matches
[
0
][
1
]));
}
if
(
$comment
!==
''
)
{
return
rtrim
(
Console
::
renderColoredString
(
Console
::
markdownToAnsi
(
$comment
)));
}
return
''
;
return
null
;
}
}
framework/console/controllers/HelpController.php
View file @
dbac35b1
...
...
@@ -250,11 +250,15 @@ class HelpController extends Controller
*/
protected
function
getActionSummary
(
$controller
,
$actionID
)
{
$description
=
''
;
$action
=
$controller
->
createAction
(
$actionID
);
if
(
$action
instanceof
InlineAction
||
$action
instanceof
Action
)
{
return
$action
->
getDescription
();
$description
=
$action
->
getDescription
();
if
(
$description
===
null
)
{
$description
=
$controller
->
getDescription
(
$actionID
);
}
}
return
''
;
return
$description
;
}
/**
...
...
@@ -281,6 +285,9 @@ class HelpController extends Controller
$options
=
$this
->
getOptionHelps
(
$controller
,
$actionID
);
$description
=
$action
->
getHelp
();
if
(
$description
===
null
)
{
$description
=
$controller
->
getHelp
(
$actionID
);
}
if
(
$description
!==
''
)
{
$this
->
stdout
(
"
\n
DESCRIPTION
\n
"
,
Console
::
BOLD
);
$this
->
stdout
(
"
\n
$description
\n\n
"
);
...
...
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