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
c43b7ee8
Commit
c43b7ee8
authored
Aug 12, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
console help WIP
parent
5c79ab20
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
150 additions
and
52 deletions
+150
-52
Action.php
framework/console/Action.php
+45
-0
Application.php
framework/console/Application.php
+1
-1
Controller.php
framework/console/Controller.php
+44
-6
InlineAction.php
framework/console/InlineAction.php
+45
-0
HelpController.php
framework/console/controllers/HelpController.php
+15
-45
No files found.
framework/console/Action.php
0 → 100644
View file @
c43b7ee8
<?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
*
* @author Carsten Brandt <mail@cebe.cc>
* @since 2.0
*/
class
Action
extends
\yii\base\Action
{
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
''
;
}
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
''
;
}
}
framework/console/Application.php
View file @
c43b7ee8
...
...
@@ -87,7 +87,7 @@ class Application extends \yii\base\Application
* @param array $config the configuration provided in the constructor.
* @return array the actual configuration to be used by the application.
*/
protected
function
loadConfig
(
$config
)
protected
function
loadConfig
(
$config
)
// TODO should be available in HELP
{
if
(
!
empty
(
$_SERVER
[
'argv'
]))
{
$option
=
'--'
.
self
::
OPTION_APPCONFIG
.
'='
;
...
...
framework/console/Controller.php
View file @
c43b7ee8
...
...
@@ -16,7 +16,7 @@ use yii\helpers\Console;
/**
* Controller is the base class of console command classes.
*
* A controller consists of one or several actions known as sub-commands.
* A con
sole con
troller consists of one or several actions known as sub-commands.
* Users call a console command by specifying the corresponding route which identifies a controller action.
* The `yii` program is used when calling a console command, like the following:
*
...
...
@@ -24,6 +24,9 @@ use yii\helpers\Console;
* yii <route> [--param1=value1 --param2 ...]
* ~~~
*
* where `<route>` is a route to a controller action and the params will be populated as properties of a command.
* See [[options()]] for details.
*
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
...
...
@@ -82,7 +85,6 @@ class Controller extends \yii\base\Controller
}
}
}
return
parent
::
runAction
(
$id
,
$params
);
}
...
...
@@ -148,7 +150,6 @@ class Controller extends \yii\base\Controller
array_shift
(
$args
);
$string
=
Console
::
ansiFormat
(
$string
,
$args
);
}
return
$string
;
}
...
...
@@ -174,7 +175,6 @@ class Controller extends \yii\base\Controller
array_shift
(
$args
);
$string
=
Console
::
ansiFormat
(
$string
,
$args
);
}
return
Console
::
stdout
(
$string
);
}
...
...
@@ -200,7 +200,6 @@ class Controller extends \yii\base\Controller
array_shift
(
$args
);
$string
=
Console
::
ansiFormat
(
$string
,
$args
);
}
return
fwrite
(
\STDERR
,
$string
);
}
...
...
@@ -272,7 +271,46 @@ class Controller extends \yii\base\Controller
*/
public
function
options
(
$actionId
)
{
// $
id might be used in subclas
s to provide options specific to action id
// $
actionId might be used in subclasse
s to provide options specific to action id
return
[
'color'
,
'interactive'
];
}
/**
* Returns a short description (one line) of information about this controller or an action.
*
* You may override this method to return customized help information for this controller.
* The default implementation returns help information retrieved from the PHPDoc comments
* of the controller class.
*
* @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
''
;
}
/**
* Returns help information for this controller.
*
* The default implementation returns help information retrieved from the PHPDoc comments
* of the controller class.
* @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
''
;
}
}
framework/console/InlineAction.php
0 → 100644
View file @
c43b7ee8
<?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
;
/**
* InlineAction represents an action that is defined as a controller method.
*
* @inheritdoc
*
* @author Carsten Brandt <mail@cebe.cc>
* @since 2.0
*/
class
InlineAction
extends
\yii\base\InlineAction
{
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
''
;
}
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
''
;
}
}
framework/console/controllers/HelpController.php
View file @
c43b7ee8
...
...
@@ -9,9 +9,10 @@ namespace yii\console\controllers;
use
Yii
;
use
yii\base\Application
;
use
yii\
base\Inline
Action
;
use
yii\
console\
Action
;
use
yii\console\Controller
;
use
yii\console\Exception
;
use
yii\console\InlineAction
;
use
yii\helpers\Console
;
use
yii\helpers\Inflector
;
...
...
@@ -66,7 +67,7 @@ class HelpController extends Controller
$this
->
getControllerHelp
(
$controller
);
}
}
else
{
$this
->
getHelp
();
$this
->
get
Global
Help
();
}
}
...
...
@@ -78,7 +79,6 @@ class HelpController extends Controller
{
$commands
=
$this
->
getModuleCommands
(
Yii
::
$app
);
sort
(
$commands
);
return
array_unique
(
$commands
);
}
...
...
@@ -95,12 +95,7 @@ class HelpController extends Controller
$result
=
Yii
::
$app
->
createController
(
$command
);
if
(
$result
!==
false
)
{
list
(
$controller
,
$actionID
)
=
$result
;
$class
=
new
\ReflectionClass
(
$controller
);
$docLines
=
preg_split
(
'~(\n|\r|\r\n)~'
,
$class
->
getDocComment
());
if
(
isset
(
$docLines
[
1
]))
{
$description
=
trim
(
$docLines
[
1
],
' *'
);
}
$description
=
$controller
->
getDescription
();
}
$descriptions
[
$command
]
=
$description
;
...
...
@@ -186,7 +181,7 @@ class HelpController extends Controller
/**
* Displays all available commands.
*/
protected
function
getHelp
()
protected
function
get
Global
Help
()
{
$commands
=
$this
->
getCommandDescriptions
();
if
(
!
empty
(
$commands
))
{
...
...
@@ -217,15 +212,12 @@ class HelpController extends Controller
*/
protected
function
getControllerHelp
(
$controller
)
{
$class
=
new
\ReflectionClass
(
$controller
);
$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
]));
}
// TODO set color option of controller to this controllers color option
$this
->
stdout
(
"
\n
DESCRIPTION
\n
"
,
Console
::
BOLD
);
$comment
=
$controller
->
getHelp
();
if
(
$comment
!==
''
)
{
$this
->
stdout
(
"
\n
DESCRIPTION
\n
"
,
Console
::
BOLD
);
echo
"
\n
"
.
rtrim
(
Console
::
renderColoredString
(
Console
::
markdownToAnsi
(
$comment
)))
.
"
\n\n
"
;
$this
->
stdout
(
"
\n
$comment
\n\n
"
);
}
$actions
=
$this
->
getActions
(
$controller
);
...
...
@@ -259,33 +251,10 @@ class HelpController extends Controller
protected
function
getActionSummary
(
$controller
,
$actionID
)
{
$action
=
$controller
->
createAction
(
$actionID
);
if
(
$action
===
null
)
{
return
''
;
}
if
(
$action
instanceof
InlineAction
)
{
$reflection
=
new
\ReflectionMethod
(
$controller
,
$action
->
actionMethod
);
}
else
{
$reflection
=
new
\ReflectionClass
(
$action
);
}
$tags
=
$this
->
parseComment
(
$reflection
->
getDocComment
());
if
(
$tags
[
'description'
]
!==
''
)
{
$limit
=
73
-
strlen
(
$action
->
getUniqueId
());
if
(
$actionID
===
$controller
->
defaultAction
)
{
$limit
-=
10
;
}
if
(
$limit
<
0
)
{
$limit
=
50
;
}
$description
=
$tags
[
'description'
];
if
((
$pos
=
strpos
(
$tags
[
'description'
],
"
\n
"
))
!==
false
)
{
$description
=
substr
(
$description
,
0
,
$pos
);
}
$text
=
substr
(
$description
,
0
,
$limit
);
return
strlen
(
$description
)
>
$limit
?
$text
.
'...'
:
$text
;
}
else
{
return
''
;
if
(
$action
instanceof
InlineAction
||
$action
instanceof
Action
)
{
return
$action
->
getDescription
();
}
return
''
;
}
/**
...
...
@@ -311,9 +280,10 @@ class HelpController extends Controller
$tags
=
$this
->
parseComment
(
$method
->
getDocComment
());
$options
=
$this
->
getOptionHelps
(
$controller
,
$actionID
);
if
(
$tags
[
'description'
]
!==
''
)
{
$description
=
$action
->
getHelp
();
if
(
$description
!==
''
)
{
$this
->
stdout
(
"
\n
DESCRIPTION
\n
"
,
Console
::
BOLD
);
echo
"
\n
"
.
rtrim
(
Console
::
renderColoredString
(
Console
::
markdownToAnsi
(
$tags
[
'description'
])))
.
"
\n\n
"
;
$this
->
stdout
(
"
\n
$description
\n\n
"
)
;
}
$this
->
stdout
(
"
\n
USAGE
\n\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