Example #1
0
 public function testTranslateCommandline()
 {
     $cmd2 = "cvs -d:pserver:hans@xmpl.org:/cvs commit -m\"added a new test file for 'fun'\" Test.php";
     $cmd3 = "cvs -d:pserver:hans@xmpl.org:/cvs  commit   -m 'added a new test file for fun' Test.php";
     // This should work fine; we expect 5 args
     $cmd1 = "cvs -d:pserver:hans@xmpl.org:/cvs commit -m \"added a new test file\" Test.php";
     $c = new Commandline($cmd1);
     $this->assertEquals(5, count($c->getArguments()));
     // This has some extra space, but we expect same number of args
     $cmd2 = "cvs -d:pserver:hans@xmpl.org:/cvs   commit  -m \"added a new test file\"    Test.php";
     $c2 = new Commandline($cmd2);
     $this->assertEquals(5, count($c->getArguments()));
     // nested quotes should not be a problem either
     $cmd3 = "cvs -d:pserver:hans@xmpl.org:/cvs   commit  -m \"added a new test file for 'fun'\"    Test.php";
     $c3 = new Commandline($cmd3);
     $this->assertEquals(5, count($c->getArguments()));
     $args = $c3->getArguments();
     $this->assertEquals("added a new test file for 'fun'", $args[3]);
     // now try unbalanced quotes -- this should fail
     $cmd4 = "cvs -d:pserver:hans@xmpl.org:/cvs   commit  -m \"added a new test file for 'fun' Test.php";
     try {
         $c4 = new Commandline($cmd4);
         $this->fail("Should throw BuildException because 'unbalanced quotes'");
     } catch (BuildException $be) {
         if (false === strpos($be->getMessage(), "unbalanced quotes")) {
             $this->fail("Should throw BuildException because 'unbalanced quotes'");
         }
     }
 }
Example #2
0
 /**
  * Gets the command string to be executed
  * @return string
  */
 private function prepareCommand()
 {
     $this->commandLine->setExecutable($this->getPhp());
     $composerCommand = $this->commandLine->createArgument(true);
     $composerCommand->setValue($this->getCommand());
     $composerPath = $this->commandLine->createArgument(true);
     $composerPath->setValue($this->getCOmposer());
 }
Example #3
0
 /**
  * Prepares the command string to be executed
  * @return string
  */
 private function prepareCommandLine()
 {
     $this->commandLine->setExecutable($this->getPhp());
     //We are un-shifting arguments to the beginning of the command line because arguments should be at the end
     $this->commandLine->createArgument(true)->setValue($this->getCommand());
     $this->commandLine->createArgument(true)->setValue($this->getComposer());
     $commandLine = strval($this->commandLine);
     //Creating new Commandline instance. It allows to handle subsequent calls correctly
     $this->commandLine = new Commandline();
     return $commandLine;
 }
 /**
  * Dispatch the application
  */
 public function dispatch()
 {
     $cmd = Commandline::getInstance();
     // -v option displays version info
     if ($cmd->get('v')) {
         include KPATH_HELP . '/version.php';
         die;
     }
     // run all tests or the test specified on the command line
     $this->runTest($cmd->getArg(1));
 }
Example #5
0
 /**
  * Starts the web server and runs the encapsulated tasks.
  */
 public function main()
 {
     $this->prepare();
     $cmd = Commandline::toString($this->commandline->getCommandline(), true);
     $streams = [["file", "/dev/null", "r"], ["file", "/dev/null", "w"], ["file", "/dev/null", "w"]];
     $handle = proc_open($cmd, $streams, $pipes);
     if (!is_resource($handle)) {
         throw new BuildException(get_class($this) . ' could not start web server.');
     } else {
         $this->log(sprintf("Started web server, listening on http://%s:%d", $this->address, $this->port), Project::MSG_INFO);
         $msg = isset($this->router) ? sprintf("with %s as docroot and %s as router", $this->docroot, $this->router) : sprintf("with %s as docroot", $this->docroot);
         $this->log($msg, Project::MSG_VERBOSE);
     }
     try {
         foreach ($this->tasks as $task) {
             $task->perform();
         }
     } finally {
         // Terminate server with SIGINT
         proc_terminate($handle, 2);
         $this->log("Stopped web server", Project::MSG_INFO);
     }
 }
 /**
  * @return Commandline
  */
 public function __copy()
 {
     $c = new Commandline();
     $c->setExecutable($this->executable);
     $c->addArguments($this->getArguments());
     return $c;
 }
 /**                
  * Builds the full command to execute and stores it in $realCommand.  
  *                                                                  
  * @param  none
  *
  * @return void   
  */
 private function buildCommand()
 {
     // Log
     $this->log('Command building started ', $this->loglevel);
     // Building the executable
     $this->realCommand = Commandline::toString($this->commandline->getCommandline(), $this->escape);
     // Adding the source filename at the end of command, validating the existing
     // sourcefile position explicit mentioning
     if ($this->addsourcefile === true && strpos($this->realCommand, self::SOURCEFILE_ID) === false) {
         $this->realCommand .= ' ' . self::SOURCEFILE_ID;
     }
     // Setting command output redirection with content appending
     if ($this->output !== null) {
         $this->realCommand .= ' 1>';
         $this->realCommand .= $this->appendoutput ? '>' : '';
         // Append output
         $this->realCommand .= ' ' . escapeshellarg($this->output->getPath());
     } elseif ($this->spawn) {
         // Validating the 'spawn' configuration, and redirecting the output to 'null'
         // Validating the O.S. variant
         if ('WIN' == $this->osvariant) {
             $this->realCommand .= ' > NUL';
             // MS Windows output nullification
         } else {
             $this->realCommand .= ' 1>/dev/null';
             // GNU/Linux output nullification
         }
         $this->log("For process spawning, setting Output nullification ", $this->loglevel);
     }
     // Setting command error redirection with content appending
     if ($this->error !== null) {
         $this->realCommand .= ' 2>';
         $this->realCommand .= $this->appendoutput ? '>' : '';
         // Append error
         $this->realCommand .= ' ' . escapeshellarg($this->error->getPath());
     }
     // Setting the execution as a background process
     if ($this->spawn) {
         // Validating the O.S. variant
         if ('WIN' == $this->osvariant) {
             $this->realCommand = 'start /b ' . $this->realcommand;
             // MS Windows background process forking
         } else {
             $this->realCommand .= ' &';
             // GNU/Linux background process forking
         }
     }
     // Log
     $this->log('Command built : ' . $this->realCommand, $this->loglevel);
     // Log
     $this->log('Command building completed ', $this->loglevel);
     return;
 }
 /**
  * Creates a nested <arg> tag.
  *
  * @return CommandlineArgument Argument object
  */
 public function createArg()
 {
     return $this->commandline->createArgument();
 }
 /**
  * Gets the command string to be executed
  * @return string
  */
 public function getCmdString()
 {
     // Add no-debug arg if it isn't already present
     if (!$this->debug && !$this->isNoDebugArgPresent()) {
         $this->createArg()->setName("no-debug");
     }
     $cmd = array(Commandline::quoteArgument($this->console), $this->command, implode(' ', $this->args));
     $cmd = implode(' ', $cmd);
     return $cmd;
 }