- Refactor of all the MindCommand class

- Rebuilt of all programs to use the pattern of the new format designed for the new MindCommand class
Esse commit está contido em:
Felipe Nascimento de Moura
2011-04-15 23:32:55 -03:00
commit aa8e451a58
58 arquivos alterados com 320 adições e 619 exclusões
Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
Ver Arquivo

Antes

Largura:  |  Altura:  |  Tamanho: 694 KiB

Depois

Largura:  |  Altura:  |  Tamanho: 694 KiB

Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
Ver Arquivo

Antes

Largura:  |  Altura:  |  Tamanho: 464 KiB

Depois

Largura:  |  Altura:  |  Tamanho: 464 KiB

Arquivo normal → Arquivo executável
Ver Arquivo

Antes

Largura:  |  Altura:  |  Tamanho: 825 KiB

Depois

Largura:  |  Altura:  |  Tamanho: 825 KiB

Arquivo normal → Arquivo executável
Ver Arquivo

Antes

Largura:  |  Altura:  |  Tamanho: 602 KiB

Depois

Largura:  |  Altura:  |  Tamanho: 602 KiB

Arquivo normal → Arquivo executável
Ver Arquivo

Antes

Largura:  |  Altura:  |  Tamanho: 342 KiB

Depois

Largura:  |  Altura:  |  Tamanho: 342 KiB

Arquivo normal → Arquivo executável
Ver Arquivo

Antes

Largura:  |  Altura:  |  Tamanho: 107 KiB

Depois

Largura:  |  Altura:  |  Tamanho: 107 KiB

Ver Arquivo

Antes

Largura:  |  Altura:  |  Tamanho: 254 KiB

Depois

Largura:  |  Altura:  |  Tamanho: 254 KiB

Arquivo normal → Arquivo executável
Ver Arquivo

Antes

Largura:  |  Altura:  |  Tamanho: 19 KiB

Depois

Largura:  |  Altura:  |  Tamanho: 19 KiB

Arquivo normal → Arquivo executável
Ver Arquivo

Antes

Largura:  |  Altura:  |  Tamanho: 36 KiB

Depois

Largura:  |  Altura:  |  Tamanho: 36 KiB

Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
Ver Arquivo

Antes

Largura:  |  Altura:  |  Tamanho: 1.1 KiB

Depois

Largura:  |  Altura:  |  Tamanho: 1.1 KiB

Arquivo normal → Arquivo executável
Ver Arquivo

Antes

Largura:  |  Altura:  |  Tamanho: 12 KiB

Depois

Largura:  |  Altura:  |  Tamanho: 12 KiB

Arquivo normal → Arquivo executável
Ver Arquivo

Antes

Largura:  |  Altura:  |  Tamanho: 1.8 KiB

Depois

Largura:  |  Altura:  |  Tamanho: 1.8 KiB

Arquivo normal → Arquivo executável
Ver Arquivo

Antes

Largura:  |  Altura:  |  Tamanho: 1.5 KiB

Depois

Largura:  |  Altura:  |  Tamanho: 1.5 KiB

+3 -4
Ver Arquivo
@@ -80,8 +80,7 @@
type:'POST',
url:'../../',
data:{
program:'test',
unit: true
program:'test'
},
success: function(ret){
document.getElementById('result').innerHTML= ret
@@ -146,7 +145,7 @@
data:{
program:'use',
what:'project',
name:'demo_en'
projectName:'demo_en'
},
success: function(ret){
$.ajax({
@@ -240,7 +239,7 @@
url:'../../',
data:{
program:'generate',
what: 'db'
lobe: 'db'
},
success: function(retQ){
document.getElementById('result').innerHTML= retQ;
Arquivo normal → Arquivo executável
Ver Arquivo
-3
Ver Arquivo
@@ -1,3 +0,0 @@
adicionar ao relatório, a definição detalhada da API, seus
métodos e parâmetros(ja tentando facilitar para a criação
da documentação para os usuarios/contribuidores).
Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
Ver Arquivo
+7
Ver Arquivo
@@ -53,6 +53,13 @@ class En implements l10n{
$this->messages['theosDBQrFailAbort'] = Mind::message("Theos: All the queries will be aborted", '[Fail]', false);
$this->messages['theosDBQrOk'] = Mind::message("Theos: Database created successfuly", '[Ok]', false);
$this->messages['dbDriverNotFound'] = Mind::message("Theos: Database Driver not found", '[Fail]', false);
$this->messages['missingParameter'] = Mind::message("API: Missing argument: %s", '[Fail]', false);
$this->messages['done'] = Mind::message("API: Done\n", '[Ok]', false);
$this->messages['invalidOptionValue'] = Mind::message("API: %s is not a valid option for %s", '[Fail]', false);
$this->messages['runnintPHPUnit'] = "Please wait...running PHPUnit...\n";
$this->messages['phpunitNotFound'] = "You must specify where to find phpUnit classes\n".
"You can configure it on mind3rd/env/mind.ini ini file\n".
"changing the phpunit-src ini property\n";;
$this->messages['http_invalid_requisition'] = <<<MESSAGE
Invalid HTTP requisition.
+7
Ver Arquivo
@@ -61,6 +61,13 @@ class pt implements l10n{
$this->messages['theosDBQrOk'] = Mind::message("Theos: Base de dados gerada com sucesso", '[Ok]', false);
$this->messages['theosDBQrOk'] = Mind::message("Theos: Base de dados gerada com sucesso", '[Ok]', false);
$this->messages['dbDriverNotFound'] = Mind::message("Theos: Database Driver não encontrado", '[Fail]', false);
$this->messages['missingParameter'] = Mind::message("API: Argumento faltando: %s", '[Fail]', false);
$this->messages['done'] = Mind::message("API: Pronto\n", '[Ok]', false);
$this->messages['invalidOptionValue'] = Mind::message("API: %s não é uma opção válida para %s", '[Fail]', false);
$this->messages['runnintPHPUnit'] = "Aguarde...executando testes unitários...\n";
$this->messages['phpunitNotFound'] = "Especifique onde encontram-se as classes do PHPUnit\n".
"Você pode configurar isto em mind3rd/env/mind.ini ini file\n".
"alterando a propriedade phpunit-src\n";
$this->messages['http_invalid_requisition'] = <<<MESSAGE
Requisição HTTP inválida.
Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
+4 -9
Ver Arquivo
@@ -43,15 +43,10 @@ class db extends \Lobe\Neuron implements \neuron{
foreach($qrs['createTable'] as $tbName=>$qrObject)
{
//foreach($qrType as $qr)
//{
//print_r($qr);
if(!$dealer->createTable($qrObject))
{
return false;
}
//}
if(!$dealer->createTable($qrObject))
{
return false;
}
}
$this->dbal->commit();
\Mind::write('theosDBQrOk');
Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
Ver Arquivo
+82 -5
Ver Arquivo
@@ -18,15 +18,16 @@ class MindCommand extends Symfony\Component\Console\Command\Command
private $requiredOptions = Array();
private $optionalOptions = Array();
private $commandFlags = Array();
public $answers = Array();
public function init()
{
//$this->configure();
parent::__construct();
}
public function configure()
{
$this->setDefinition(Array());
$this->setName($this->commandName);
$definition= Array();
@@ -39,6 +40,78 @@ class MindCommand extends Symfony\Component\Console\Command\Command
$this->setDefinition($definition);
}
public function prompt($name, $question, $mode=false)
{
GLOBAL $_REQ;
$secret= false;
$options= false;
if($mode)
{
if(is_array($mode))
{
$options= $mode;
}else
$secret= true;
}
$answer= null;
if($_REQ['env'] !='http')
{
do
{
echo $question."\n";
if($options)
{
echo "(";
$optionLegend= Array();
foreach($options as $optVal=>$optLabel)
{
$optionLegend[]= $optVal."=".$optLabel;
}
echo trim(implode(" |", $optionLegend));
echo ")\n";
}
if(!$secret)
{
$fp = fopen('php://stdin', 'r');
$answer = trim(fgets($fp, 1024));
if($options &&
!in_array(strtolower($answer),
array_map('strtolower', array_keys($options))))
{
Mind::write('invalidOptionValue', true, $answer, $name);
$answer= false;
}
}else{
$answer= $this->readPassword('*');
}
}while(!$answer);
}else{
if(isset($_POST[$name]))
{
$answer= $_POST[$name];
if($options &&
!in_array(strtolower($answer),
array_map('strtolower', $options)))
{
Mind::write('invalidOptionValue', true, $answer, $name);
$answer= false;
}
}
if(!$answer)
{
Mind::write('missingParameter', true, $name);
exit;
}
}
$this->answers[$name]= trim($answer);
return $this->answers[$name];
}
public function addRequiredArgument($argName, $agDescription='')
{
$this->requiredArguments[]= new InputArgument($argName,
@@ -75,9 +148,9 @@ class MindCommand extends Symfony\Component\Console\Command\Command
public function addFlag($name, $shortCut=null, $description='')
{
$this->commandFlags[]= new InputOption($name,
$shortCut,
InputOption::PARAMETER_NONE,
$description);
$shortCut,
InputOption::PARAMETER_NONE,
$description);
return $this;
}
@@ -204,6 +277,10 @@ class MindCommand extends Symfony\Component\Console\Command\Command
{
$this->$k= $arg;
}
foreach($input->getOptions() as $k=>$opt)
{
$this->$k= $opt;
}
$this->runAction();
}
Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
+5
Ver Arquivo
@@ -12,6 +12,11 @@ namespace theos;
*/
final class ProjectFileManager {
public static function getLobesDir()
{
return _MINDSRC_."/mind3rd/API/Lobe/";
}
private static function filterURI($uri, $allowSlashes=true)
{
$uri= \urlencode(\utf8_encode($uri));
Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
Ver Arquivo
Arquivo normal → Arquivo executável
Ver Arquivo
+11 -38
Ver Arquivo
@@ -15,48 +15,25 @@
private $nameSpace= false;
public $autoCommit= false;
public function configure()
public function __construct()
{
$this->setName('analyze')
$this->setCommandName('analyze')
->setDescription('Analyze the the code for your application')
->setRestrict(true)
->setDefinition(Array(
new InputArgument('namespace', InputArgument::OPTIONAL, 'Analyze an specific namespace'),
new InputOption('commit', false, InputOption::PARAMETER_NONE, "Commit the result after analisys")
))
->setAction('action')
->setHelp(<<<EOT
This program will analyze your code, typed on your application directory, on all the files .mnd starting for the main.mnd
You may have as many files as you want, each of then will be treated as namespaces and will be analyzed too,
unless you have sent an specific namespace to parse, as argument
EOT
);
}
public function execute(Console\Input\InputInterface $input,
Console\Output\OutputInterface $output)
{
if(!parent::execute($input, $output))
return false;
$this->nameSpace= $input->getArgument('namespace');
$this->autoCommit= $input->getOption('commit');
Mind::write('thinking');
$this->runAction();
);
$this->addOptionalArgument('namespace', 'Analyze an specific namespace');
$this->addFlag('commit', false, "Commit the result after analisys");
$this->init();
}
public function HTTPExecute()
{
GLOBAL $_REQ;
if(!parent::HTTPExecute())
return false;
if(isset($_REQ['data']['namespace']))
$this->nameSpace= $_REQ['data']['namespace'];
if(isset($_REQ['data']['commit']))
{
$this->autoCommit= $_REQ['data']['commit'];
}
$this->runAction();
}
private function action()
public function action()
{
if(!isset($_SESSION['currentProject']))
{
@@ -64,14 +41,10 @@ EOT
Mind::write('currentProjectRequiredTip');
return false;
}
Mind::write('thinking');
MindProject::analyze($this->autoCommit? true: false);
//Mind::write('done');
return $this;
}
public function runAction()
{
$ret= $this->action();
parent::runAction();
return $ret;
}
}
+34 -70
Ver Arquivo
@@ -12,75 +12,27 @@
*/
class Auth extends MindCommand implements program
{
public function configure()
{
$this->setName('auth')
->setDescription('Autenticate a user')
->setRestrict(false)
->setDefinition(Array(
new InputArgument('login', InputArgument::REQUIRED, 'Login to access'),
new InputArgument('pwd', InputArgument::OPTIONAL, 'The user password')
))
->setHelp(<<<EOT
Sets the user with a password.
It is required to autenticate, to run most of the commands
EOT
);
}
public function execute(Console\Input\InputInterface $input,
Console\Output\OutputInterface $output)
{
if(!parent::execute($input, $output))
return false;
if(!$pw= $input->getArgument('pwd'))
{
Mind::write('passwordRequired', true);
$pw= Mind::readPassword(true);
}
$this->login= $input->getArgument('login');
$this->pwd= $pw;
if($this->runAction())
Mind::write('autenticated', true, $input->getArgument('login'));
}
public function HTTPExecute()
{
if(!parent::HTTPExecute())
return false;
GLOBAL $_REQ;
if(!isset($_REQ['data']))
{
Mind::write('loginRequired');
return false;
}elseif(!isset($_REQ['data']['pwd']) || !isset($_REQ['data']['login']))
{
Mind::write('loginRequired');
return false;
}
$this->pwd= $_REQ['data']['pwd'];
$this->login= $_REQ['data']['pwd'];
if($this->runAction())
Mind::write('autenticated', true, $_REQ['data']['login']);
}
private function action()
public $login= null;
public $pwd= null;
public function action()
{
if(!$this->pwd)
$this->pwd= $this->prompt('pwd',
Mind::write('passwordRequired', false),
true);
if($db = new SQLite3(_MINDSRC_.'/mind3rd/SQLite/mind'))
{
$result= $db->query("SELECT * FROM user where login='".$this->login.
"' AND pwd='".sha1($this->pwd)."' AND status= 'A'");
$row= $result->fetchArray();
/*while()
{
$row = $result->current();*/
$_SESSION['auth']= JSON_encode($row);
$_SESSION['pk_user']= $row['pk_user'];
$_SESSION['status']= $row['status'];
$_SESSION['login']= $row['login'];
/*break;
}*/
$_SESSION['auth']= JSON_encode($row);
$_SESSION['pk_user']= $row['pk_user'];
$_SESSION['status']= $row['status'];
$_SESSION['login']= $row['login'];
if(!$row)
{
Mind::write('auth_fail', true);
@@ -89,13 +41,25 @@ EOT
}else{
die('Database not found!');
}
Mind::write('autenticated', true, $this->login);
return $this;
}
public function runAction()
{
$ret= $this->action();
parent::runAction();
return $ret;
}
public function __construct()
{
$this->setCommandName('auth')
->setDescription('Autenticate a user')
->setRestrict(false)
->setAction('action')
->setHelp(<<<EOT
Sets the user with a password.
It is required to autenticate, to run most of the commands
EOT
);
$this->addRequiredArgument('login', 'Login to access');
$this->addOptionalArgument('pwd', 'The password may optionaly be passed');
$this->init();
}
}
+6 -20
Ver Arquivo
@@ -5,34 +5,20 @@
class Clear extends MindCommand implements program
{
public function configure()
public function __construct()
{
$this->setName('clear')
$this->setCommandName('clear')
->setDescription('Clears the console')
->setDefinition(array())
->setRestrict(false)
->setAction('action')
->setHelp(<<<EOT
Clears the console
EOT
);
$this->init();
}
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
public function action()
{
system('clear');
}
public function HTTPExecute()
{
}
private function action()
{
return $this;
}
public function runAction()
{
$ret= $this->action();
parent::runAction();
return $ret;
}
}
+5 -27
Ver Arquivo
@@ -15,35 +15,20 @@
private $nameSpace= false;
public $autoCommit= false;
public function configure()
public function __construct()
{
$this->setName('commit')
$this->setCommandName('commit')
->setDescription('Commits the analyzed content to a new version')
->setRestrict(true)
->setAction('action')
->setHelp(<<<EOT
This command will increase the current version and also will persist the currently analyzed structure into the system's knowledge base.
EOT
);
}
public function execute(Console\Input\InputInterface $input,
Console\Output\OutputInterface $output)
{
if(!parent::execute($input, $output))
return false;
Mind::write('thinking');
$this->runAction();
$this->init();
}
public function HTTPExecute()
{
GLOBAL $_REQ;
if(!parent::HTTPExecute())
return false;
$this->runAction();
}
private function action()
public function action()
{
if(!isset($_SESSION['currentProject']))
{
@@ -54,11 +39,4 @@ EOT
MindProject::analyze(true, false);
return $this;
}
public function runAction()
{
$ret= $this->action();
parent::runAction();
return $ret;
}
}
+28 -79
Ver Arquivo
@@ -18,81 +18,31 @@
class Create extends MindCommand implements program
{
public $what= null;
public $argname= false;
public $argName= false;
public $info= "";
private $userType= null;
public function configure()
public function __construct()
{
$this->setName('create')
$this->setCommandName('create')
->setDescription('Create structures, such as project or user')
->setRestrict(true)
->setDefinition(Array(
new InputArgument('what', InputArgument::REQUIRED, 'What to create'),
new InputArgument('name', InputArgument::REQUIRED, 'The refered name'),
new InputOption('info', '-i', InputOption::PARAMETER_OPTIONAL, 'Add extra information about the project')
))
->setAction('action')
->setHelp(<<<EOT
You can create a new project by typing "create project name"
You can create your users typing "create user name" and then, adding the user to any specific group.
You need to be a super user to perform these actions
EOT
);
$this->addRequiredArgument('what', 'What to create');
$this->addRequiredArgument('argName', 'The refered name');
$this->addOptionalOption('into', '-i', 'Add extra information about what is being created');
$this->init();
}
public function execute(Console\Input\InputInterface $input,
Console\Output\OutputInterface $output)
{
if(!parent::execute($input, $output))
return false;
$this->what= $input->getArgument('what');
$this->argName= $input->getArgument('name');
if($this->what == 'user')
{
$this->info= $input->getOption('info');
echo "login: ";
$this->login= trim(fgets(fopen("php://stdin", "r")));
echo "pwd: ";
$this->pwd= Mind::readPassword(true);
echo "\n";
while($this->userType!='N' && $this->userType!='A')
{
echo "Type (use A for admin, or N for normal): ";
$this->userType= strtoupper(trim(fgets(fopen("php://stdin", "r"))));
}
}
$this->runAction();
}
public function HTTPExecute()
{
if(!parent::HTTPExecute())
{
return false;
}
$this->what= $_REQ['data']['what'];
$this->argName= $_REQ['data']['name'];
if(isset($_REQ['data']['info']))
$this->info= $_REQ['data']['info'];
if($this->what == 'user')
{
if(!isset($_REQ['data']['login'])
||
!isset($_REQ['data']['pwd'])
||
!isset($_REQ['data']['userType']))
{
return false;
}
$this->login= $_REQ['data']['login'];
$this->pwd= $_REQ['data']['pwd'];
$this->userType= $_REQ['data']['userType'];
}
$this->runAction();
}
private function action()
public function action()
{
GLOBAL $_MIND;
switch($this->what)
@@ -115,10 +65,6 @@ EOT
return false;
}
Mind::copyDir(Mind::$modelsDir.'mind/', $this->projectfile);
chmod($this->projectfile, 0777);
$db= new MindDB();
$qr_newProj= "INSERT into project
(
@@ -147,7 +93,6 @@ EOT
)";
$db->execute($qr_userProj);
//Mind::$currentProject[''];
$iniSource= Mind::$projectsDir.$this->argName.'/mind.ini';
$cP= $_MIND->defaults;
@@ -179,6 +124,9 @@ EOT
$db->execute($qr_vsProj);
$db->execute("COMMIT");
Mind::copyDir(Mind::$modelsDir.'mind/', $this->projectfile);
chmod($this->projectfile, 0777);
Mind::write('projectCreated', true, $this->argName);
$ini= file_get_contents($iniSource);
@@ -195,14 +143,19 @@ EOT
$this->argName.
'/mind.ini',
$ini);
Mind::openProject(Array('pk_project'=>$key,
'name'=>$this->argName));
echo "\n";
break;
case 'user':
$db= new MindDB();
$this->prompt('name', "What is the new user's name?");
$this->prompt('pwd', "What will be the password?", true);
$this->prompt('type',
"\nWill this user be an administrator?",
Array('Y'=>'Yes',
'N'=>'No'));
$qr_newUser= "INSERT into user
(
name,
@@ -213,11 +166,14 @@ EOT
)
values
(
'".$this->answers['name']."',
'".addslashes($this->argName)."',
'".$this->login."',
'".sha1($this->pwd)."',
'".sha1($this->answers['pwd'])."',
'A',
'".$this->userType."'
'".(strtoupper(
substr($this->answers['type'],
0,
1))=='Y'? 'A': 'N')."'
)";
$db->execute($qr_newUser);
Mind::write('userCreated', true, $this->argName);
@@ -229,11 +185,4 @@ EOT
break;
}
}
public function runAction()
{
$ret= $this->action();
parent::runAction();
return $ret;
}
}
Arquivo normal → Arquivo executável
+33 -51
Ver Arquivo
@@ -12,58 +12,46 @@
*/
class Generate extends MindCommand implements program
{
public $what;
public $lobe;
public $param;
public $detail;
public $optional;
public $extra;
public function configure()
public function __construct()
{
$this->setName('generate')
->setDescription('Commits the analyzed content to a new version')
$dir= \theos\ProjectFileManager::getLobesDir();
$d = dir($dir);
$options= Array();
while (false !== ($entry = $d->read())) {
if(is_dir($dir.$entry) && substr($entry, 0, 1) != '.')
$options[]= " >".$entry."\n";
}
$d->close();
$help= <<<EOT
will generate an output.
This program uses one(or more) of the Lobe classes to generate different
data, structure or output.
EOT;
$help.= "\n Currently installed Lobes:\n".implode("", $options);
$this->setCommandName('generate')
->setDescription('Generates different outputs')
->setRestrict(true)
->setHelp(<<<EOT
This command will increase the current version and also will persist the currently analyzed structure into the system's knowledge base.
EOT
)
->setDefinition(Array(
new InputArgument('what', InputArgument::REQUIRED, 'What to create'),
new InputArgument('param', InputArgument::OPTIONAL, 'A param for that command'),
new InputArgument('detail', InputArgument::OPTIONAL, 'A detail for that command'),
new InputArgument('optional', InputArgument::OPTIONAL, 'An optional argument'),
new InputArgument('extra', InputArgument::OPTIONAL, 'Extra data to pass'),
));
}
public function execute(Console\Input\InputInterface $input,
Console\Output\OutputInterface $output)
{
if(!parent::execute($input, $output))
return false;
$this->what= $input->getArgument('what');
$this->param= $input->getArgument('param');
$this->detail= $input->getArgument('detail');
$this->optional= $input->getArgument('optional');
$this->extra= $input->getArgument('extra');
Mind::write('thinking');
$this->runAction();
->setAction('action')
->setHelp($help);
$this->addRequiredArgument('lobe', 'Lobe to be used');
$this->addOptionalArgument('param', 'A param for that command');
$this->addOptionalArgument('detail', 'A detail for that command');
$this->addOptionalArgument('optional', 'An optional argument');
$this->addOptionalArgument('extra', 'Extra data to be passed');
$this->init();
}
public function HTTPExecute()
{
GLOBAL $_REQ;
if(!parent::HTTPExecute())
return false;
$this->what = $_REQ['data']['what'];
$this->param = (isset($_REQ['data']['param']))? $_REQ['data']['param']: false;
$this->detail = (isset($_REQ['data']['detail']))? $_REQ['data']['detail']: false;
$this->optional= (isset($_REQ['data']['optional']))? $_REQ['data']['optional']: false;
$this->extra = (isset($_REQ['data']['extra']))? $_REQ['data']['extra']: false;
$this->runAction();
}
private function action()
public function action()
{
if(!isset($_SESSION['currentProject']))
{
@@ -71,8 +59,9 @@ EOT
Mind::write('currentProjectRequiredTip');
return false;
}
Mind::write('thinking');
if($exec= Mind::$gosh->generate(Array(
$this->what,
$this->lobe,
$this->param,
$this->detail,
$this->optional,
@@ -81,11 +70,4 @@ EOT
return false;
return $this;
}
public function runAction()
{
$ret= $this->action();
parent::runAction();
return $ret;
}
}
+5 -24
Ver Arquivo
@@ -10,43 +10,24 @@
*/
class Info extends MindCommand implements program
{
public function configure()
public function __construct()
{
$this
->setName('info')
->setCommandName('info')
->setDescription('Performs some tests on theWebMind')
->setRestrict(true)
->setDefinition(array())
->setAction('action')
->setHelp(<<<EOT
Executes specific tests and report their results, about the system itself
EOT
);
}
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
if(!parent::execute($input, $output))
return false;
$this->runAction();
$this->init();
}
public function HTTPExecute()
{
$this->runAction();
}
private function action()
public function action()
{
GLOBAL $_MIND;
if(!parent::verifyCredentials())
return false;
print_r($_MIND->about);
return $this;
}
public function runAction()
{
$ret= $this->action();
parent::runAction();
return $ret;
}
}
+8 -22
Ver Arquivo
@@ -5,38 +5,24 @@
class Quit extends MindCommand implements program
{
public function configure()
public function __construct()
{
$this->setName('exit')
$this->setCommandName('exit')
->setDescription('Finishes the application')
->setDefinition(Array())
->setAction('action')
->setRestrict(false)
->setFileName('Quit')
->setHelp(<<<EOT
Finishes the application, leaving the console;
EOT
);
}
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
$this->runAction();
exit;
$this->init();
}
public function HTTPExecute()
public function action()
{
$this->runAction();
}
private function action()
{
session_destroy();
@session_destroy();
Mind::write('bye');
return $this;
}
public function runAction()
{
$ret= $this->action();
return $ret;
exit;
}
}
+29 -79
Ver Arquivo
@@ -8,94 +8,48 @@
class RunTest extends MindCommand implements program
{
public function configure()
public $unit=false;
public function __construct()
{
$this
->setName('test')
->setDescription('Performs some tests on theWebMind')
->setRestrict(false)
->setDefinition(Array(
new InputOption('unit', '-u', InputOption::PARAMETER_NONE, 'Execute unit tests, also')
))
->setFileName('RunTest')
->setHelp(<<<EOT
Executes specific tests and report their results, about the system itself
$this->setCommandName('test')
->setDescription('Performs some tests on theWebMind')
->setRestrict(false)
->setAction('action')
->setFileName('RunTest')
->setHelp(<<<EOT
Executes specific tests and report their results, about the system itself
EOT
);
$this->addFlag('unit', '-u', 'Also execute unit tests');
$this->init();
}
private function action()
public function action()
{
GLOBAL $_MIND;
ob_start();
$this->runStep1();
ob_flush();
$this->runStep2();
ob_flush();
$this->runStep3();
if($this->unitTestsAlso)
ob_flush();
if($this->unit)
{
if(file_exists(_MINDSRC_."/Tests/bundle.list"))
{
if(!isset($_MIND->conf['phpunit-src']))
{
// TODO: put it into speaker classes, to use l10n messages
echo " You must specify where to find phpUnit classes\n";
echo " You can configure it on mind3rd/env/mind.ini ini file\n";
echo " changing the phpunit-src ini property\n";
return false;
}
// TODO: it doesn't work yet
/*
$unitTestsFolder= _MINDSRC_."/Tests/";
$unitTestsList= file_get_contents($unitTestsFolder."bundle.list");
$unitTestsList= explode("\n", $unitTestsList);
foreach($unitTestsList as $unitTests)
{
$unitTests= explode(' ', $unitTests);
echo "Applying Unit tests to ".$unitTests[1]."\n";
//include_once $unitTestsFolder.$unitTests[0];
echo shell_exec("phpunit ".$unitTestsFolder.$unitTests[0]);
break;
}
*/
}else
{
// TODO: send it to the speaker
echo "[Error] Unit Tests not fount in [root]/Tests\n";
return false;
}
if(!isset($_MIND->conf['phpunit-src']))
{
\Mind::write('phpunitNotFound');
return false;
}
\Mind::write('runnintPHPUnit');
ob_flush();
echo shell_exec($_MIND->conf['phpunit-src']." "._MINDSRC_."/Tests/");
}
}
public function runAction()
{
$ret= $this->action();
parent::runAction();
return $ret;
}
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
if(!parent::execute($input, $output))
return false;
$this->unitTestsAlso= $input->getOption('unit')? true: false;
return $this->runAction();
}
public function HTTPExecute()
{
GLOBAL $_REQ;
if(!parent::HTTPExecute())
return false;
$this->unitTestsAlso= (isset($_REQ['data'])
&&
isset($_REQ['data']['unit']))?
true: false;
return $this->runAction();
}
private function runStep1()
{
@@ -122,8 +76,4 @@ EOT
$stat= '[OK]';
Mind::message('Read & Write permissions', $stat);
}
public function __construct($name = null) {
parent::__construct($name);
}
}
+13 -47
Ver Arquivo
@@ -12,64 +12,30 @@
*/
class SetUse extends MindCommand implements program
{
private $argName= false;
private $what= false;
public $projectName= false;
public function configure()
public function __construct()
{
$this->setName('use')
$this->setCommandName('use')
->setDescription('Opens the project, or specifies any personal option')
->setRestrict(true)
->setaction('action')
->setFileName('SetUse')
->setDefinition(Array(
new InputArgument('what', InputArgument::REQUIRED, 'What to use, from now on'),
new InputArgument('name', InputArgument::REQUIRED, 'specify what you want to use/open')
))
->setHelp(<<<EOT
You can use this command to start using a different language or project, for example
EOT
);
$this->addRequiredArgument('projectName', 'Specify the project name, you want to use/open');
$this->init();
}
public function execute(Console\Input\InputInterface $input,
Console\Output\OutputInterface $output)
public function action()
{
if(!parent::execute($input, $output))
return false;
$this->what= $input->getArgument('what');
$this->argName= $input->getArgument('name');
$this->runAction();
}
public function HTTPExecute()
{
GLOBAL $_REQ;
if(!parent::HTTPExecute())
return false;
if(isset($_REQ['data']['what']) && isset($_REQ['data']['name']))
{
$this->argName= $_REQ['data']['name'];
$this->what= $_REQ['data']['what'];
}
$this->runAction();
}
private function action()
{
switch($this->what)
{
case 'project':
if(!$projectData= Mind::hasProject($this->argName))
return false;
Mind::openProject($projectData);
break;
}
if(!$projectData= Mind::hasProject($this->projectName))
return false;
Mind::openProject($projectData);
return $this;
}
public function runAction()
{
$ret= $this->action();
parent::runAction();
return $ret;
}
}
+16 -48
Ver Arquivo
@@ -5,56 +5,32 @@
class Show extends MindCommand implements program
{
private $whatToShow= null;
public $what= null;
public $detailed= false;
public $extra= '';
public function configure()
public function __construct()
{
$this->setName('show')
$this->setCommandName('show')
->setDescription('Show many different kind of data')
->setDefinition(array(
new InputArgument('what', InputArgument::REQUIRED, 'What to show'),
new InputOption('detailed', '-d', InputOption::PARAMETER_NONE, 'Show detailed data'),
new InputArgument('extra', InputArgument::OPTIONAL, 'Extra information to be used'),
))
->setAction('action')
->setHelp(<<<EOT
You can use this command to see lists or details of a sort of components
EOT
);
}
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
if(!parent::execute($input, $output))
return false;
$this->whatToShow= $input->getArgument('what');
//echo $input->getOption('detailed')."\n";
$this->detailed= $input->getOption('detailed');
$this->extra= $input->getArgument('extra');
$this->runAction();
$this->addRequiredArgument('what', 'What to how');
$this->addOptionalArgument('extra', 'Extra information to be used');
$this->addFlag('detailed', '-d', 'Show detailed data');
$this->init();
}
public function HTTPExecute()
{
if(!parent::HTTPExecute())
return false;
GLOBAL $_REQ;
$this->whatToShow= $_REQ['data']['what'];
if(isset($_REQ['data']['detailed']) && $_REQ['data']['detailed'])
$this->detailed= 1;
else
$this->detailed= false;
if(isset($_REQ['data']['extra']))
$this->extra= $_REQ['data']['extra'];
else
$this->extra= false;
$this->runAction();
}
private function action()
public function action()
{
GLOBAL $_REQ;
GLOBAL $_MIND;
switch($this->whatToShow)
switch($this->what)
{
case 'projects':
$projs= $this->loadProjectList();
@@ -153,20 +129,12 @@ EOT
}
break;
default:
Mind::write('invalidOption', true, $this->whatToShow);
Mind::write('invalidOption', true, $this->what);
return false;
break;
}
return $this;
}
public function runAction()
{
$ret= $this->action();
parent::runAction();
return $ret;
}
private function loadProjectList()
{
$db= new MindDB();
@@ -222,4 +190,4 @@ EOT
echo "\n";
}
}
}
}
-53
Ver Arquivo
@@ -1,53 +0,0 @@
<?php
use Symfony\Component\Console\Input\InputArgument,
Symfony\Component\Console\Input\InputOption,
Symfony\Component\Console;
class CommandName extends MindCommand implements program
{
public function configure()
{
$this->setName('Mind:commandName')
->setDescription('CommandDescription')
->setDefinition(array(
new InputArgument('arg1', InputArgument::REQUIRED, 'ArgDescription.'),
new InputOption(
'Option', null, InputOption::PARAMETER_REQUIRED,
'Description of the option',
'object'
),
new InputOption('detailed', '-d', InputOption::PARAMETER_NONE, ''),
new InputOption(
'first-result', null, InputOption::PARAMETER_REQUIRED,
'The first result in the result set.'
)
))
->setHelp(<<<EOT
Executes arbitrary DQL directly from the command line.
EOT
);
}
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
$this->runAction();
}
public function HTTPExecute()
{
$this->runAction();
}
private function action()
{
return $this;
}
public function runAction()
{
$ret= $this->action();
// this is used to run the plugins set to be executed
// AFTER the execution of the current program
parent::runAction();
return $ret;
}
}
Arquivo normal → Arquivo executável
+16 -39
Ver Arquivo
@@ -10,54 +10,38 @@
*/
class DQB extends MindCommand implements program
{
public function configure()
public $query=null;
public $table=null;
public function __construct()
{
$this
->setName('dqb')
->setCommandName('dqb')
->setDescription('Performs some tests on theWebMind')
->setRestrict(true)
->setDefinition(array(
new InputArgument('query',
InputArgument::REQUIRED,
'Options: create, drop, alter, insert, delete, select and update'),
new InputArgument('table',
InputArgument::REQUIRED,
"Which table will have its query built. Use * to see them all."),
))
->setAction('action')
->setHelp(<<<EOT
This program will create the needed query to the selected database.
Notice that it will NOT execute then, only return them as a string.
EOT
);
}
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
if(!parent::execute($input, $output))
return false;
$this->query= $input->getArgument('query');
$this->table= $input->getArgument('table');
$this->runAction();
//$this->addRequiredArgument('query', 'Options: create, drop, alter, insert, delete, select and update');
$this->addRequiredArgument('table', 'Which table will have its query built. Use * to see them all.');
$this->init();
}
public function HTTPExecute()
{
GLOBAL $_REQ;
if(!parent::HTTPExecute())
return false;
if(isset($_REQ['data']['query']) && isset($_REQ['data']['table']))
{
$this->query= $_REQ['data']['query'];
$this->table= $_REQ['data']['table'];
}
$this->runAction();
}
private function action()
public function action()
{
GLOBAL $_MIND, $_REQ;
if(!parent::verifyCredentials())
return false;
// for now, only the create has been developed
// even if the following options are already described there are not
// plans to build them so soon.
$this->query= 'c';
switch($this->query)
{
case 'create':
@@ -90,11 +74,4 @@ EOT
echo $qrs;
return $this;
}
public function runAction()
{
$ret= $this->action();
parent::runAction();
return $ret;
}
}
Arquivo normal → Arquivo executável
+8 -1
Ver Arquivo
@@ -23,6 +23,13 @@
// in this example, we will simply show a message using one argument
echo " This command has just been executed!\n";
echo " With argument: ".$this->firstArgument."\n\n";
$this->prompt('name', "What's your name?");
echo "Hello ".$this->answers['name']."\n";
$this->prompt('pwd', 'Say a magic word!', true);
$this->prompt('genre', "\nwhat is your genre?",
Array('F'=>'Female',
'M'=>'Male'));
echo "\nOW, ok :)\n\n";
}
public function __construct()
@@ -45,7 +52,7 @@
->setDescription("This is a model command, only")
->setRestrict(false)
->setHelp("A longer text, explaining the command")
->setAction('executableFunction');
->setAction('executableFunction'); // in this case, the method MUST be public
*/
/**
Arquivo normal → Arquivo executável
Ver Arquivo