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
4ab2e986
Commit
4ab2e986
authored
Sep 28, 2013
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Advanced application: init script can now be executed in non-interactive input mode
Usage: init --env=Development init --env=Production
parent
907d24fb
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
57 additions
and
14 deletions
+57
-14
README.md
apps/advanced/README.md
+2
-1
init
apps/advanced/init
+55
-13
No files found.
apps/advanced/README.md
View file @
4ab2e986
...
...
@@ -103,7 +103,8 @@ GETTING STARTED
After you install the application, you have to conduct the following steps to initialize
the installed application. You only need to do these once for all.
1.
Execute the
`init`
command and select
`dev`
as environment.
1.
Execute the
`init`
command and select
`dev`
as environment. Alternatively you can execute it as
`init --env=Development`
or
`init --env=Production`
.
2.
Create a new database. It is assumed that MySQL InnoDB is used. If not, adjust
`console/migrations/m130524_201442_init.php`
.
3.
In
`common/config/params.php`
set your database details in
`components.db`
values.
...
...
apps/advanced/init
View file @
4ab2e986
#!/usr/bin/env php
<?php
$params
=
getParams
();
$root
=
str_replace
(
'\\'
,
'/'
,
__DIR__
);
$envs
=
require
(
"
$root
/environments/index.php"
);
$envNames
=
array_keys
(
$envs
);
echo
"Yii Application Init Tool v1.0
\n\n
"
;
echo
"Which environment do you want the application to be initialized in?
\n\n
"
;
foreach
(
$envNames
as
$i
=>
$name
)
{
echo
"Yii Application Initialization Tool v1.0
\n\n
"
;
$envName
=
null
;
if
(
empty
(
$params
[
'env'
]))
{
echo
"Which environment do you want the application to be initialized in?
\n\n
"
;
foreach
(
$envNames
as
$i
=>
$name
)
{
echo
" [
$i
]
$name
\n
"
;
}
echo
"
\n
Your choice [0-"
.
(
count
(
$envs
)
-
1
)
.
', or "q" to quit] '
;
$answer
=
trim
(
fgets
(
STDIN
));
if
(
!
ctype_digit
(
$answer
)
||
!
isset
(
$envNames
[
$answer
]))
{
}
echo
"
\n
Your choice [0-"
.
(
count
(
$envs
)
-
1
)
.
', or "q" to quit] '
;
$answer
=
trim
(
fgets
(
STDIN
));
if
(
!
ctype_digit
(
$answer
)
||
!
in_array
(
$answer
,
range
(
0
,
count
(
$envs
)
-
1
)))
{
echo
"
\n
Quit initialization.
\n
"
;
return
;
exit
(
1
);
}
if
(
isset
(
$envNames
[
$answer
]))
{
$envName
=
$envNames
[
$answer
];
}
}
else
{
$envName
=
$params
[
'env'
];
}
if
(
!
in_array
(
$envName
,
$envNames
))
{
$envsList
=
implode
(
', '
,
$envNames
);
echo
"
\n
$envName
is not a valid environment. Try one of the following:
$envsList
.
\n
"
;
exit
(
2
);
}
$env
=
$envs
[
$envNames
[
$answer
]];
echo
"
\n
Initialize the application under '
{
$envNames
[
$answer
]
}
' environment? [yes|no] "
;
$answer
=
trim
(
fgets
(
STDIN
));
if
(
strncasecmp
(
$answer
,
'y'
,
1
))
{
$env
=
$envs
[
$envName
];
if
(
empty
(
$params
[
'env'
]))
{
echo
"
\n
Initialize the application under '
{
$envNames
[
$answer
]
}
' environment? [yes|no] "
;
$answer
=
trim
(
fgets
(
STDIN
));
if
(
strncasecmp
(
$answer
,
'y'
,
1
))
{
echo
"
\n
Quit initialization.
\n
"
;
return
;
exit
(
1
);
}
}
echo
"
\n
Start initialization ...
\n\n
"
;
...
...
@@ -110,3 +132,23 @@ function copyFile($root, $source, $target, &$all)
file_put_contents
(
$root
.
'/'
.
$target
,
file_get_contents
(
$root
.
'/'
.
$source
));
return
true
;
}
function
getParams
()
{
$rawParams
=
array
();
if
(
isset
(
$_SERVER
[
'argv'
]))
{
$rawParams
=
$_SERVER
[
'argv'
];
array_shift
(
$rawParams
);
}
$params
=
array
();
foreach
(
$rawParams
as
$param
)
{
if
(
preg_match
(
'/^--(\w+)(=(.*))?$/'
,
$param
,
$matches
))
{
$name
=
$matches
[
1
];
$params
[
$name
]
=
isset
(
$matches
[
3
])
?
$matches
[
3
]
:
true
;
}
else
{
$params
[]
=
$param
;
}
}
return
$params
;
}
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