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
11a4d6de
Commit
11a4d6de
authored
Sep 07, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
console gii WIP
parent
dd6f4442
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
138 additions
and
32 deletions
+138
-32
Generator.php
extensions/gii/Generator.php
+1
-1
Module.php
extensions/gii/Module.php
+17
-7
Action.php
extensions/gii/console/Action.php
+4
-7
GenerateController.php
extensions/gii/console/GenerateController.php
+116
-17
No files found.
extensions/gii/Generator.php
View file @
11a4d6de
...
...
@@ -47,7 +47,7 @@ abstract class Generator extends Model
* @var string the name of the code template that the user has selected.
* The value of this property is internally managed by this class.
*/
public
$template
;
public
$template
=
'default'
;
/**
* @var boolean whether the strings will be generated using `Yii::t()` or normal strings.
*/
...
...
extensions/gii/Module.php
View file @
11a4d6de
...
...
@@ -84,11 +84,19 @@ class Module extends \yii\base\Module implements BootstrapInterface
*/
public
function
bootstrap
(
$app
)
{
$app
->
getUrlManager
()
->
addRules
([
$this
->
id
=>
$this
->
id
.
'/default/index'
,
$this
->
id
.
'/<id:\w+>'
=>
$this
->
id
.
'/default/view'
,
$this
->
id
.
'/<controller:\w+>/<action:\w+>'
=>
$this
->
id
.
'/<controller>/<action>'
,
],
false
);
if
(
$app
instanceof
\yii\web\Application
)
{
$app
->
getUrlManager
()
->
addRules
([
$this
->
id
=>
$this
->
id
.
'/default/index'
,
$this
->
id
.
'/<id:\w+>'
=>
$this
->
id
.
'/default/view'
,
$this
->
id
.
'/<controller:\w+>/<action:\w+>'
=>
$this
->
id
.
'/<controller>/<action>'
,
],
false
);
}
elseif
(
$app
instanceof
\yii\console\Application
)
{
$app
->
controllerMap
[
$this
->
id
]
=
[
'class'
=>
'yii\gii\console\GenerateController'
,
'generators'
=>
array_merge
(
$this
->
coreGenerators
(),
$this
->
generators
),
'module'
=>
$this
,
];
}
}
/**
...
...
@@ -100,7 +108,7 @@ class Module extends \yii\base\Module implements BootstrapInterface
return
false
;
}
if
(
!
$this
->
checkAccess
())
{
if
(
Yii
::
$app
instanceof
\yii\web\Application
&&
!
$this
->
checkAccess
())
{
throw
new
ForbiddenHttpException
(
'You are not allowed to access this page.'
);
}
...
...
@@ -118,7 +126,9 @@ class Module extends \yii\base\Module implements BootstrapInterface
*/
protected
function
resetGlobalSettings
()
{
Yii
::
$app
->
assetManager
->
bundles
=
[];
if
(
Yii
::
$app
instanceof
\yii\web\Application
)
{
Yii
::
$app
->
assetManager
->
bundles
=
[];
}
}
/**
...
...
extensions/gii/console/Action.php
View file @
11a4d6de
...
...
@@ -13,20 +13,17 @@ namespace yii\gii\console;
*/
class
Action
extends
\yii\base\Action
{
/**
* @var \yii\gii\Generator
*/
public
$generator
;
// TODO: is there are better way, needed for `./yii help gii`
public
function
getUniqueId
()
{
return
'gii/'
.
$this
->
generatorName
;
}
/**
* @inheritdoc
*/
public
function
run
()
{
echo
"Loading generator '
$this->
generatorName
'...
\n\n
"
;
echo
"Loading generator '
$this->
id
'...
\n\n
"
;
if
(
$this
->
generator
->
validate
())
{
$files
=
$this
->
generator
->
generate
();
$answers
=
[];
...
...
extensions/gii/console/GenerateController.php
View file @
11a4d6de
...
...
@@ -5,7 +5,7 @@
* @license http://www.yiiframework.com/license/
*/
namespace
yii\gii\co
mmands
;
namespace
yii\gii\co
nsole
;
use
Yii
;
use
yii\console\Controller
;
...
...
@@ -31,34 +31,78 @@ class GenerateController extends Controller
* @var boolean whether to generate all files and overwrite existing files
*/
public
$generate
=
false
;
public
$generators
=
[];
/**
* @var array
stores generator attribut
es
* @var array
generator option valu
es
*/
private
$_
attribute
s
=
[];
private
$_
option
s
=
[];
public
function
__set
(
$key
,
$value
)
/**
* @inheritdoc
*/
public
function
__get
(
$name
)
{
// todo: check if $key is a valid option
$this
->
_attributes
[
$key
]
=
$value
;
return
isset
(
$this
->
_options
[
$name
])
?
$this
->
_options
[
$name
]
:
null
;
if
(
$this
->
action
)
{
$options
=
$this
->
options
(
$this
->
action
->
id
);
if
(
in_array
(
$name
,
$options
))
{
return
isset
(
$this
->
_options
[
$name
])
?
$this
->
_options
[
$name
]
:
null
;
}
else
{
return
parent
::
__get
(
$name
);
}
}
elseif
(
array_key_exists
(
$name
,
$this
->
_options
))
{
return
$this
->
_options
[
$name
];
}
else
{
return
parent
::
__get
(
$name
);
}
}
/**
* @inheritdoc
*/
public
function
__set
(
$name
,
$value
)
{
$this
->
_options
[
$name
]
=
$value
;
return
;
if
(
$this
->
action
)
{
$options
=
$this
->
options
(
$this
->
action
->
id
);
if
(
in_array
(
$name
,
$options
))
{
$this
->
_options
[
$name
]
=
$value
;
}
else
{
parent
::
__set
(
$name
,
$value
);
}
}
else
{
$this
->
_options
[
$name
]
=
$value
;
}
}
public
function
__get
(
$key
)
public
function
init
(
)
{
// todo: check if $key is a valid option
if
(
isset
(
$this
->
_attributes
[
$key
])
)
{
return
$this
->
_attributes
[
$key
]
;
parent
::
init
();
foreach
(
$this
->
generators
as
$id
=>
$config
)
{
$this
->
generators
[
$id
]
=
Yii
::
createObject
(
$config
)
;
}
}
public
function
createAction
(
$id
)
{
$action
=
parent
::
createAction
(
$id
);
foreach
(
$this
->
_options
as
$name
=>
$value
)
{
$action
->
generator
->
$name
=
$value
;
}
return
$action
;
}
/**
* @inheritdoc
*/
public
function
actions
()
{
$actions
=
[];
foreach
(
$this
->
module
->
generators
as
$name
=>
$generator
)
{
// create a generate action for every generator
foreach
(
$this
->
generators
as
$name
=>
$generator
)
{
$actions
[
$name
]
=
[
'class'
=>
'yii\gii\console\Action'
,
'generator'
=>
$generator
,
...
...
@@ -67,15 +111,70 @@ class GenerateController extends Controller
return
$actions
;
}
public
function
getUniqueID
()
{
return
$this
->
id
;
}
/**
* @inheritdoc
*/
public
function
options
(
$id
)
{
$generator
=
$this
->
module
->
generators
[
$id
];
return
array_merge
(
parent
::
options
(
$id
),
array_keys
(
$generator
->
attributes
)
// global for all actions
);
if
(
isset
(
$this
->
generators
[
$id
]))
{
return
array_merge
(
parent
::
options
(
$id
),
array_keys
(
$this
->
generators
[
$id
]
->
attributes
)
);
}
else
{
return
parent
::
options
(
$id
);
}
}
/**
* @inheritdoc
*/
public
function
getActionHelpSummary
(
$action
)
{
/** @var $action Action */
return
$action
->
generator
->
getName
();
}
/**
* @inheritdoc
*/
public
function
getActionHelp
(
$action
)
{
/** @var $action Action */
return
$action
->
generator
->
getDescription
();
}
/**
* @inheritdoc
*/
public
function
getActionArgsHelp
(
$action
)
{
return
[];
}
/**
* @inheritdoc
*/
public
function
getActionOptionsHelp
(
$action
)
{
/** @var $action Action */
$attributes
=
$action
->
generator
->
attributes
;
$hints
=
$action
->
generator
->
hints
();
$options
=
[];
foreach
(
$attributes
as
$name
=>
$value
)
{
$options
[
$name
]
=
[
'type'
=>
'string'
,
'default'
=>
$value
,
'comment'
=>
isset
(
$hints
[
$name
])
?
$hints
[
$name
]
:
''
,
];
}
return
$options
;
}
}
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