PhpBrew\CommandBuilder::buildCommand PHP Méthode

buildCommand() public méthode

public buildCommand ( $handleRedirect = true )
    public function buildCommand($handleRedirect = true)
    {
        $cmd = array();
        if ($this->nice) {
            $cmd[] = 'nice';
            $cmd[] = '-n';
            $cmd[] = $this->nice;
        }
        $cmd[] = $this->script;
        if ($this->args) {
            foreach ($this->args as $arg) {
                $cmd[] = escapeshellarg($arg);
            }
        }
        // redirect stderr to stdout and pipe to the file.
        if ($handleRedirect) {
            if ($this->stdout) {
                // XXX: tee is disabled here because the exit status won't be
                // correct when using pipe.
                /*
                                $cmd[] = '| tee';
                                if ($this->append) {
                   $cmd[] = '-a';
                                }
                                $cmd[] = $this->logPath;
                */
                $cmd[] = '2>&1';
            } elseif ($this->logPath) {
                $cmd[] = $this->append ? '>>' : '>';
                $cmd[] = $this->logPath;
                $cmd[] = '2>&1';
            }
        }
        return implode(' ', $cmd);
    }

Usage Example

Exemple #1
0
 public function run(Build $build, $targets = array())
 {
     if ($build->getState() >= Build::STATE_BUILD) {
         $this->info('===> Already built, skipping...');
         return;
     }
     $this->info('===> Building...');
     $cmd = new CommandBuilder('make');
     $cmd->setAppendLog(true);
     $cmd->setLogPath($build->getBuildLogPath());
     $cmd->setStdout($this->options->{'stdout'});
     if (!empty($targets)) {
         foreach ($targets as $t) {
             $cmd->addArg($t);
         }
     }
     if ($this->options->nice) {
         $cmd->nice($this->options->nice);
     }
     if ($makeJobs = $this->options->{'jobs'}) {
         $cmd->addArg("-j{$makeJobs}");
     }
     $this->debug($cmd->buildCommand());
     if (!$this->options->dryrun) {
         $startTime = microtime(true);
         $code = $cmd->execute($lastline);
         if ($code !== 0) {
             throw new SystemCommandException("Make failed: {$lastline}", $build, $build->getBuildLogPath());
         }
         $buildTime = round((microtime(true) - $startTime) / 60, 1);
         $this->info("Build finished: {$buildTime} minutes.");
     }
     $build->setState(Build::STATE_BUILD);
 }
All Usage Examples Of PhpBrew\CommandBuilder::buildCommand