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
21440d7a
Commit
21440d7a
authored
Sep 04, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Moved common help parsing code into HelpParser. Action methods now have default implementation.
parent
d44f4248
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
111 additions
and
50 deletions
+111
-50
Action.php
framework/console/Action.php
+9
-7
Controller.php
framework/console/Controller.php
+39
-36
HelpParser.php
framework/console/HelpParser.php
+53
-0
HelpController.php
framework/console/controllers/HelpController.php
+10
-7
No files found.
framework/console/Action.php
View file @
21440d7a
...
...
@@ -22,25 +22,27 @@ use yii\helpers\Console;
class
Action
extends
\yii\base\Action
{
/**
* Returns
a short description (one line) of information about the
action.
* Returns
one-line short summary describing this
action.
*
* The default implementation returns help information retrieved from the PHPDoc comments.
* You may override this method to return customized summary.
* The default implementation returns first line from the PHPDoc comment.
*
* @return string
*/
public
function
get
Description
()
public
function
get
HelpSummary
()
{
return
null
;
return
HelpParser
::
getSummary
(
new
\ReflectionClass
(
$this
))
;
}
/**
* Returns help information for th
e
action.
* Returns help information for th
is
action.
*
* The default implementation returns help information retrieved from the PHPDoc comments.
* 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
null
;
return
HelpParser
::
getDescriptionForConsole
(
new
\ReflectionClass
(
$this
))
;
}
}
framework/console/Controller.php
View file @
21440d7a
...
...
@@ -9,6 +9,7 @@ namespace yii\console;
use
Yii
;
use
yii\base\Action
;
use
yii\base\InlineAction
;
use
yii\base\InvalidRouteException
;
use
yii\helpers\Console
;
...
...
@@ -99,7 +100,7 @@ class Controller extends \yii\base\Controller
*/
public
function
bindActionParams
(
$action
,
$params
)
{
if
(
$action
instanceof
\yii\base\
InlineAction
)
{
if
(
$action
instanceof
InlineAction
)
{
$method
=
new
\ReflectionMethod
(
$this
,
$action
->
actionMethod
);
}
else
{
$method
=
new
\ReflectionMethod
(
$action
,
'run'
);
...
...
@@ -275,67 +276,69 @@ class Controller extends \yii\base\Controller
}
/**
* Returns
a short description (one line) of information about this controller or it's action (if specified)
.
* Returns
one-line short summary describing 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.
* 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 description for. null means overall controller description.
* @return string
*/
public
function
getDescription
(
$actionID
=
null
)
public
function
getHelpSummary
()
{
return
HelpParser
::
getSummary
(
new
\ReflectionClass
(
$this
));
}
/**
* 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
=
null
;
if
(
$actionID
===
null
)
{
$class
=
new
\ReflectionClass
(
$this
);
}
else
{
$action
=
$this
->
createAction
(
$actionID
);
if
(
$action
instanceof
\yii\base\
InlineAction
)
{
if
(
$action
instanceof
InlineAction
)
{
$class
=
new
\ReflectionMethod
(
$this
,
$action
->
actionMethod
);
}
else
{
$class
=
new
\ReflectionClass
(
$action
);
}
}
$docLines
=
preg_split
(
'~\R~'
,
$class
->
getDocComment
());
if
(
isset
(
$docLines
[
1
]))
{
return
trim
(
$docLines
[
1
],
' *'
);
return
HelpParser
::
getSummary
(
$class
);
}
return
''
;
/**
* Returns help information for this controller.
*
* 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
::
getFull
(
new
\ReflectionClass
(
$this
));
}
/**
* Returns help information for this controller
or it's action (if specified)
.
* 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 comments
* of the controller class.
* @param string $actionID action to get help for. null means overall controller help.
* The default implementation returns help information retrieved from the PHPDoc comment.
* @param string $actionID action to get help for
* @return string
*/
public
function
get
Help
(
$actionID
=
null
)
public
function
get
ActionHelp
(
$actionID
)
{
$action
=
null
;
if
(
$actionID
===
null
)
{
$class
=
new
\ReflectionClass
(
$this
);
}
else
{
$action
=
$this
->
createAction
(
$actionID
);
if
(
$action
instanceof
\yii\base\
InlineAction
)
{
if
(
$action
instanceof
InlineAction
)
{
$class
=
new
\ReflectionMethod
(
$this
,
$action
->
actionMethod
);
}
else
{
$class
=
new
\ReflectionClass
(
$action
);
}
}
$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
HelpParser
::
getFull
(
$class
);
}
}
framework/console/HelpParser.php
0 → 100644
View file @
21440d7a
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\console
;
use
yii\helpers\Console
;
/**
* HelpParser contains methods used to get help information from phpDoc.
*
* @author Alexander Makarov <sam@rmcreative.ru>
* @since 2.0
*/
class
HelpParser
{
/**
* Returns the first line of docblock.
*
* @param \Reflector $reflector
* @return string
*/
public
static
function
getSummary
(
\Reflector
$reflector
)
{
$docLines
=
preg_split
(
'~\R~'
,
$reflector
->
getDocComment
());
if
(
isset
(
$docLines
[
1
]))
{
return
trim
(
$docLines
[
1
],
' *'
);
}
return
''
;
}
/**
* Returns full description from the docblock.
*
* @param \Reflector $reflector
* @return string
*/
public
static
function
getFull
(
\Reflector
$reflector
)
{
$comment
=
strtr
(
trim
(
preg_replace
(
'/^\s*\**( |\t)?/m'
,
''
,
trim
(
$reflector
->
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
''
;
}
}
\ No newline at end of file
framework/console/controllers/HelpController.php
View file @
21440d7a
...
...
@@ -9,6 +9,7 @@ namespace yii\console\controllers;
use
Yii
;
use
yii\base\Application
;
use
yii\base\InlineAction
;
use
yii\console\Action
;
use
yii\console\Controller
;
use
yii\console\Exception
;
...
...
@@ -61,7 +62,7 @@ class HelpController extends Controller
$actions
=
$this
->
getActions
(
$controller
);
if
(
$actionID
!==
''
||
count
(
$actions
)
===
1
&&
$actions
[
0
]
===
$controller
->
defaultAction
)
{
$this
->
getActionHelp
(
$controller
,
$actionID
);
$this
->
get
Controller
ActionHelp
(
$controller
,
$actionID
);
}
else
{
$this
->
getControllerHelp
(
$controller
);
}
...
...
@@ -94,7 +95,8 @@ class HelpController extends Controller
$result
=
Yii
::
$app
->
createController
(
$command
);
if
(
$result
!==
false
)
{
list
(
$controller
,
$actionID
)
=
$result
;
$description
=
$controller
->
getDescription
();
/** @var Controller $controller */
$description
=
$controller
->
getHelpSummary
();
}
$descriptions
[
$command
]
=
$description
;
...
...
@@ -253,10 +255,10 @@ class HelpController extends Controller
$action
=
$controller
->
createAction
(
$actionID
);
if
(
$action
instanceof
Action
)
{
$description
=
$action
->
get
Description
();
$description
=
$action
->
get
HelpSummary
();
}
if
(
$description
===
null
)
{
$description
=
$controller
->
get
Description
(
$actionID
);
$description
=
$controller
->
get
ActionHelpSummary
(
$actionID
);
}
return
$description
;
}
...
...
@@ -267,7 +269,7 @@ class HelpController extends Controller
* @param string $actionID action ID
* @throws Exception if the action does not exist
*/
protected
function
getActionHelp
(
$controller
,
$actionID
)
protected
function
get
Controller
ActionHelp
(
$controller
,
$actionID
)
{
$action
=
$controller
->
createAction
(
$actionID
);
if
(
$action
===
null
)
{
...
...
@@ -276,9 +278,10 @@ class HelpController extends Controller
]));
}
$description
=
null
;
if
(
$action
instanceof
\yii\base\
InlineAction
)
{
if
(
$action
instanceof
InlineAction
)
{
$method
=
new
\ReflectionMethod
(
$controller
,
$action
->
actionMethod
);
}
else
{
/** @var Action $action */
$description
=
$action
->
getHelp
();
$method
=
new
\ReflectionMethod
(
$action
,
'run'
);
}
...
...
@@ -287,7 +290,7 @@ class HelpController extends Controller
$options
=
$this
->
getOptionHelps
(
$controller
,
$actionID
);
if
(
$description
===
null
)
{
$description
=
$controller
->
getHelp
(
$actionID
);
$description
=
$controller
->
get
Action
Help
(
$actionID
);
}
if
(
$description
!==
''
)
{
$this
->
stdout
(
"
\n
DESCRIPTION
\n
"
,
Console
::
BOLD
);
...
...
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