Added multiple line support to console component(symfony console);

Added 'set project.source' command;
Esse commit está contido em:
Felipe N. Moura
2012-07-01 15:24:44 -03:00
commit a871b2c49d
4 arquivos alterados com 55 adições e 12 exclusões
+28 -10
Ver Arquivo
@@ -23,7 +23,8 @@ class MindProject extends VersionManager{
'database_name', 'database_name',
'database_port', 'database_port',
'database_user', 'database_user',
'database_pwd'); 'database_pwd',
'source');
/** /**
* Uses the QueryFactory to return the sql to create all the database. * Uses the QueryFactory to return the sql to create all the database.
@@ -81,14 +82,18 @@ class MindProject extends VersionManager{
* This method actually changes AND PERSISTS the change to the * This method actually changes AND PERSISTS the change to the
* database. * database.
* *
* To change the source of a project, the user MUST be with the project opened.
* Neither Admin users have access to change a source of a project, without
* loging into it(opening the project).
*
* @param String $attr * @param String $attr
* @param Mixed $value * @param Mixed $value
* @param String $proj * @param String $proj The project or the source file to be chenged
* @return boolean * @return boolean
*/ */
public static function set($attr, $value, $proj=false) public static function set($attr, $value, $proj=false)
{ {
if(\in_array($attr, self::$adminValidAttrs) || $proj){ if(\in_array($attr, self::$adminValidAttrs) || ($proj && $attr != 'source')){
if(!\MindUser::isAdmin()){ if(!\MindUser::isAdmin()){
\Mind::write('mustBeAdmin'); \Mind::write('mustBeAdmin');
return false; return false;
@@ -142,6 +147,7 @@ class MindProject extends VersionManager{
\MindSpeaker::write('permissionDenied', true, $proj); \MindSpeaker::write('permissionDenied', true, $proj);
return false; return false;
} }
$attr= trim($attr); $attr= trim($attr);
if(!\in_array($attr, self::$availableAttrs)){ if(!\in_array($attr, self::$availableAttrs)){
\MindSpeaker::write('invalidCreateParams'); \MindSpeaker::write('invalidCreateParams');
@@ -149,14 +155,26 @@ class MindProject extends VersionManager{
return false; return false;
} }
$iniContent= preg_replace("/".$attr."(( |\t)+)?=.+(\n|$)/", $attr."=".$value."\n", $iniContent); if($attr == 'source'){
try{ $srcs= Mind::$currentProject['sources'];
file_put_contents($iniSource, $iniContent); $source= func_get_arg(2);
\MindProject::reload(); if(!$source)
return true; $source= 'main';
}catch(Excepption $e){ //echo "\n\n".$srcs.'/'.addslashes($source).'.mnd'."\n\n";
\MindSpeaker::write('permissionDenied', true, $proj); if(file_put_contents($srcs.'/'.addslashes($source).'.mnd', $value))
return true;
Mind::write('permissionDenied');
return false; return false;
}else{
$iniContent= preg_replace("/".$attr."(( |\t)+)?=.+(\n|$)/", $attr."=".str_replace('"', '', $value)."\n", $iniContent);
try{
file_put_contents($iniSource, $iniContent);
\MindProject::reload();
return true;
}catch(Excepption $e){
\MindSpeaker::write('permissionDenied', true, $proj);
return false;
}
} }
} }
} }
@@ -68,10 +68,18 @@ class Shell
$command = readline($this->application->getName().' > '); $command = readline($this->application->getName().' > ');
/** changed by felipeNMoura **/ /** changed by felipeNMoura **/
// showing nothing when the user just hits ENTER
if($command == "\n" || $command == ""){ if($command == "\n" || $command == ""){
$this->output->write(""); $this->output->write("");
continue; continue;
} }
// enabling multiple lines when quoted
preg_filter('/\"/', '"', $command, -1, $count);
while($count%2>0){ // unended quoted string
$command.= "\\n".readline(' > ');
preg_filter('/\"/', '"', $command, -1, $count);
//continue;
}
/** end of changes made by felipnmoura **/ /** end of changes made by felipnmoura **/
+17 -1
Ver Arquivo
@@ -77,7 +77,23 @@
set user :username: as :status: set user :username: as :status:
or or
set user :username: as :type: set user :username: as :type:
Where status may be 'A' or 'I', and type may be 'A' or 'N'")
Where status may be 'A' or 'I', and type may be 'A' or 'N'
Examples:
1) An administrator changing the name of another project
auth admin
set project.name \"New Name\" projectToBeChanged
2) A user changing the idiom of one of his projects
auth felipe
use projectToBeChanged
set project.idiom pt
3) A user changing the source of a project(changing the main.mnd source file)
auth felipe
use projectToBeChanged
set project.source \"New content is written here, for the source of the project\" main
")
->setAction('executableFunction'); ->setAction('executableFunction');
$this->addRequiredArgument('property', $this->addRequiredArgument('property',
+2 -1
Ver Arquivo
@@ -122,7 +122,8 @@ EOT
case 'source': case 'source':
$p= \Mind::$currentProject; $p= \Mind::$currentProject;
if($p){ if($p){
var_dump(\MindProject::loadSource()); $s= $this->extra? $this->extra: 'main';
echo \MindProject::loadSource($s)."\n";
}else{ }else{
\MindSpeaker::write("currentProjectRequired"); \MindSpeaker::write("currentProjectRequired");
} }