Example #1
0
 /**
  * You can overwrite this method to add portion of the code to be executed every time before action.
  * @param string $actionName name of the action to be executed, except for action part
  * @return boolean true to continue
  */
 protected function beforeAction($actionName)
 {
     if (!$this->debug) {
         InlineCliLogger::get()->ignoredClasses = array('mpf\\datasources\\sql\\PDOConnection');
         Helper::get()->showProgressBar = false;
     }
     return true;
 }
Example #2
0
 protected static function mailConfig()
 {
     echo "Setup MailHelper (from && reply-to data): \n";
     echo "You can configure multiple setups to be used by different scenarious. To use a different setup other than" . "`default` just complete in `from` param the name of the setup. It will automatically get the info from the config\n";
     $key = 'default';
     do {
         echo "Set-up {$key} options:\n";
         self::$data['mpf\\helpers\\MailHelper'][$key] = ['email' => Helper::get()->input("From Email Address", '*****@*****.**'), 'name' => Helper::get()->input("From Name", "MPF App"), 'reply-to' => ['email' => Helper::get()->input("Reply-to Email Address", "*****@*****.**"), 'name' => Helper::get()->input("Reply-to Name", '')]];
     } while ('n' != ($key = Helper::get()->input("Next setup(n - to stop)", 'n')));
 }
Example #3
0
File: SQL.php Project: mpf-soft/mpf
 public static function testConnection($type, $host, $name, $user, $pass)
 {
     try {
         self::$connection = new PDOConnection(['dns' => "{$type}:dbname={$name};host={$host}", 'username' => $user, 'password' => $pass]);
     } catch (\Exception $e) {
         echo Helper::get()->color("Error: " . $e->getMessage(), Helper::CLIGHT_RED) . "\n\n\n";
         self::$retryCount++;
         self::$connected = false;
         if (self::$retryCount > 3) {
             return 'y' == Helper::get()->input("Skip this step?", 'n');
         } else {
             return false;
         }
     }
     echo "\n" . Helper::get()->color("Connected!", Helper::CLIGHT_GREEN) . "\n";
     self::$connected = true;
     return true;
 }
Example #4
0
 protected function getAllCommands()
 {
     $path = APP_ROOT . str_replace('\\', '/', ConsoleApp::get()->commandsNamespace) . DIRECTORY_SEPARATOR;
     if (!$path) {
         return array();
     }
     $files = scandir($path);
     echo HCli::color('Available actions: ' . "\n\n");
     foreach ($files as $file) {
         if (in_array($file, array('.', '..', '.htaccess'))) {
             continue;
         }
         $command = lcfirst(str_replace('.php', '', $file));
         $reflection = new \ReflectionClass($this->getClassFromFile($file));
         $methods = $reflection->getMethods(\ReflectionMethod::IS_PUBLIC);
         foreach ($methods as $method) {
             $this->present($command, $method, $reflection);
         }
     }
     echo "\n";
 }
Example #5
0
 protected function colorizeLog($message, $level)
 {
     return HCli::get()->color($message, $this->levelsToColors[$level], $this->levelsToBackground[$level]);
 }
Example #6
0
    public function actionModel($table)
    {
        if (!ConsoleApp::get()->sql()->tableExists($table)) {
            $this->error("Table `{$table}` not found!");
            if (!($table = $this->similarTables($table))) {
                return;
            }
        }
        $className = str_replace(' ', '', ucwords(str_replace('_', ' ', $table)));
        $className = Helper::get()->input("Class name", $className);
        $this->info("Selected class: {$className}");
        $columns = ConsoleApp::get()->sql()->getTableColumns($table);
        $modelInfo = array('table' => $table, 'class' => $className, 'namespace' => Helper::get()->input("Namespace", 'app\\models'), 'columns' => array(), 'labels' => array());
        echo "Labels (found " . count($columns) . " columns): \n";
        foreach ($columns as $column) {
            $modelInfo['columns'][$column['Field']] = $column['Type'];
            $modelInfo['labels'][$column['Field']] = Helper::get()->input($column['Field'], ucwords(str_replace('_', ' ', $column['Field'])));
        }
        if ('Y' == strtoupper(Helper::get()->input('Add relations? (y/n)', 'y'))) {
            $modelInfo['relations'] = array();
            do {
                $name = '';
                while (!$name) {
                    $name = Helper::get()->input('Name');
                }
                $type = 0;
                while (!$type) {
                    $type = Helper::get()->input('Types
[1] : BELONGS_TO
[2] : HAS_ONE
[3] : HAS_MANY
[4] : MANY_TO_MANY

Selected type');
                }
                $model = '';
                $classError = false;
                while (!$model || ($classError = !class_exists($model))) {
                    if ($classError) {
                        $this->error('Class "' . $model . '" not found!');
                        $classError = false;
                    }
                    $model = Helper::get()->input('Model class');
                }
                $connection = '';
                while (!$connection) {
                    $connection = Helper::get()->input('Connection');
                }
                $modelInfo['relations'][] = array('name' => $name, 'type' => $type, 'model' => $model, 'connection' => $connection);
            } while ('y' == Helper::get()->input('Add more? (y/n)', 'y'));
        }
        $creator = new Creator($modelInfo);
        if ($creator->model()) {
            $this->debug('model created!');
        }
    }
Example #7
0
 public function previewLog($lines = 40)
 {
     exec("tail -n {$lines} {$this->log}", $output);
     return Helper::get()->logToHtml(implode("\n", $output));
 }