added console features to interact with HTTP requests

Esse commit está contido em:
Felipe Nascimento de Moura
2011-05-07 16:42:30 -03:00
commit fce9629454
9 arquivos alterados com 284 adições e 37 exclusões
+109 -3
Ver Arquivo
@@ -1,5 +1,4 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<link rel="shortcut icon" href="images/logo.png" />
@@ -50,7 +49,26 @@
<input type='button' value='generate db' onclick="genDB()"/>
<input type='button' value='generate docs' onclick="genDocs()"/>
<input type='button' value='logoff' onclick="logoff()"/>
<pre><div id='result' style='border:solid 1px #777;'></div></pre>
<div style='border:solid 1px #777;
overflow:auto;
color:white;
background-color: black;'
id="scrollingDiv">
<div id='result'
style='border:none;
width:100%;
font-family: Courier New;
white-space:pre;'></div>
<textarea style='width:100%;
margin: 0px;
border: none;
height:120px;
color:white;
font-family: Courier New;
background-color: black;'
id='consoleCommand'
value=""></textarea>
</div>
<input type='button' value='create demo_en project' onclick="createDemo_en()"/>
<input type='button' value='run example' onclick="exampleModel()"/>
<input type='button' value='API Facade tests' onclick="APITest()"/>
@@ -326,5 +344,93 @@
}
});
}
var MindConsole= {
history: [],
current: 0,
add: function(str)
{
if(str=='')
return;
MindConsole.current= MindConsole.history.length;
if(MindConsole.current && MindConsole.history[MindConsole.current-1] == str)
{
return;
}
MindConsole.history.push(str);
MindConsole.current++;
},
back: function(){
if(MindConsole.current == 0)
return false;
MindConsole.current--;
return MindConsole.history[MindConsole.current];
},
next: function(){
if(MindConsole.current == MindConsole.history.length)
return false;
MindConsole.current++;
return MindConsole.history[MindConsole.current];
}
};
$('#consoleCommand').bind('keyup', function(event){
if(event.which == 38) // up
{
var comm= false;
if(comm = MindConsole.back())
this.value= comm;
}
if(event.which == 40) // down
{
var comm= false;
if(comm= MindConsole.next())
this.value= comm;
else{
MindConsole.add(this.value);
this.value= '';
}
}
if(event.which == 13)
{
this.value= this.value.replace(/[\t\n]/g, '');
MindConsole.add(this.value);
if(this.value == 'clear')
{
var el= document.getElementById('result');
var scr= document.getElementById('scrollingDiv');
el.innerHTML= '';
this.value= '';
return;
}
var commandToExecute= this.value;
$.ajax({
type:'POST',
url:'../../',
data:{
program:'eval',
command: commandToExecute
},
success: function(retQ){
var el= document.getElementById('result');
el.innerHTML+= commandToExecute+"\n"+retQ;
//el.scrollIntoView(true);
document.getElementById('scrollingDiv').scrollTop= el.offsetHeight;
}
});
this.value= '';
}
});
function adjust()
{
document.getElementById('scrollingDiv').style.height= ($(document).height() - 100)+"px";
document.getElementById('consoleCommand').focus();
}
$('#scrollingDiv').bind('click', adjust);
$(document).ready(adjust);
$(window).bind('resize', adjust);
</script>
</html>
+17 -16
Ver Arquivo
@@ -15,23 +15,24 @@
*/
class Mind
{
public $about= null;
public $defaults= null;
public $conf= null;
public $about = null;
public $defaults = null;
public $conf = null;
public static $project= null;
public static $autoloadPaths= Array();
public static $currentProject= null;
public static $ref= Array();
public static $projectsDir= '';
public static $pluginList= Array();
public static $l10n= null;
public static $triggers= Array();
public static $modelsDir= "";
public static $langPath= "";
public static $content= "";
public static $originalContent= "";
public static $curLang= 'en';
public static $programs = null;
public static $project = null;
public static $autoloadPaths = Array();
public static $currentProject = null;
public static $ref = Array();
public static $projectsDir = '';
public static $pluginList = Array();
public static $l10n = null;
public static $triggers = Array();
public static $modelsDir = "";
public static $langPath = "";
public static $content = "";
public static $originalContent = "";
public static $curLang = 'en';
/**
* @var Lexer An instance of the Lexer class
+10 -2
Ver Arquivo
@@ -175,6 +175,11 @@ class MindProject extends VersionManager{
else
return Mind::$project;
}
$msg= false;
if($_SESSION['currentProject'] != $p['pk_project'])
$msg= true;
$_SESSION['currentProject']= $p['pk_project'];
$_SESSION['currentProjectName']= $p['name'];
$_SESSION['currentProjectDir']= Mind::$projectsDir.$p['name'];
@@ -196,8 +201,11 @@ class MindProject extends VersionManager{
Mind::$currentProject['version']= $pF->data['version'];
Mind::$currentProject['pk_version']= $pF->data['pk_version'];
Mind::$project= $pF;
Mind::write('projectOpened', true, $p['name']);
if($msg)
{
Mind::write('projectOpened', true, $p['name']);
}
return true;
}
+100
Ver Arquivo
@@ -0,0 +1,100 @@
<?php
/**
* This file is part of TheWebMind 3rd generation.
*
* @author Felipe Nascimento de Moura <felipenmoura@gmail.com>
* @license licenses/mind3rd.license
*/
namespace API;
/**
* This is a facade to help you getting generic data.
* This class offers you a bunch of "shortcuts" to many different data or results.
*
* @author felipe
*/
class Program{
public static function all($full=false)
{
return ($full)? \MIND::$programs : array_keys(\MIND::$programs);
}
public static function getDetails($programName)
{
return \MIND::$programs[strtolower($programName)];
}
public static function getHelp($programName)
{
$help= self::signature($programName)."\n";
$help.= \MIND::$programs[strtolower($programName)]->getHelp();
return $help;
}
public static function getArgs($programName)
{
return \MIND::$programs[strtolower($programName)]->getDefinition();
}
public static function argumentsDescription($programName)
{
$args= \MIND::$programs[strtolower($programName)]->getDefinition();
foreach($args->getArguments() as $arg)
{
}
}
public static function signature($programName, $string=true)
{
$signature= Array($programName);
$def= \MIND::$programs[strtolower($programName)]->getDefinition();
foreach($def->getArguments() as $arg)
{
$signature[]= $arg->getName();
}
$options= Array();
foreach($def->getOptions() as $opt)
{
$options[]= $opt->getName();
}
if(sizeof($options) > 0)
{
if($string)
$signature[]= '[';
$signature= array_merge($signature, $options);
if($string)
$signature[]= ']';
}
return $string? implode(' ', $signature): $signature;
}
public static function execute($programName)
{
if(strpos($programName, ' ') !== false)
{
$args= explode(' ', $programName);
$programName= array_shift($args);
}else{
$args= \func_get_args();
array_shift($args);
}
$realArgs= self::signature($programName, false);
array_shift($realArgs);
$programName= self::getDetails($programName)->getFileName();
$program= new $programName;
foreach($args as $k=>$arg)
{
if($arg == 'help' || $arg=='-h' || $arg=='--help')
{
echo self::getHelp($programName);
return;
}
$program->$realArgs[$k]= $arg;
}
$program->action();
}
}
+29
Ver Arquivo
@@ -0,0 +1,29 @@
<?php
use Symfony\Component\Console\Input\InputArgument,
Symfony\Component\Console\Input\InputOption,
Symfony\Component\Console;
class ConsoleCommand extends MindCommand implements program
{
public function __construct()
{
$this->setCommandName('eval')
->setDescription('Clears the console')
->setRestrict(false)
->setFileName('ConsoleCommand')
->setAction('action')
->setHelp(<<<EOT
Clears the console
EOT
);
//$this->addArgument('command', null, 'The command to be executed');
$this->addRequiredArgument('command', 'The command to be executed');
$this->init();
}
public function action()
{
return \API\Program::execute($this->command);
}
}
+1
Ver Arquivo
@@ -34,6 +34,7 @@ EOT
public function action()
{
GLOBAL $_MIND;
ob_start();
$this->runStep1();
ob_flush();
+1 -1
Ver Arquivo
@@ -27,7 +27,7 @@ EOT
$this->addRequiredArgument('what',
'What to show',
Array('projects',
Array( 'projects',
'users',
'entities',
'relations',
+14 -14
Ver Arquivo
@@ -22,18 +22,18 @@
Mind::$triggers= array_keys($app->getCommands());
try {
$sh= new Symfony\Component\Console\Shell($app);
$sh->run();
}catch(Exception $exc) {
$sh= new Symfony\Component\Console\Shell($app);
$sh->run();
}catch(Exception $exc) {
echo " <[ERROR] It looks like you are not using the readline extension enabled!\n";
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
{
echo " Sorry! The readline extension is not available for windows(!)\n";
echo " So, you will not be able to use the application through command line\n\n";
}
else
echo " Please, follow these instructions to install it: http://goo.gl/UDrEY\n\n";
echo " NOTE: Even without the readline extension, you already can use the\n";
echo " system via HTTP once it does not need the shell towork\n\n";
}
echo " <[ERROR] It looks like you are not using the readline extension enabled!\n";
if (strtoupper(substr(PHP_OS, 0, 3)) == 'WIN')
{
echo " Sorry! The readline extension is not available for windows(!)\n";
echo " So, you will not be able to use the application through command line\n\n";
}
else
echo " Please, follow these instructions to install it: http://goo.gl/UDrEY\n\n";
echo " NOTE: Even without the readline extension, you already can use the\n";
echo " system via HTTP once it does not need the shell to work\n\n";
}
+3 -1
Ver Arquivo
@@ -47,11 +47,13 @@
if(substr($entry, 0, 1) != '.')
{
$entry= str_replace('.php', '', $entry);
$programs[]= new $entry();
$prog= new $entry();
$programs[strtolower($prog->getName())]= $prog;
}
}
$d->close();
$app->addCommands($programs);
\MIND::$programs= $programs;
// starting the application
if($_REQ['env']=='shell')