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
dd6f4442
Commit
dd6f4442
authored
Sep 05, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gii command line WIP
parent
ef1a6d20
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
131 additions
and
0 deletions
+131
-0
Action.php
extensions/gii/console/Action.php
+50
-0
GenerateController.php
extensions/gii/console/GenerateController.php
+81
-0
No files found.
extensions/gii/console/Action.php
0 → 100644
View file @
dd6f4442
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\gii\console
;
/**
* @author Qiang Xue <qiang.xue@gmail.com>
* @since 2.0
*/
class
Action
extends
\yii\base\Action
{
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
"
;
if
(
$this
->
generator
->
validate
())
{
$files
=
$this
->
generator
->
generate
();
$answers
=
[];
foreach
(
$files
AS
$file
)
{
$answers
[
$file
->
id
]
=
true
;
}
$params
[
'hasError'
]
=
$this
->
generator
->
save
(
$files
,
(
array
)
$answers
,
$results
);
$params
[
'results'
]
=
$results
;
echo
$params
[
'hasError'
];
echo
"
\n
"
;
echo
$results
;
}
else
{
echo
"Attribute Errors
\n
"
;
echo
"----------------
\n
"
;
foreach
(
$this
->
generator
->
errors
AS
$attribute
=>
$errors
)
{
echo
"
$attribute
: "
.
implode
(
'; '
,
$errors
)
.
"
\n
"
;
}
echo
"
\n
"
;
}
}
}
extensions/gii/console/GenerateController.php
0 → 100644
View file @
dd6f4442
<?php
/**
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
namespace
yii\gii\commands
;
use
Yii
;
use
yii\console\Controller
;
/**
* Allows you to run Gii from the command line.
* Example command:
*
* ```
* $ ./yii gii/<generator> --property1=foo --property2=bar --generate=true
* ```
*
* @author Tobias Munk <schmunk@usrbin.de>
* @since 2.0
*/
class
GenerateController
extends
Controller
{
/**
* @var \yii\gii\Module
*/
public
$module
;
/**
* @var boolean whether to generate all files and overwrite existing files
*/
public
$generate
=
false
;
/**
* @var array stores generator attributes
*/
private
$_attributes
=
[];
public
function
__set
(
$key
,
$value
)
{
// todo: check if $key is a valid option
$this
->
_attributes
[
$key
]
=
$value
;
}
public
function
__get
(
$key
)
{
// todo: check if $key is a valid option
if
(
isset
(
$this
->
_attributes
[
$key
]))
{
return
$this
->
_attributes
[
$key
];
}
}
/**
* @inheritdoc
*/
public
function
actions
()
{
$actions
=
[];
foreach
(
$this
->
module
->
generators
as
$name
=>
$generator
)
{
// create a generate action for every generator
$actions
[
$name
]
=
[
'class'
=>
'yii\gii\console\Action'
,
'generator'
=>
$generator
,
];
}
return
$actions
;
}
/**
* @inheritdoc
*/
public
function
options
(
$id
)
{
$generator
=
$this
->
module
->
generators
[
$id
];
return
array_merge
(
parent
::
options
(
$id
),
array_keys
(
$generator
->
attributes
)
// global for all actions
);
}
}
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