Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenDocCN
yii2_fecshop
提交
984f68da
Y
yii2_fecshop
项目概览
OpenDocCN
/
yii2_fecshop
通知
17
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
Y
yii2_fecshop
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
984f68da
编写于
12月 07, 2018
作者:
T
Terry
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
delete initFecShop
上级
ad8d1b99
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
0 addition
and
223 deletion
+0
-223
initFecShop
initFecShop
+0
-223
未找到文件。
initFecShop
已删除
100755 → 0
浏览文件 @
ad8d1b99
#!/usr/bin/env php
<?php
/**
* Yii Application Initialization Tool
*
* In order to run in non-interactive mode:
*
* init --env=Development --overwrite=n
*
* @author Alexander Makarov <sam@rmcreative.ru>
*
* @link http://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
if
(
!
extension_loaded
(
'openssl'
))
{
die
(
'The OpenSSL PHP extension is required by Yii2.'
);
}
$params
=
getParams
();
$root
=
str_replace
(
'\\'
,
'/'
,
__DIR__
);
$root
=
"
$root
/../../.."
;
$envs
=
require
(
"
$root
/vendor/fancyecommerce/fecshop/environments/index.php"
);
$envNames
=
array_keys
(
$envs
);
echo
"Yii Application Initialization Tool v1.0
\n\n
"
;
$envName
=
null
;
if
(
empty
(
$params
[
'env'
])
||
$params
[
'env'
]
===
'1'
)
{
/*
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) || !in_array($answer, range(0, count($envs) - 1))) {
echo "\n Quit initialization.\n";
exit(0);
}
if (isset($envNames[$answer])) {
$envName = $envNames[$answer];
}
*/
$envName
=
'prod'
;
}
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
[
$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
"
;
exit
(
0
);
}
}
echo
"
\n
Start initialization ...
\n\n
"
;
$files
=
getFileList
(
"
$root
/vendor/fancyecommerce/fecshop/environments/
{
$env
[
'path'
]
}
"
);
var_dump
(
$files
);
exit
;
if
(
isset
(
$env
[
'skipFiles'
]))
{
$skipFiles
=
$env
[
'skipFiles'
];
array_walk
(
$skipFiles
,
function
(
&
$value
)
use
(
$env
,
$root
)
{
$value
=
"
$root
/
$value
"
;
});
$files
=
array_diff
(
$files
,
array_intersect_key
(
$env
[
'skipFiles'
],
array_filter
(
$skipFiles
,
'file_exists'
)));
}
$all
=
false
;
foreach
(
$files
as
$file
)
{
if
(
!
copyFile
(
$root
,
"vendor/fancyecommerce/fecshop/environments/
{
$env
[
'path'
]
}
/
$file
"
,
$file
,
$all
,
$params
))
{
break
;
}
}
$callbacks
=
[
'setCookieValidationKey'
,
'setWritable'
,
'setExecutable'
,
'createSymlink'
];
foreach
(
$callbacks
as
$callback
)
{
if
(
!
empty
(
$env
[
$callback
]))
{
$callback
(
$root
,
$env
[
$callback
]);
}
}
echo
"
\n
... initialization completed.
\n\n
"
;
function
getFileList
(
$root
,
$basePath
=
''
)
{
$files
=
[];
$handle
=
opendir
(
$root
);
while
((
$path
=
readdir
(
$handle
))
!==
false
)
{
if
(
$path
===
'.git'
||
$path
===
'.svn'
||
$path
===
'.'
||
$path
===
'..'
)
{
continue
;
}
$fullPath
=
"
$root
/
$path
"
;
$relativePath
=
$basePath
===
''
?
$path
:
"
$basePath
/
$path
"
;
if
(
is_dir
(
$fullPath
))
{
$files
=
array_merge
(
$files
,
getFileList
(
$fullPath
,
$relativePath
));
}
else
{
$files
[]
=
$relativePath
;
}
}
closedir
(
$handle
);
return
$files
;
}
function
copyFile
(
$root
,
$source
,
$target
,
&
$all
,
$params
)
{
if
(
!
is_file
(
$root
.
'/'
.
$source
))
{
echo
" skip
$target
(
$source
not exist)
\n
"
;
return
true
;
}
if
(
is_file
(
$root
.
'/'
.
$target
))
{
if
(
file_get_contents
(
$root
.
'/'
.
$source
)
===
file_get_contents
(
$root
.
'/'
.
$target
))
{
echo
" unchanged
$target
\n
"
;
return
true
;
}
if
(
$all
)
{
echo
" overwrite
$target
\n
"
;
}
else
{
echo
" exist
$target
\n
"
;
echo
" ...overwrite? [Yes|No|All|Quit] "
;
$answer
=
!
empty
(
$params
[
'overwrite'
])
?
$params
[
'overwrite'
]
:
trim
(
fgets
(
STDIN
));
if
(
!
strncasecmp
(
$answer
,
'q'
,
1
))
{
return
false
;
}
else
{
if
(
!
strncasecmp
(
$answer
,
'y'
,
1
))
{
echo
" overwrite
$target
\n
"
;
}
else
{
if
(
!
strncasecmp
(
$answer
,
'a'
,
1
))
{
echo
" overwrite
$target
\n
"
;
$all
=
true
;
}
else
{
echo
" skip
$target
\n
"
;
return
true
;
}
}
}
}
file_put_contents
(
$root
.
'/'
.
$target
,
file_get_contents
(
$root
.
'/'
.
$source
));
return
true
;
}
echo
" generate
$target
\n
"
;
@
mkdir
(
dirname
(
$root
.
'/'
.
$target
),
0777
,
true
);
file_put_contents
(
$root
.
'/'
.
$target
,
file_get_contents
(
$root
.
'/'
.
$source
));
return
true
;
}
function
getParams
()
{
$rawParams
=
[];
if
(
isset
(
$_SERVER
[
'argv'
]))
{
$rawParams
=
$_SERVER
[
'argv'
];
array_shift
(
$rawParams
);
}
$params
=
[];
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
;
}
function
setWritable
(
$root
,
$paths
)
{
foreach
(
$paths
as
$writable
)
{
if
(
is_dir
(
"
$root
/
$writable
"
))
{
echo
" chmod 0777
$writable
\n
"
;
@
chmod
(
"
$root
/
$writable
"
,
0777
);
}
else
{
echo
"
\n
Error. Directory
$writable
does not exist.
\n
"
;
}
}
}
function
setExecutable
(
$root
,
$paths
)
{
foreach
(
$paths
as
$executable
)
{
echo
" chmod 0755
$executable
\n
"
;
@
chmod
(
"
$root
/
$executable
"
,
0755
);
}
}
function
setCookieValidationKey
(
$root
,
$paths
)
{
foreach
(
$paths
as
$file
)
{
echo
" generate cookie validation key in
$file
\n
"
;
$file
=
$root
.
'/'
.
$file
;
$length
=
32
;
$bytes
=
openssl_random_pseudo_bytes
(
$length
);
$key
=
strtr
(
substr
(
base64_encode
(
$bytes
),
0
,
$length
),
'+/='
,
'_-.'
);
$content
=
preg_replace
(
'/(("|\')cookieValidationKey("|\')\s*=>\s*)(""|\'\')/'
,
"
\\
1'
$key
'"
,
file_get_contents
(
$file
));
file_put_contents
(
$file
,
$content
);
}
}
function
createSymlink
(
$root
,
$links
)
{
foreach
(
$links
as
$link
=>
$target
)
{
echo
" symlink "
.
$root
.
"/"
.
$target
.
" "
.
$root
.
"/"
.
$link
.
"
\n
"
;
//first removing folders to avoid errors if the folder already exists
@
rmdir
(
$root
.
"/"
.
$link
);
//next removing existing symlink in order to update the target
if
(
is_link
(
$root
.
"/"
.
$link
))
{
@
unlink
(
$root
.
"/"
.
$link
);
}
@
symlink
(
$root
.
"/"
.
$target
,
$root
.
"/"
.
$link
);
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录