Ejemplo n.º 1
22
 /**
  * @return CliManager|void
  */
 public function handlingProcess()
 {
     // Set Environments
     $env = $_SERVER['argv'];
     if (sizeof($env) != 2 || !strpos($env[1], ":")) {
         return CliManager::getErrorMessage("Unknown Command \nview help:commands");
     }
     $this->getObjectManager()->get('router')->checkCliRoutes();
     return new CliManager($env[1]);
 }
Ejemplo n.º 2
18
 /**
  * Clear Assets
  */
 public function clearAction()
 {
     // get Asset manager
     $assets = Safan::handler()->getObjectManager()->get('assets');
     // get assets path
     $path = $assets->getCompressor()->getAssetsPath();
     if (is_dir($path)) {
         shell_exec('rm -rf ' . $path . DS . '*');
     } else {
         return CliManager::getErrorMessage('Assets path is not exist');
     }
 }
Ejemplo n.º 3
0
 /**
  * Check Table fields
  *
  * @param $modelObj
  * @return bool
  */
 private function checkTable($modelObj)
 {
     if (!method_exists($modelObj, 'table')) {
         return false;
     }
     // get table name
     $tableName = $modelObj->table();
     // check table, add if not exist
     $existTable = PdoDriver::getInstance()->tableExists($tableName);
     if (!$existTable) {
         $this->createTable($tableName, $modelObj->getFields());
         CliManager::getMessage('Created table ' . $tableName);
     }
     // get database table data and check
     PdoDriver::getInstance()->query('SHOW COLUMNS FROM ' . $tableName);
     $dbFields = PdoDriver::getInstance()->selectAll();
     $modelFieldNames = [];
     foreach ($modelObj->getFields() as $modelField) {
         $modelFieldNames[] = $modelField->identifier();
     }
     // check db fields on model fields
     $dbFieldNames = [];
     foreach ($dbFields as $dbField) {
         if (!in_array($dbField->Field, $modelFieldNames)) {
             echo " --- Old field " . CliManager::setTextColor($dbField->Field, 'yellow') . " in table " . CliManager::setTextColor($modelObj->table(), 'green') . " --- \n\r";
         }
         $dbFieldNames[] = $dbField->Field;
     }
     // check model fields on db fields
     foreach ($modelObj->getFields() as $key => $modelField) {
         if (!in_array($modelField->identifier(), $dbFieldNames)) {
             // Add new fields to db table
             $previousField = false;
             if (isset($modelObj->getFields()[$key - 1])) {
                 $previousField = $modelObj->getFields()[$key - 1];
             }
             $this->createField($tableName, $modelField, $previousField);
             echo CliManager::setTextColor(" --- Add New field " . $modelField->identifier() . " in table " . $modelObj->table(), 'green') . " --- \n\r";
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Get Error message for unknown command
  */
 public function notfoundAction()
 {
     return CliManager::getErrorMessage('Command not found');
 }