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
19989353
Commit
19989353
authored
Mar 10, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2671 from hqx/2670-ConsoleLocalOptions
2670 console local options
parents
d1a5c854
bf5de411
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
37 additions
and
32 deletions
+37
-32
PhpDocController.php
build/controllers/PhpDocController.php
+2
-2
console.md
docs/guide/console.md
+2
-2
upgrade-from-v1.md
docs/guide/upgrade-from-v1.md
+1
-1
ApiController.php
extensions/apidoc/commands/ApiController.php
+2
-2
GuideController.php
extensions/apidoc/commands/GuideController.php
+2
-2
BaseController.php
extensions/apidoc/components/BaseController.php
+2
-2
FixtureController.php
extensions/faker/FixtureController.php
+2
-2
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
Controller.php
framework/console/Controller.php
+12
-9
FixtureController.php
framework/console/controllers/FixtureController.php
+2
-2
HelpController.php
framework/console/controllers/HelpController.php
+4
-4
MigrateController.php
framework/console/controllers/MigrateController.php
+5
-4
No files found.
build/controllers/PhpDocController.php
View file @
19989353
...
...
@@ -113,9 +113,9 @@ class PhpDocController extends Controller
/**
* @inheritdoc
*/
public
function
globalOptions
(
)
public
function
options
(
$id
)
{
return
array_merge
(
parent
::
globalOptions
(
),
[
'updateFiles'
]);
return
array_merge
(
parent
::
options
(
$id
),
[
'updateFiles'
]);
}
protected
function
updateClassPropertyDocs
(
$file
,
$className
,
$propertyDoc
)
...
...
docs/guide/console.md
View file @
19989353
...
...
@@ -97,8 +97,8 @@ If a route does not contain an action ID, the default action will be executed.
### Options
By overriding the
[
[yii\console\Controller::
globalOptions(
)
]
] method, you can specify options that are available
to a console command. The method should return a list of public property names of the controller class.
By overriding the
[
[yii\console\Controller::
options($id
)
]
] method, you can specify options that are available
to a console command
(controller/actionID)
. The method should return a list of public property names of the controller class.
When running a command, you may specify the value of an option using the syntax
`--OptionName=OptionValue`
.
This will assign
`OptionValue`
to the
`OptionName`
property of the controller class.
...
...
docs/guide/upgrade-from-v1.md
View file @
19989353
...
...
@@ -296,7 +296,7 @@ Each console controller is like `CConsoleCommand` in 1.1. It consists of one or
actions. You use the
`yii <route>`
command to execute a console command, where
`<route>`
stands for a controller route (e.g.
`sitemap/index`
). Additional anonymous arguments
are passed as the parameters to the corresponding controller action method, and named arguments
are treated as
global options declared in
`globalOptions(
)`
.
are treated as
options declared in
`options($id
)`
.
Yii 2.0 supports automatic generation of command help information from comment blocks.
...
...
extensions/apidoc/commands/ApiController.php
View file @
19989353
...
...
@@ -154,8 +154,8 @@ class ApiController extends BaseController
/**
* @inheritdoc
*/
public
function
globalOptions
(
)
public
function
options
(
$id
)
{
return
array_merge
(
parent
::
globalOptions
(
),
[
'template'
,
'guide'
]);
return
array_merge
(
parent
::
options
(
$id
),
[
'template'
,
'guide'
]);
}
}
extensions/apidoc/commands/GuideController.php
View file @
19989353
...
...
@@ -109,8 +109,8 @@ class GuideController extends BaseController
/**
* @inheritdoc
*/
public
function
globalOptions
(
)
public
function
options
(
$id
)
{
return
array_merge
(
parent
::
globalOptions
(
),
[
'apiDocs'
]);
return
array_merge
(
parent
::
options
(
$id
),
[
'apiDocs'
]);
}
}
extensions/apidoc/components/BaseController.php
View file @
19989353
...
...
@@ -121,8 +121,8 @@ abstract class BaseController extends Controller
/**
* @inheritdoc
*/
public
function
globalOptions
(
)
public
function
options
(
$id
)
{
return
array_merge
(
parent
::
globalOptions
(
),
[
'template'
,
'exclude'
]);
return
array_merge
(
parent
::
options
(
$id
),
[
'template'
,
'exclude'
]);
}
}
extensions/faker/FixtureController.php
View file @
19989353
...
...
@@ -174,9 +174,9 @@ class FixtureController extends \yii\console\controllers\FixtureController
* Returns the names of the global options for this command.
* @return array the names of the global options for this command.
*/
public
function
globalOptions
(
)
public
function
options
(
$id
)
{
return
array_merge
(
parent
::
globalOptions
(
),
[
return
array_merge
(
parent
::
options
(
$id
),
[
'templatePath'
,
'language'
,
'fixtureDataPath'
]);
}
...
...
framework/CHANGELOG.md
View file @
19989353
...
...
@@ -137,6 +137,7 @@ Yii Framework 2 Change Log
-
Enh #2526: Allow for null values in batchInsert (skotos)
-
Enh #2646: Added support for specifying hostinfo in the pattern of a URL rule (qiangxue)
-
Enh #2661: Added boolean column type support for SQLite (qiangxue)
-
Enh #2670: Changed
`console\Controller::globalOptions()`
to
`options($actionId)`
to (make it possible to) differentiate options per action (hqx)
-
Enh: Added support for using arrays as option values for console commands (qiangxue)
-
Enh: Added
`favicon.ico`
and
`robots.txt`
to default application templates (samdark)
-
Enh: Added
`Widget::autoIdPrefix`
to support prefixing automatically generated widget IDs (qiangxue)
...
...
framework/console/Controller.php
View file @
19989353
...
...
@@ -67,8 +67,8 @@ class Controller extends \yii\base\Controller
public
function
runAction
(
$id
,
$params
=
[])
{
if
(
!
empty
(
$params
))
{
// populate
global
options here so that they are available in beforeAction().
$options
=
$this
->
globalOptions
(
);
// populate options here so that they are available in beforeAction().
$options
=
$this
->
options
(
$id
);
foreach
(
$params
as
$name
=>
$value
)
{
if
(
in_array
(
$name
,
$options
,
true
))
{
$default
=
$this
->
$name
;
...
...
@@ -85,7 +85,7 @@ class Controller extends \yii\base\Controller
/**
* Binds the parameters to the action.
* This method is invoked by [[Action]] when it begins to run with the given parameters.
* This method will first bind the parameters with the [[
globalOptions()|global
options]]
* This method will first bind the parameters with the [[
options()|
options]]
* available to the action. It then validates the given arguments.
* @param Action $action the action to be bound with parameters
* @param array $params the parameters to be bound to the action
...
...
@@ -251,19 +251,22 @@ class Controller extends \yii\base\Controller
return
Console
::
select
(
$prompt
,
$options
);
}
/**
* Returns the names of
the global options for this command.
* A
global
option requires the existence of a public member variable whose
* Returns the names of
valid options for the action (id)
* A
n
option requires the existence of a public member variable whose
* name is the option name.
* Child classes may override this method to specify possible
global
options.
* Child classes may override this method to specify possible options.
*
* Note that the values setting via
global
options are not available
* Note that the values setting via options are not available
* until [[beforeAction()]] is being called.
*
* @return array the names of the global options for this command.
* @param $id action name
* @return array the names of the options valid for the action
*/
public
function
globalOptions
(
)
public
function
options
(
$id
)
{
// $id might be used in subclass to provide options specific to action id
return
[
'color'
,
'interactive'
];
}
}
framework/console/controllers/FixtureController.php
View file @
19989353
...
...
@@ -61,9 +61,9 @@ class FixtureController extends Controller
* Returns the names of the global options for this command.
* @return array the names of the global options for this command.
*/
public
function
globalOptions
(
)
public
function
options
(
$id
)
{
return
array_merge
(
parent
::
globalOptions
(
),
[
return
array_merge
(
parent
::
options
(
$id
),
[
'namespace'
,
'globalFixtures'
]);
}
...
...
framework/console/controllers/HelpController.php
View file @
19989353
...
...
@@ -287,7 +287,7 @@ class HelpController extends Controller
}
$tags
=
$this
->
parseComment
(
$method
->
getDocComment
());
$options
=
$this
->
getOptionHelps
(
$controller
);
$options
=
$this
->
getOptionHelps
(
$controller
,
$actionID
);
if
(
$tags
[
'description'
]
!==
''
)
{
$this
->
stdout
(
"
\n
DESCRIPTION
\n
"
,
Console
::
BOLD
);
...
...
@@ -317,7 +317,6 @@ class HelpController extends Controller
echo
implode
(
"
\n\n
"
,
array_merge
(
$required
,
$optional
))
.
"
\n\n
"
;
}
$options
=
$this
->
getOptionHelps
(
$controller
);
if
(
!
empty
(
$options
))
{
$this
->
stdout
(
"
\n
OPTIONS
\n\n
"
,
Console
::
BOLD
);
echo
implode
(
"
\n\n
"
,
$options
)
.
"
\n\n
"
;
...
...
@@ -360,11 +359,12 @@ class HelpController extends Controller
/**
* Returns the help information about the options available for a console controller.
* @param Controller $controller the console controller
* @param string $actionID name of the action, if set include local options for that action
* @return array the help information about the options
*/
protected
function
getOptionHelps
(
$controller
)
protected
function
getOptionHelps
(
$controller
,
$actionID
)
{
$optionNames
=
$controller
->
globalOptions
(
);
$optionNames
=
$controller
->
options
(
$actionID
);
if
(
empty
(
$optionNames
))
{
return
[];
}
...
...
framework/console/controllers/MigrateController.php
View file @
19989353
...
...
@@ -95,11 +95,12 @@ class MigrateController extends Controller
* Returns the names of the global options for this command.
* @return array the names of the global options for this command.
*/
public
function
globalOptions
(
)
public
function
options
(
$id
)
{
return
array_merge
(
parent
::
globalOptions
(),
[
'migrationPath'
,
'migrationTable'
,
'db'
,
'templateFile'
,
'interactive'
,
'color'
]);
return
array_merge
(
parent
::
options
(
$id
),
[
'migrationPath'
,
'migrationTable'
,
'db'
],
// global for all actions
(
$id
==
'create'
)
?
[
'templateFile'
]
:
[]
// action create
);
}
/**
...
...
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