コード例 #1
0
 public function generate()
 {
     $warning = false;
     if (!is_dir($this->model_path)) {
         throw new \Exception("[RepelGenerator] Given model path does not exist, or is not a directory! ({$this->model_path})");
     }
     if (!is_dir($this->base_path)) {
         mkdir($this->base_path);
     } else {
         // Check if proper directory
         $dh = opendir($this->base_path);
         $ignore = array('.', '..');
         $warning = false;
         while (false !== ($filename = readdir($dh))) {
             if (in_array($filename, $ignore)) {
                 continue;
             }
             if (preg_match('/^R.*Base.php$/', $filename)) {
                 unlink($this->base_path . $filename);
             } else {
                 $warning = true;
             }
         }
     }
     if ($warning) {
         echo CLI::warning("Warning! Irrelevant files found in base_path!");
     }
     foreach ($this->adapter->getSchemaTables($this->key) as $t) {
         foreach ($this->adapter->getTables() as $table) {
             if ($table->name === $t) {
                 echo CLI::dotFill($table->name . ' (' . CLI::color($table->type, dark_gray) . ')', DOT_FILL + 11);
                 $this->clear();
                 $table_filename = self::getTableName($table->name);
                 $query_filename = self::getQueryName($table->name);
                 $table_base_filename = self::getTableBaseName($table->name);
                 $query_base_filename = self::getQueryBaseName($table->name);
                 if (!file_exists($this->model_path . $table_filename . '.php')) {
                     file_put_contents($this->model_path . $table_filename . '.php', $this->generateTable($table));
                 }
                 if (!file_exists($this->model_path . $query_filename . '.php')) {
                     file_put_contents($this->model_path . $query_filename . '.php', $this->generateTableQuery($table));
                 }
                 file_put_contents($this->base_path . $table_base_filename . '.php', $this->generateTableBase($table));
                 file_put_contents($this->base_path . $query_base_filename . '.php', $this->generateTableQueryBase($table));
                 echo CLI::color("done", green) . "\n";
             }
         }
     }
 }