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}]."); } }
public function posts($prefix = null, $htmlFilter = true) { if (isset($prefix) && is_string($prefix)) { $posts = array(); $items = Generic::fast_array_key_filter($_POST, $prefix . '_'); foreach ($items as $key => $value) { $key = str_replace($prefix . '_', '', $key); if (!$htmlFilter) { $posts[$key] = $value; } else { $posts[$key] = Strings::htmlFilter($value); } } return $posts; } else { $posts = array(); foreach ($_POST as $key => $value) { if (!$htmlFilter) { $posts[$key] = $value; } else { $posts[$key] = Strings::htmlFilter($value); } } return $posts; } }
private function clearTableSchema($name) { if (preg_match('#m[\\d]+(Create|Alter)(?<table>[a-zA-Z][a-zA-Z0-9\\_]+)Table#i', $name, $matches)) { $table = strtolower(Strings::camelToSnake($matches['table'])); $path = App::path('cache') . "/schema/" . DB::getDatabaseName() . "/{$table}.dat"; if (file_exists($path)) { unlink($path); } } }
public function __construct() { if (isset($this->table)) { $table = $this->table; } else { $statements = explode('\\', get_called_class()); $table = $statements[count($statements) - 1]; $table = Strings::camelToSnake($table); } $this->initializeModel($table); }
public static function generateModel($table, $class, array $properties, $namespace = null) { $content = str_replace('{{header}}', self::generateHeader($properties), self::getModelTemplate()); $namespace = isset($namespace) ? "namespace {$namespace};" : ""; $content = str_replace('{{namespace}}', $namespace, $content); $content = str_replace('{{model}}', $class, $content); $content = str_replace('{{table_name}}', $table === Strings::camelToSnake($class) ? "" : ' protected $table = "' . $table . '"; ', $content); return $content; }
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]."); }