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
706ab7f9
Commit
706ab7f9
authored
Mar 09, 2014
by
Christian Nadolle
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
combine globalOptions() with local options into options($id)
adjust existing Console Controllers and docs
parent
b0d7559a
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
33 additions
and
58 deletions
+33
-58
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
+3
-2
GuideController.php
extensions/apidoc/commands/GuideController.php
+3
-2
BaseController.php
extensions/apidoc/components/BaseController.php
+2
-2
FixtureController.php
extensions/faker/FixtureController.php
+2
-2
Controller.php
framework/console/Controller.php
+11
-35
FixtureController.php
framework/console/controllers/FixtureController.php
+2
-2
HelpController.php
framework/console/controllers/HelpController.php
+3
-6
MigrateController.php
framework/console/controllers/MigrateController.php
+2
-2
No files found.
build/controllers/PhpDocController.php
View file @
706ab7f9
...
...
@@ -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 @
706ab7f9
...
...
@@ -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 @
706ab7f9
...
...
@@ -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 @
706ab7f9
...
...
@@ -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'
]);
}
}
\ No newline at end of file
extensions/apidoc/commands/GuideController.php
View file @
706ab7f9
...
...
@@ -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'
]);
}
}
\ No newline at end of file
extensions/apidoc/components/BaseController.php
View file @
706ab7f9
...
...
@@ -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 @
706ab7f9
...
...
@@ -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/console/Controller.php
View file @
706ab7f9
...
...
@@ -67,18 +67,8 @@ class Controller extends \yii\base\Controller
public
function
runAction
(
$id
,
$params
=
[])
{
if
(
!
empty
(
$params
))
{
// extract valid local options first so that they don't throw "unknown option"- exception below.
$options
=
$this
->
localOptions
(
$id
);
foreach
(
$params
as
$name
=>
$value
)
{
if
(
in_array
(
$name
,
$options
,
true
))
{
$default
=
$this
->
$name
;
$this
->
$name
=
is_array
(
$default
)
?
preg_split
(
'/\s*,\s*/'
,
$value
)
:
$value
;
unset
(
$params
[
$name
]);
}
}
// 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
;
...
...
@@ -95,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
...
...
@@ -261,36 +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
* name is the option name.
* Child classes may override this method to specify possible global options.
*
* Note that the values setting via global options are not available
* until [[beforeAction()]] is being called.
*
* @return array the names of the global options for this command.
*/
public
function
globalOptions
()
{
return
[
'color'
,
'interactive'
];
}
/**
* Returns the names of valid options
local to
the action (id)
* A
local
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
local
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.
*
* @param $id action name
* @return array the names of the options valid for th
is action (in addition to global options above)
* @return array the names of the options valid for th
e action
*/
public
function
localO
ptions
(
$id
)
public
function
o
ptions
(
$id
)
{
return
[];
// $id might be used in subclass to provide options specific to action id
return
[
'color'
,
'interactive'
];
}
}
framework/console/controllers/FixtureController.php
View file @
706ab7f9
...
...
@@ -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 @
706ab7f9
...
...
@@ -359,15 +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|null
$actionID name of the action, if set include local options for that action
* @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
,
$actionID
=
null
)
protected
function
getOptionHelps
(
$controller
,
$actionID
)
{
$optionNames
=
$controller
->
globalOptions
();
if
(
!
empty
(
$actionID
))
{
$optionNames
=
array_merge
(
$optionNames
,
$controller
->
localOptions
(
$actionID
));
}
$optionNames
=
$controller
->
options
(
$actionID
);
if
(
empty
(
$optionNames
))
{
return
[];
}
...
...
framework/console/controllers/MigrateController.php
View file @
706ab7f9
...
...
@@ -95,9 +95,9 @@ 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
(
),
[
return
array_merge
(
parent
::
options
(
$id
),
[
'migrationPath'
,
'migrationTable'
,
'db'
,
'templateFile'
,
'interactive'
,
'color'
]);
}
...
...
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