Ejemplo n.º 1
0
 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}].");
     }
 }
Ejemplo n.º 2
0
 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;
     }
 }
Ejemplo n.º 3
0
 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);
         }
     }
 }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
0
    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;
    }
Ejemplo n.º 6
0
 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].");
 }