public function handle() { $this->checkArgs(array('table')); $namespace = array_key_exists('namespace', $this->args) ? $this->args['namespace'] : null; if (!isset($namespace)) { $namespace = array_key_exists('ns', $this->args) ? $this->args['ns'] : null; } $table = $this->args['table']; $class = array_key_exists('class', $this->args) ? $this->args['class'] : Strings::snakeToCamel($table); $path = $this->path($class, $namespace); $schema = new TableSchema($table); if (file_exists($path)) { $content = File::readText($path); $className = isset($namespace) ? "{$namespace}\\{$class}" : $class; $reflection = new \ReflectionClass($className); $header = $reflection->getDocComment(); if (isset($header)) { $content = str_replace($header, Template::generateHeader($schema->columns()), $content); unlink($path); File::writeText($path, $content); } Console::line("Model [{$class}] updated in path [{$path}]."); } else { File::writeText($path, Template::generateModel($table, $class, $schema->columns(), $namespace)); Console::line("Model [{$class}] created in path [{$path}]."); } }
private function makeMigration() { if (!isset($this->args[1])) { throw new ConsoleException("Invalid migration argument in [--make]."); } $migration = $this->args[1]; $author = isset($this->args[2]) ? $this->args[2] : "Unknown"; $class = 'm' . time() . Strings::snakeToCamel($migration); $path = App::path('migration') . "/{$class}.php"; File::writeText($path, Template::generate($class, $author)); Console::line("migration [{$migration}] finished in [{$class}.php]."); }
private function createPidFile() { File::writeText($this->pidFilePath, posix_getpid()); }
private function writeCache() { File::writeText($this->source, serialize($this)); }
public static function save($path, $content) { if (isset($path)) { File::writeText($path, $content); } }