示例#1
0
 /**
  * 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!');
         }
     }
 }
示例#2
0
 /**
  * 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!');
             }
         }
     }
 }
示例#3
0
 /**
  * Create the project's database configurations file
  * 
  * @since 1.0
  * @access private
  * @return void
  */
 private function createDbConfig()
 {
     //--------------------------------------------------------------------
     // DEFINE THE DATABASE CONFIGURATION
     //--------------------------------------------------------------------
     $db = array();
     $driverTypes = array('mysql');
     $db['dbdriver'] = $driverTypes[ConsoleIgniter::writeQuestion('What is the database driver?', $driverTypes, 0)];
     $db['hostname'] = ConsoleIgniter::writeQuestion('What is the host of the database server?', null, 'localhost');
     $db['username'] = ConsoleIgniter::writeQuestion('What is the database username?', null, 'root');
     $db['password'] = ConsoleIgniter::writeQuestion('What is the database password?', null, null, true);
     $db['database'] = ConsoleIgniter::writeQuestion('What is the name of the database?', null, 'code_igniter');
     //--------------------------------------------------------------------
     // SHOW THE DATABASE CONFIGURATION
     //--------------------------------------------------------------------
     ConsoleIgniter::write('');
     ConsoleIgniter::line();
     ConsoleIgniter::write('The following database configuration will be created.');
     ConsoleIgniter::line();
     ConsoleIgniter::write('Driver		: ' . $db['dbdriver']);
     ConsoleIgniter::write('Host			: ' . $db['hostname']);
     ConsoleIgniter::write('Username		: '******'username']);
     ConsoleIgniter::write('Password		: '******'password']);
     ConsoleIgniter::write('Database		: ' . $db['database']);
     ConsoleIgniter::line();
     $confirm = ConsoleIgniter::writeQuestion('The information above is correct?', array('y', 'n'), 0);
     if ($confirm != 0) {
         ConsoleIgniter::bye();
     }
     //--------------------------------------------------------------------
     // SAVE THE DATABASE CONFIGURATION
     //--------------------------------------------------------------------
     if (!file_exists(TEMPLATES_PATH . DS . 'db.php')) {
         ConsoleIgniter::write('ERROR!');
         ConsoleIgniter::write('Template: "' . TEMPLATES_PATH . DS . 'db.php" not found!');
         ConsoleIgniter::bye();
     }
     ob_start();
     require TEMPLATES_PATH . DS . 'db.php';
     $template = ob_get_clean();
     $template = "<?php\n" . $template;
     file_put_contents(PROJECTS_PATH . DS . self::$name . DS . 'db.php', $template);
     ConsoleIgniter::write('Database configuration was successfully created.');
 }
示例#4
0
 /**
  * List the CrudIgniter options
  * 
  * @since 1.0
  * @access public
  * @return void
  */
 public function listOptions()
 {
     $result = ConsoleIgniter::writeQuestion('What do you want to generate?', array('MODEL', 'VIEW', 'CONTROLLER', 'EXIT'), 0);
     $generator = null;
     $result = strtolower($result);
     switch ($result) {
         case 0:
             if (class_exists('MY_ModelGenerator')) {
                 $generator = new MY_ModelGenerator();
             } else {
                 $generator = new ModelGenerator();
             }
             break;
         case 1:
             if (class_exists('MY_ViewGenerator')) {
                 $generator = new MY_ViewGenerator();
             } else {
                 $generator = new ViewGenerator();
             }
             break;
         case 2:
             if (class_exists('MY_ControllerGenerator')) {
                 $generator = new MY_ControllerGenerator();
             } else {
                 $generator = new ControllerGenerator();
             }
             break;
         default:
             ConsoleIgniter::bye();
     }
     $generator->generate();
     ConsoleIgniter::bye();
 }
示例#5
0
 /**
  * Verify if a file can be overrided
  * 
  * @since 1.0
  * @access protected
  * @param string $file the file to verify
  * @return boolean
  */
 protected function overrideFile($file)
 {
     if (file_exists($file)) {
         $wannaOverride = ConsoleIgniter::writeQuestion('The file ' . $file . ' already exists, do you want to override?', array('y', 'n'), 0);
         if ($wannaOverride == 0) {
             return true;
         } else {
             return false;
         }
     }
     return true;
 }