Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Y
yii2-giiant
Project
Project
Details
Activity
Releases
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
dmstr
yii2-giiant
Commits
182a44f0
Commit
182a44f0
authored
Nov 28, 2016
by
Tobias Munk
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added fixOutput parameter to run php-cs-fixer on generated files
parent
047c7393
Pipeline
#16246
passed with stages
in 5 minutes and 11 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
7 deletions
+30
-7
BatchController.php
src/commands/BatchController.php
+7
-0
Generator.php
src/generators/crud/Generator.php
+22
-7
12_GiiantBatchCrudOnlyCept.php
tests/cli/onlycrud/12_GiiantBatchCrudOnlyCept.php
+1
-0
No files found.
src/commands/BatchController.php
View file @
182a44f0
...
...
@@ -179,6 +179,11 @@ class BatchController extends Controller
*/
public
$crudTidyOutput
=
true
;
/**
* @var bool whether to fix generated code (PSR-2)
*/
public
$crudFixOutput
=
true
;
/**
* @var string the namespace of the ActiveQuery class to be generated
*/
...
...
@@ -240,6 +245,7 @@ class BatchController extends Controller
'modelGenerateLabelsFromComments'
,
'modelGenerateHintsFromComments'
,
'crudTidyOutput'
,
'crudFixOutput'
,
'crudControllerNamespace'
,
'crudSearchModelNamespace'
,
'crudSearchModelSuffix'
,
...
...
@@ -383,6 +389,7 @@ class BatchController extends Controller
'accessFilter'
=>
$this
->
crudAccessFilter
,
'baseTraits'
=>
$this
->
crudBaseTraits
,
'tidyOutput'
=>
$this
->
crudTidyOutput
,
'fixOutput'
=>
$this
->
crudFixOutput
,
'template'
=>
$this
->
crudTemplate
,
'indexWidgetType'
=>
$this
->
crudIndexWidgetType
,
'indexGridClass'
=>
$this
->
crudIndexGridClass
,
...
...
src/generators/crud/Generator.php
View file @
182a44f0
...
...
@@ -123,6 +123,11 @@ class Generator extends \yii\gii\generators\crud\Generator
*/
public
$tidyOutput
=
true
;
/**
* @var bool whether to use php-cs-fixer to generate PSR compatible output
*/
public
$fixOutput
=
false
;
/**
* @var string form field for selecting and loading saved gii forms
*/
...
...
@@ -388,18 +393,28 @@ class Generator extends \yii\gii\generators\crud\Generator
public
function
render
(
$template
,
$params
=
[])
{
$code
=
parent
::
render
(
$template
,
$params
);
// create temp file for code formatting
$tmpDir
=
Yii
::
getAlias
(
'@runtime/giiant'
);
FileHelper
::
createDirectory
(
$tmpDir
);
$tmpFile
=
$tmpDir
.
'/'
.
md5
(
$template
);
file_put_contents
(
$tmpFile
,
$code
);
if
(
$this
->
tidyOutput
)
{
$tmpDir
=
Yii
::
getAlias
(
'@runtime/giiant'
);
FileHelper
::
createDirectory
(
$tmpDir
);
$tmpFile
=
$tmpDir
.
'/'
.
md5
(
$template
);
file_put_contents
(
$tmpFile
,
$code
);
$command
=
Yii
::
getAlias
(
'@vendor/bin/phptidy'
)
.
' replace '
.
$tmpFile
;
shell_exec
(
$command
);
$code
=
file_get_contents
(
$tmpFile
);
}
return
file_get_contents
(
$tmpFile
);
}
else
{
return
$code
;
if
(
$this
->
fixOutput
)
{
$command
=
Yii
::
getAlias
(
'@vendor/bin/php-cs-fixer'
)
.
' fix '
.
$tmpFile
;
shell_exec
(
$command
);
$code
=
file_get_contents
(
$tmpFile
);
}
unlink
(
$tmpFile
);
return
$code
;
}
public
function
validateClass
(
$attribute
,
$params
)
...
...
tests/cli/onlycrud/12_GiiantBatchCrudOnlyCept.php
View file @
182a44f0
...
...
@@ -22,6 +22,7 @@ $batch = <<<CMD
--crudPathPrefix={$name}/ \
--crudSkipRelations=Variant,Variants \
--crudProviders=schmunk42\\\\giiant\\\\generators\\\\crud\\\\providers\\\\extensions\\\\EditorProvider \
--crudFixOutput=1 \
--tables=country
CMD;
...
...
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