#!/usr/bin/env php $v) { if ($method == 2) { $n = explode('/', $v); $m = count($n) - 2; $n = $n[$m]; if (!is_dir(PATH . 'web/data/assets/' . $n)) { $n = 'default'; } $template = $v . 'template'; if (!is_dir(PATH . $template)) { $template = $v . 'main/template'; } $e = ' web/data/assets/' . $n . ' web/data/compile/' . $n . ' --exclude=' . $template; } else { $e = ' --exclude=' . $v . 'template'; } $path .= ' ' . $v . $e; } } } self::command('tar -czf install/' . $name . '.tar.gz ' . $path . ' --exclude-vcs'); } protected static function method_init_laravel() { self::command('composer create-project laravel/laravel --prefer-dist'); } protected static function method_create() { self::method_install('create'); } protected static function method_mysql() { $text = array ( '请输入命令以执行相应操作:' , 'backup:备份mysql' , 'restore:恢复mysql' , '请在输入命令之后按回车键', ); $shell = self::input($text); switch ($shell) { case 'backup': Mysql::backup(); break; case 'restore': Mysql::restore(); break; default: echo "未定义的方法"; break; } } protected static function method_install($value) { $value .= '.tar.gz'; if (self::check()) { self::command('wget -c ' . self::$package . $value); self::command('tar -zxvf ' . $value); self::command('rm -rf ' . $value); if ($value == 'composer') { self::method_init($value); } } elseif (class_exists('PharData')) { self::$check = true; $path = dirname(__FILE__) . '/'; file_put_contents($path . $value, file_get_contents(self::$package . $value)); $phar = new PharData($value); $phar->extractTo($path, null, true); unlink($path . $value); } else { self::notice(); } } private static function copy($src, $dst, $path) { if (function_exists('system')) { system('cp -R ' . $src . ' ' . $dst); } else { $path = str_replace(array('/', '..'), '', $path); $dst = $dst . $path; if (!is_dir($dst)) { mkdir($dst); } $dir = opendir($src); while (false !== ($file = readdir($dir))) { if (($file != '.') && ($file != '..')) { if (is_dir($src . '/' . $file)) { $this->copyDir($src . '/' . $file, $dst . '/' . $file); } else { copy($src . '/' . $file, $dst . '/' . $file); } } } closedir($dir); } } protected static function method_build($path = 'vendor') { //$exts = ['php','js','css','html']; $exts = array('php', 'js', 'css', 'html'); $dir = dirname(__FILE__) . '/build/'; $path && system('cp -R ' . $path . ' ' . $dir); $file = 'dever.phar'; $phar = new Phar($dir . $file, FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME, $file); $phar->startBuffering(); if ($path) { foreach ($exts as $ext) { $phar->buildFromDirectory($dir, '/\.' . $ext . '$/'); } } $index = 'boot.php'; $phar->buildFromIterator ( new ArrayIterator ( array ( $index => $dir . $index, ) ) ); //$phar->delete('build.php'); $phar->setStub($phar->createDefaultStub($index, $index)); $phar->compressFiles(Phar::GZ); $phar->stopBuffering(); //system('cp -R ' . $dir . $file . ' ' . $file); $path && system('rm -rf ' . $dir . $path); } } class Create extends Dever { } class Mysql extends Dever { protected static function common() { $info['host'] = self::input('请输入mysql的主机地址:默认为localhost', 'localhost'); $info['username'] = self::input('请输入mysql的账号:默认为root', 'root'); $info['password'] = self::input('请输入mysql的密码:默认为空', ''); $info['database'] = self::input('请输入mysql的数据库名:'); if (!$info['host'] || !$info['username'] || !$info['password'] || !$info['database']) { self::out('请输入正确的数据库信息!');die; } $info['file'] = PATH . 'web/data/sql/' . $info['database']; $info['shell'] = ' -u' . $info['username'] . ' -p' . $info['password'] . ' -h' . $info['host'] . ' '; return $info; } public static function backup() { $info = self::common(); $info['table'] = self::input('请输入mysql的表名(不输入则备份整个' . $info['database'] . '数据库):'); $info['type'] = self::input('请输入备份类型:1为备份全部,2为备份结构,3为备份数据'); $info['shell'] = 'mysqldump ' . $info['shell']; if ($info['type'] == 2) { $info['shell'] .= ' -d ' . $info['database']; } elseif ($info['type'] == 3) { $info['shell'] .= ' -t ' . $info['database']; } else { $info['shell'] .= ' ' . $info['database']; } if ($info['table']) { $info['shell'] .= ' ' . $info['table']; $info['file'] .= '.' . $info['table']; } $info['file'] .= '.sql'; $info['shell'] .= ' > ' . $info['file']; self::command($info['shell']); self::out('操作成功,输出路径:' . $info['file']); } public static function restore() { $info = self::common(); $info['new'] = self::input('请输入要恢复的全新数据库:为空则使用上边填的数据库', $info['database']); $create_table = 'mysqladmin ' . $info['shell'] . ' create ' . $info['new']; $info['shell'] = 'mysql ' . $info['shell'] . ' ' . $info['new']; $info['file'] .= '.sql'; $info['shell'] .= ' < ' . $info['file']; self::exe($create_table); self::command($info['shell']); self::out('操作成功,您已成功恢复' . $info['file'] . '里的数据'); } } Dever::handle();