From 756b4f7c6b0492ea51e02e0419839d28fadccecb Mon Sep 17 00:00:00 2001 From: Felipe Date: Sat, 28 May 2011 18:49:06 -0300 Subject: [PATCH] Added annotations, messages in L10N. Changes made to modeloTeste(as example for those who may want to create their own programs). Startging works in 'insall' program --- mind3rd/API/L10N/en.php | 1 + mind3rd/API/L10N/pt.php | 1 + mind3rd/API/classes/Mind.php | 14 ++++- mind3rd/API/classes/MindCommand.php | 18 +++++- mind3rd/API/classes/MindUser.php | 23 +++++++ mind3rd/API/classes/scientia/Darwin.php | 33 +++++++++- mind3rd/API/classes/scientia/Decision.php | 23 +++++++ mind3rd/API/classes/scientia/Doubt.php | 23 +++++++ mind3rd/API/classes/scientia/Tip.php | 23 +++++++ mind3rd/API/programs/Auth.php | 1 + mind3rd/API/programs/Install.php | 77 +++++++++++++++++++++++ mind3rd/API/programs/modeloTeste.php | 2 +- mind3rd/env/about.ini | 9 ++- mind3rd/env/mind.ini | 4 +- mind3rd/env/trusted-sources.list | 2 + 15 files changed, 244 insertions(+), 10 deletions(-) create mode 100644 mind3rd/API/classes/scientia/Decision.php create mode 100644 mind3rd/API/classes/scientia/Doubt.php create mode 100644 mind3rd/API/classes/scientia/Tip.php create mode 100644 mind3rd/API/programs/Install.php create mode 100644 mind3rd/env/trusted-sources.list diff --git a/mind3rd/API/L10N/en.php b/mind3rd/API/L10N/en.php index b705b56..727025d 100755 --- a/mind3rd/API/L10N/en.php +++ b/mind3rd/API/L10N/en.php @@ -58,6 +58,7 @@ class En implements l10n{ $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['mustBeAdmin'] = Mind::message("API: You must be the admin to perform this action", '[Fail]', false); + $this->messages['cannotInstall'] = Mind::message("API: To install a component, you need to change the 'allow_installation' property into mind.ini file, setting it as true", '[Fail]', false); $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";; diff --git a/mind3rd/API/L10N/pt.php b/mind3rd/API/L10N/pt.php index 5d7c6d0..df380fa 100755 --- a/mind3rd/API/L10N/pt.php +++ b/mind3rd/API/L10N/pt.php @@ -66,6 +66,7 @@ class pt implements l10n{ $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['mustBeAdmin'] = Mind::message("API: Você precisa ser o administrador para executar esta instrução", '[Fail]', false); + $this->messages['cannotInstall'] = Mind::message("API: Para instalar um componente, será preciso alterar a propriedade 'allow_installation' no arquivo mind.ini para true", '[Fail]', false); $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"; diff --git a/mind3rd/API/classes/Mind.php b/mind3rd/API/classes/Mind.php index 20b4e17..64616d9 100755 --- a/mind3rd/API/classes/Mind.php +++ b/mind3rd/API/classes/Mind.php @@ -34,6 +34,14 @@ public static $originalContent = ""; public static $curLang = 'en'; + public static function &getInstance() + { + GLOBAL $_MIND; + if(!$_MIND) + $_MIND= new Mind(); + return $_MIND; + } + /** * @var Lexer An instance of the Lexer class */ @@ -171,13 +179,11 @@ * false, otherwise * Alias for MindProject::hasProject * - * @global Mind $_MIND * @param String $project * @return boolean */ static function hasProject($project) { - GLOBAL $_MIND; return MindProject::hasProject($project); } @@ -211,6 +217,10 @@ * Constructor */ public function Mind(){ + if(isset($GLOBALS['_MIND'])) + { + return $GLOBALS['_MIND']; + } $path= _MINDSRC_; Mind::$projectsDir= $path.PROJECTS_DIR; Mind::$modelsDir= $path.MODELS_DIR; diff --git a/mind3rd/API/classes/MindCommand.php b/mind3rd/API/classes/MindCommand.php index b960a9b..ef3547f 100755 --- a/mind3rd/API/classes/MindCommand.php +++ b/mind3rd/API/classes/MindCommand.php @@ -24,6 +24,7 @@ class MindCommand extends Symfony\Component\Console\Command\Command private $requiredOptions = Array(); private $optionalOptions = Array(); private $commandFlags = Array(); + private $adminOnly = false; public $answers = Array(); public $commandAction = null; public $commandAvailableOptions = Array(); @@ -301,6 +302,12 @@ class MindCommand extends Symfony\Component\Console\Command\Command return $this; } + public function setAdminAccess() + { + $this->adminOnly= true; + return $this; + } + /** * Sets the command's description. * @param string $description @@ -388,12 +395,19 @@ class MindCommand extends Symfony\Component\Console\Command\Command public function verifyCredentials() { if($this->restrict) - if(!isset($_SESSION['auth'])) + if(!MindUser::isIn()) { Mind::write('not_allowed'); Mind::write('not_allowed_tip'); return false; } + + if($this->adminOnly && !MindUser::isAdmin()) + { + Mind::write('mustBeAdmin'); + return false; + } + return true; } @@ -529,7 +543,7 @@ class MindCommand extends Symfony\Component\Console\Command\Command } } - // yea, I know it looks a bit crazy! + // yeah, I know it looks a bit crazy! if(is_string($this->commandAction)) $this->{$this->commandAction}(); else diff --git a/mind3rd/API/classes/MindUser.php b/mind3rd/API/classes/MindUser.php index d7379d5..979de38 100755 --- a/mind3rd/API/classes/MindUser.php +++ b/mind3rd/API/classes/MindUser.php @@ -47,6 +47,24 @@ class MindUser echo "\n"; } + /** + * Verifies if there is a user autenticated. + * @return boolean + */ + public static function isIn() + { + return isset($_SESSION['pk_user']); + } + + /** + * Retrieves if the currently logged user is an administrator. + * @return boolean + */ + public static function isAdmin() + { + return isset($_SESSION['pk_user']) && $_SESSION['type'] == 'A'; + } + protected static function getDBConn() { if(!self::$dbConn) @@ -54,6 +72,11 @@ class MindUser return self::$dbConn; } + /** + * Retrieves the list of users. + * @param boolean $detailed + * @return mixed + */ public static function listUsers($detailed=false) { $db= self::getDBConn(); diff --git a/mind3rd/API/classes/scientia/Darwin.php b/mind3rd/API/classes/scientia/Darwin.php index 686e03e..bd33c8d 100755 --- a/mind3rd/API/classes/scientia/Darwin.php +++ b/mind3rd/API/classes/scientia/Darwin.php @@ -9,10 +9,39 @@ /** * * @author felipe + * @package scientia */ class Darwin { - public static function addDoubt($context, $type) + + protected $tips = Array(); + protected $decisions = Array(); + protected $doubts = Array(); + + public static function getTips() + { + return self::$tips; + } + public static function getDecisions() + { + return self::$decisions; + } + public static function getDoubts() + { + return self::$doubts; + } + + public static function addTip($tipMessage, $context=false) + { + self::$tips[]= new Tip($tipMessage, $context); + } + + public static function addDecision($decisionMessage, $context=false) + { + self::$decisions[]= new Decision($decisionMessage, $context); + } + + public static function addDoubt($doubtMessage, $context) { - echo "DUVIDAAAA"; + self::$doubts[]= new Doubt($doubtMessage, $context); } } \ No newline at end of file diff --git a/mind3rd/API/classes/scientia/Decision.php b/mind3rd/API/classes/scientia/Decision.php new file mode 100644 index 0000000..546a211 --- /dev/null +++ b/mind3rd/API/classes/scientia/Decision.php @@ -0,0 +1,23 @@ + + * @license licenses/mind3rd.license + */ + namespace scientia; + /** + * + * @author felipe + * @package scientia + */ + class Decision { + + public $context = false; + public $doubtMessage= ""; + + public function __construct($doubtMessage, $context) + { + + } + } \ No newline at end of file diff --git a/mind3rd/API/classes/scientia/Doubt.php b/mind3rd/API/classes/scientia/Doubt.php new file mode 100644 index 0000000..e8dc136 --- /dev/null +++ b/mind3rd/API/classes/scientia/Doubt.php @@ -0,0 +1,23 @@ + + * @license licenses/mind3rd.license + */ + namespace scientia; + /** + * + * @author felipe + * @package scientia + */ + class Doubt { + + public $context = false; + public $doubtMessage= ""; + + public function __construct($doubtMessage, $context) + { + + } + } \ No newline at end of file diff --git a/mind3rd/API/classes/scientia/Tip.php b/mind3rd/API/classes/scientia/Tip.php new file mode 100644 index 0000000..0ce3717 --- /dev/null +++ b/mind3rd/API/classes/scientia/Tip.php @@ -0,0 +1,23 @@ + + * @license licenses/mind3rd.license + */ + namespace scientia; + /** + * + * @author felipe + * @package scientia + */ + class Tip { + + public $context = false; + public $doubtMessage= ""; + + public function __construct($doubtMessage, $context) + { + + } + } \ No newline at end of file diff --git a/mind3rd/API/programs/Auth.php b/mind3rd/API/programs/Auth.php index 62c66be..37fcae9 100755 --- a/mind3rd/API/programs/Auth.php +++ b/mind3rd/API/programs/Auth.php @@ -38,6 +38,7 @@ $_SESSION['pk_user']= $row['pk_user']; $_SESSION['status']= $row['status']; $_SESSION['login']= $row['login']; + $_SESSION['type']= $row['type']; if(!$row) { diff --git a/mind3rd/API/programs/Install.php b/mind3rd/API/programs/Install.php new file mode 100644 index 0000000..0b4ac84 --- /dev/null +++ b/mind3rd/API/programs/Install.php @@ -0,0 +1,77 @@ + + * @license licenses/mind3rd.license + */ + use Symfony\Component\Console\Input\InputArgument, + Symfony\Component\Console\Input\InputOption, + Symfony\Component\Console; + + /** + * This program will be able to install components to the application. + * These components may be a new L10N idiom, a new language to be interpreted, a new program, a new DBMS, a new Plugin or a new Lobe. + * + * @author Felipe Nascimento de Moura + */ + class Install extends MindCommand implements program + { + /* + * The properties you will use as argument MUST be declared, and public + */ + public $firstArgument= ''; + + protected function installIt() + { + $list= explode("\n", + file_get_contents(_MINDSRC_. + '/mind3rd/env/trusted-sources.list')); + foreach($list as $source) + { + $src= $source.$this->what."/".$this->which_one.".xml"; + echo $src."\n"; + if(file_exists($src)) + { + echo file_get_contents($src); + return true; + } + } + echo "Thing not found!"; + return false; + } + + public function executableFunction() + { + if(Mind::getInstance()->conf['allow_installation']) + { + return $this->installIt(); + } + return Mind::write('cannotInstall'); + } + + public function __construct() + { + $this->setCommandName('install') + ->setDescription("This program will be able to install components to the application.") + //->setFileName('modeloTeste') // use this if your class has NOT the same name as its file + ->setRestrict(true) + ->setAdminAccess() + ->setHelp("This program will be able to install components to the application.\nThese components may be a new L10N idiom, a new language to be interpreted, a new program, a new DBMS, a new Plugin or a new Lobe.") + ->setAction('executableFunction'); + + $this->addRequiredArgument('what', + 'what will be installed', + Array('l10n', 'language', 'dbms', 'plugin', 'lobe')); + + $this->addRequiredArgument('which_one', + 'What is te one of it you choosed, you will install?'); + + //$this->addOptionalArgument('secondArgument', 'This is the second and optional argument'); + //$this->addRequiredOption('user', '-u', 'The user who will be passed for any reason', 'root'); + //$this->addOptionalOption('detailed', '-d', 'Should perform its action detailed?', null); + //$this->addFlag('silent', '-s', 'Executes the command quietly'); + + $this->init(); + } + } \ No newline at end of file diff --git a/mind3rd/API/programs/modeloTeste.php b/mind3rd/API/programs/modeloTeste.php index a5c49f3..4d24c1d 100755 --- a/mind3rd/API/programs/modeloTeste.php +++ b/mind3rd/API/programs/modeloTeste.php @@ -76,4 +76,4 @@ // after all the definition, you MUST initiate your program. $this->init(); } - } + } \ No newline at end of file diff --git a/mind3rd/env/about.ini b/mind3rd/env/about.ini index 03582b6..554f66f 100755 --- a/mind3rd/env/about.ini +++ b/mind3rd/env/about.ini @@ -18,15 +18,20 @@ version=3.0.0.1 ; the last date it has been changed date= Jul 6th, 2010 ; here, a list of the authors -; name, +; name,name... authors= Felipe Nascimento de Moura ; some technologies it uses ; PHP -; SQLite +; SQLite3 ; RegExp ; INI files ; shell commands ; HTTP Headers/Rest ; Bootstrap +; MVC +; Factories +; PHPUnit +; XML +; readline(php extension) \ No newline at end of file diff --git a/mind3rd/env/mind.ini b/mind3rd/env/mind.ini index ebee14a..a2aaac5 100755 --- a/mind3rd/env/mind.ini +++ b/mind3rd/env/mind.ini @@ -21,4 +21,6 @@ relations_length= 4 ; should use the entity's name as prefix on merged entities use_prefix_on_merged_entities= true ; how many points should consider an entity worth of mergin or not -merging_amount_pts=2 \ No newline at end of file +merging_amount_pts=2 +; should admin users be able to install components to the structure? +allow_installation=true \ No newline at end of file diff --git a/mind3rd/env/trusted-sources.list b/mind3rd/env/trusted-sources.list new file mode 100644 index 0000000..d6a72a4 --- /dev/null +++ b/mind3rd/env/trusted-sources.list @@ -0,0 +1,2 @@ +http://localhost/theWebMind/extra/ +http://extra.thewebmind.org/ \ No newline at end of file