Exemple #1
0
 public function cli()
 {
     //命令模式
     if (IS_CLI && $_SERVER['SCRIPT_NAME'] == 'hd') {
         require_once __DIR__ . '/../cli/Cli.php';
         \hdphp\cli\Cli::run();
         exit;
     }
 }
Exemple #2
0
 public function run($name)
 {
     //检测文件是否存在,也检测类名
     foreach (glob(ROOT_PATH . '/system/database/migrations/*.php') as $f) {
         if (substr(basename($f), 18, -4) == $name) {
             \hdphp\cli\Cli::error("File already exists\n");
         }
     }
     $file = ROOT_PATH . '/system/database/seeds/' . date('Y_m_d') . '_' . substr(time(), -6) . '_' . $name . '.php';
     //创建文件
     $data = file_get_contents(__DIR__ . '/view/seeder.tpl');
     $data = str_replace(['{{className}}'], [$name], $data);
     file_put_contents($file, $data);
 }
Exemple #3
0
 /**
  * 创建模型或控制器
  * @param $arg [0=>'模型名']
  */
 public function make($arg)
 {
     $info = explode('.', $arg);
     $MODEL = ucfirst($info[0]);
     $TABLE = strtolower($info[0]);
     $file = 'system/model/' . ucfirst($MODEL) . '.php';
     //创建模型文件
     if (is_file($file)) {
         \hdphp\cli\Cli::error("Model file already exists");
     } else {
         $data = file_get_contents(__DIR__ . '/Model.tpl');
         $data = str_replace(['{{MODEL}}', '{{TABLE}}'], [$MODEL, $TABLE], $data);
         file_put_contents($file, $data);
     }
 }
Exemple #4
0
 /**
  * 创建控制器
  *
  * @param  string $arg 路径
  * @param  string $type 参数 base 基本 resource 资源
  *
  * @return void
  */
 public function make($arg, $type = 'controller')
 {
     $info = explode('.', $arg);
     $MODULE = $info[0];
     $CONTROLLER = ucfirst($info[1]);
     $file = APP_PATH . '/' . $MODULE . '/controller/' . ucfirst($CONTROLLER) . '.php';
     //判断目录
     if (!is_dir(APP_PATH . '/' . $MODULE . '/controller')) {
         die("Directory does not exist\n");
     }
     //创建模型文件
     if (is_file($file)) {
         \hdphp\cli\Cli::error('Controller file already exists');
     } else {
         $data = file_get_contents(__DIR__ . '/' . ucfirst($type) . '.tpl');
         $data = str_replace(['{{APP}}', '{{MODULE}}', '{{CONTROLLER}}'], [c('app.path'), $MODULE, $CONTROLLER], $data);
         file_put_contents($file, $data);
     }
 }
Exemple #5
0
 public function error($errno, $error, $file, $line)
 {
     $msg = $error . "({$errno})" . $file . " ({$line}).";
     //命令行模式
     IS_CLI and \hdphp\cli\Cli::error($msg);
     switch ($errno) {
         case E_NOTICE:
         case E_USER_NOTICE:
         case E_DEPRECATED:
             break;
         default:
             if (c('app.debug')) {
                 require __DIR__ . '/view/debug.php';
             } else {
                 class_exists('Log', FALSE) && Log::write($msg, $this->errorType($errno));
                 _404();
             }
     }
 }
Exemple #6
0
 public function run($name, $arg)
 {
     $info = explode('=', $arg);
     //检测文件是否存在,也检测类名
     foreach (glob(ROOT_PATH . '/system/database/migrations/*.php') as $f) {
         if (substr(basename($f), 18, -4) == $name) {
             \hdphp\cli\Cli::error("File already exists\n");
         }
     }
     $file = ROOT_PATH . '/system/database/migrations/' . date('Y_m_d') . '_' . substr(time(), -6) . '_' . $name . '.php';
     if ($info[0] == '--create') {
         //创建模型文件
         $data = file_get_contents(__DIR__ . '/view/migration.create.tpl');
         $data = str_replace(['{{TABLE}}', '{{className}}'], [$info[1], $name], $data);
         file_put_contents($file, $data);
     }
     if ($info[0] == '--table') {
         //创建模型文件
         $data = file_get_contents(__DIR__ . '/view/migration.table.tpl');
         $data = str_replace(['{{TABLE}}', '{{className}}'], [$info[1], $name], $data);
         file_put_contents($file, $data);
     }
 }
Exemple #7
0
 function cli()
 {
     $argv[] = 'hd';
     foreach (func_get_args() as $v) {
         $argv[] = $v;
     }
     $_SERVER['argv'] = $argv;
     \hdphp\cli\Cli::run();
 }