|
|
<?php
|
|
|
/**
|
|
|
* Created by PhpStorm.
|
|
|
* User: Zip
|
|
|
* Date: 15/4/5
|
|
|
* Time: 下午4:54
|
|
|
*/
|
|
|
|
|
|
namespace QSns\Composer;
|
|
|
|
|
|
|
|
|
class Common
|
|
|
{
|
|
|
const DS = DIRECTORY_SEPARATOR;
|
|
|
|
|
|
/**
|
|
|
* 安装App
|
|
|
* @param $appName
|
|
|
* @throws \Exception
|
|
|
*/
|
|
|
static public function installApp($appName)
|
|
|
{
|
|
|
$appPath = dirname(dirname(__DIR__)) . self::DS . "Application" . self::DS . $appName;
|
|
|
if (!file_exists($appPath)) {
|
|
|
return;
|
|
|
}
|
|
|
$toAppPath = realpath("../../") . self::DS . 'application' . self::DS . 'modules' . self::DS . $appName;
|
|
|
self::moveName($appPath, $toAppPath);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 卸载App
|
|
|
* @param $appName
|
|
|
*/
|
|
|
static public function uninstallApp($appName)
|
|
|
{
|
|
|
$toAppPath = realpath("../../") . self::DS . 'application' . self::DS . 'modules' . self::DS . $appName;
|
|
|
self::delTree($toAppPath);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 移动文件夹
|
|
|
* @param $appPath
|
|
|
* @param $toAppPath
|
|
|
* @throws \Exception
|
|
|
*/
|
|
|
static public function moveName($appPath, $toAppPath)
|
|
|
{
|
|
|
$appRootPath = dirname($toAppPath);
|
|
|
if (!file_exists($appRootPath)) {
|
|
|
if (!mkdir($appRootPath, 0777, true)) {
|
|
|
throw new \Exception('Error : ' . $toAppPath . " Failed to create folders...");
|
|
|
}
|
|
|
}
|
|
|
if (is_writable(dirname($toAppPath)) == false) {
|
|
|
throw new \Exception('Error : ' . $toAppPath . " is readonly.");
|
|
|
}
|
|
|
if (file_exists($toAppPath) == true) {
|
|
|
self::delTree($toAppPath);
|
|
|
}
|
|
|
rename($appPath, $toAppPath);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 删除目录树
|
|
|
* @param $dir
|
|
|
* @return bool
|
|
|
*/
|
|
|
public static function delTree($dir)
|
|
|
{
|
|
|
$files = array_diff(scandir($dir), array('.', '..'));
|
|
|
foreach ($files as $file) {
|
|
|
(is_dir("$dir/$file")) ? self::delTree("$dir/$file") : unlink("$dir/$file");
|
|
|
}
|
|
|
return rmdir($dir);
|
|
|
}
|
|
|
} |
|
|
\ No newline at end of file |
...
|
...
|
|