コード例 #1
0
ファイル: ScanTables.php プロジェクト: janpoem/kephp
 protected function onPrepare($argv = null)
 {
     $this->adapter = Db::getAdapter($this->source);
     $this->prefix = trim($this->adapter->getConfiguration()['prefix'], ' -_.');
     $this->tables = $this->adapter->getForge()->getDbTables();
     if (!empty($this->namespace)) {
         $this->namespace = str_replace('/', '\\', trim($this->namespace, KE_PATH_NOISE));
     }
 }
コード例 #2
0
ファイル: NewModel.php プロジェクト: janpoem/kephp
 public function buildModel(string $table, string $class, string $path)
 {
     list($namespace, $pureClass) = parse_class($class);
     $dir = dirname($path);
     $tpl = $this->getTplContent();
     $forge = $this->adapter->getForge();
     $vars = $forge->buildTableProps($table);
     $vars['namespace'] = $namespace;
     $vars['class'] = $pureClass;
     $vars['tableName'] = $table;
     $vars['datetime'] = date('Y-m-d H:i:s');
     if (is_file($path)) {
         return ['Fail', PHP_EOL, "File {$path} is existing!"];
     }
     if (!is_dir($dir)) {
         mkdir($dir, 0755, true);
     }
     if (file_put_contents($path, substitute($tpl, $vars))) {
         return ['Success'];
     } else {
         return ['Fail', PHP_EOL, 'I/O error, please try again!'];
     }
 }