/** * Read the database's configuration file * * @since 1.0 * @access private * @param $item the item's name * @return string */ private function loadDbConfig() { if (empty($this->db)) { require PROJECTS_PATH . DS . ProjectIgniter::getName() . DS . 'db.php'; if ($db == null || empty($db)) { return false; } $this->db = $db; } }
/** * Receives the name of the project and decide * what to do, create a new or use an existing * * @since 1.0 * @access public * @param string $name the project's name * @return void */ public function __construct($name) { self::$name = $name; if (!file_exists(PROJECTS_PATH . DS . self::$name)) { ConsoleIgniter::write('Project not found!'); $this->newProject(); } else { if (!file_exists(PROJECTS_PATH . DS . self::$name . DS . 'db.php')) { ConsoleIgniter::write('Cannot find database configurations!'); $this->createDbConfig(); } } }
/** * Generates the model's file * * @see crudigniter/generator/Generator#generate() */ public function generate() { $model = ProjectIgniter::getName() . DS . 'application' . DS . strtolower($this->layer . 's') . DS . strtolower($this->tables[$this->choosedLayer]['Name']) . '_' . strtolower($this->layer) . '.php'; $content = parent::getTemplate(); if ($content === false) { ConsoleIgniter::write($this->layer . ' ' . $model . ' was not created!'); } else { if ($this->overrideFile(PROJECTS_PATH . DS . $model)) { file_put_contents(PROJECTS_PATH . DS . $model, $content); ConsoleIgniter::write($this->layer . ' ' . $model . ' was successfully created!'); } else { ConsoleIgniter::write($this->layer . ' ' . $model . ' was not created!'); } } }
/** * Generates the view's files * * @see crudigniter/generator/Generator#generate() */ public function generate() { $table = strtolower($this->tables[$this->choosedLayer]['Name']); if (!file_exists(PROJECTS_PATH . DS . ProjectIgniter::getName() . DS . 'application' . DS . 'views' . DS . $table)) { mkdir(PROJECTS_PATH . DS . ProjectIgniter::getName() . DS . 'application' . DS . 'views' . DS . $table); } foreach ($this->tables[$this->choosedLayer]['Views'] as $view) { $content = parent::getTemplate($view); $template = ProjectIgniter::getName() . DS . 'application' . DS . strtolower($this->layer . 's') . DS . $table . DS . $view . '.php'; if ($content === false) { ConsoleIgniter::write($this->layer . ' ' . $template . ' was not created!'); } else { if ($this->overrideFile(PROJECTS_PATH . DS . $template)) { file_put_contents(PROJECTS_PATH . DS . $template, $content); ConsoleIgniter::write($this->layer . ' ' . $template . ' was successfully created!'); } else { ConsoleIgniter::write($this->layer . ' ' . $template . ' was not created!'); } } } }