Пример #1
0
 public function main()
 {
     $_ = $this;
     $_->APP_ROOT = CmdLibs::getAppRoot(1);
     $_->initView();
     $_->usage = $_->getUsage();
     $params = $_->getParams();
     if ($params['rootDir']) {
         $parentPath = $params['rootDir'];
     } else {
         $parentPath = CmdLibs::getParentPath($_->APP_ROOT);
     }
     echo "parentPath={$parentPath}\n";
     $newAppRoot = $parentPath . '/' . $params['appName'];
     if (!file_exists($newAppRoot)) {
         mkdir($newAppRoot, 0755, true);
         $filename = 'composer.json';
         copy($_->APP_ROOT . '/' . $filename, "{$newAppRoot}/{$filename}");
         $subdirs = array("behavior" => 0755, "bin" => 0755, "controller" => 0755, "controller/cmn" => 0755, "etc" => 0755, "etc/template" => 0755, "htdocs" => 0755, "htdocs/cmn" => 0755, "htdocs/cmn/img" => 0755, "lib" => 0755, "lib/Datatype" => 0755, "lib/DbOperator" => 0755, "lib/share" => 0755, "lib/Util" => 0755, "model" => 0755, "model/_def" => 0755, "model/_def/api" => 0755, "model/_def/db" => 0755, "model/amazon" => 0755, "model/excel" => 0755, "test" => 0755, "test/controller" => 0755, "test/model" => 0755, "test/model/amazon" => 0755, "test/model/excel" => 0755, "var" => 0755, "var/compiled" => 0777, "var/files" => 0777, "var/images" => 0777, "var/images/uploaded" => 0777, "var/log" => 0777, "view" => 0755, "view/cmn" => 0755, "view/cmn/css" => 0755, "view/cmn/includes" => 0755, "view/cmn/js" => 0755, "view/cmn/js/jarty" => 0755, "view/cmn/js/validationEngine" => 0755, "view/cmn/js/validationEngine/languages" => 0755, "view/cmn/js/validationEngine/contrib" => 0755, "view/cmn/lang" => 0755, "view/cmn/layout" => 0755);
         $oldMask = umask(0);
         foreach ($subdirs as $subdir => $permission) {
             mkdir("{$newAppRoot}/{$subdir}", $permission, true);
             if ($subdir == 'var/compiled') {
                 continue;
             }
             $files = glob($_->APP_ROOT . "/{$subdir}/*");
             if (!empty($files)) {
                 foreach ($files as $filepath) {
                     if (!is_dir($filepath)) {
                         $filename = basename($filepath);
                         copy($filepath, "{$newAppRoot}/{$subdir}/{$filename}");
                     }
                 }
             }
         }
         $_->copySubdirs("etc/template", $newAppRoot);
         $_->view->assign('APP_NAME', $params['appName']);
         $_->view->assign('APP_ROOT', $newAppRoot);
         $localVh = $_->view->fetch($_->APP_ROOT . '/etc/local_vh.conf');
         $vhFilePath = "{$newAppRoot}/etc/local_vh.conf";
         file_put_contents($vhFilePath, $localVh);
         chmod("{$newAppRoot}/bin/makeNewApp.php", 0755);
         chmod("{$newAppRoot}/bin/makeDbClassFile.php", 0755);
         chmod("{$newAppRoot}/bin/makeTableClassFiles.php", 0755);
         chmod("{$newAppRoot}/bin/makeModelClassFiles.php", 0755);
         chmod("{$newAppRoot}/bin/makeCtlAndView.php", 0755);
         chmod("{$newAppRoot}/bin/test.sh", 0755);
         chmod("{$newAppRoot}/bin/genTest.sh", 0755);
         chmod("{$newAppRoot}/bin/backSyncToMin.sh", 0755);
         chmod("{$newAppRoot}/bin/syncFromMin.sh", 0755);
         chmod("{$newAppRoot}/bin/setup.sh", 0755);
         chmod("{$newAppRoot}/etc/template/bin/setSample.sh", 0755);
         umask($oldMask);
     }
     if (!empty($params['dbName'])) {
         $_->saveDbClassFile($params);
     }
     echo "\n\nPlease run 'composer install' at new app root.\n";
     exit;
 }