5 use Symfony\Component\Process\ExecutableFinder;
6 use Symfony\Component\Process\Process;
9 * This task is supposed to be executed as shell command.
10 * You can specify working directory and if output is printed.
17 * @var \Robo\Common\TimeKeeper
22 * @return \Robo\Common\TimeKeeper
24 protected function getExecTimer()
26 if (!isset($this->execTimer)) {
27 $this->execTimer = new TimeKeeper();
29 return $this->execTimer;
33 * Look for a "{$cmd}.phar" in the current working
34 * directory; return a string to exec it if it is
35 * found. Otherwise, look for an executable command
36 * of the same name via findExecutable.
42 protected function findExecutablePhar($cmd)
44 if (file_exists("{$cmd}.phar")) {
45 return "php {$cmd}.phar";
47 return $this->findExecutable($cmd);
51 * Return the best path to the executable program
52 * with the provided name. Favor vendor/bin in the
53 * current project. If not found there, use
54 * whatever is on the $PATH.
60 protected function findExecutable($cmd)
62 $pathToCmd = $this->searchForExecutable($cmd);
64 return $this->useCallOnWindows($pathToCmd);
74 private function searchForExecutable($cmd)
76 $projectBin = $this->findProjectBin();
78 $localComposerInstallation = $projectBin . DIRECTORY_SEPARATOR . $cmd;
79 if (file_exists($localComposerInstallation)) {
80 return $localComposerInstallation;
82 $finder = new ExecutableFinder();
83 return $finder->find($cmd, null, []);
89 protected function findProjectBin()
92 $candidates = [ __DIR__ . '/../../vendor/bin', __DIR__ . '/../../bin', $cwd . '/vendor/bin' ];
94 // If this project is inside a vendor directory, give highest priority
96 $vendorDirContainingUs = realpath(__DIR__ . '/../../../..');
97 if (is_dir($vendorDirContainingUs) && (basename($vendorDirContainingUs) == 'vendor')) {
98 array_unshift($candidates, $vendorDirContainingUs . '/bin');
101 foreach ($candidates as $dir) {
102 if (is_dir("$dir")) {
103 return realpath($dir);
110 * Wrap Windows executables in 'call' per 7a88757d
116 protected function useCallOnWindows($cmd)
118 if (defined('PHP_WINDOWS_VERSION_BUILD')) {
119 if (file_exists("{$cmd}.bat")) {
127 protected function getCommandDescription()
129 return $this->process->getCommandLine();
133 * @param string $command
135 * @return \Robo\Result
137 protected function executeCommand($command)
139 // TODO: Symfony 4 requires that we supply the working directory.
140 $result_data = $this->execute(new Process($command, getcwd()));
143 $result_data->getExitCode(),
144 $result_data->getMessage(),
145 $result_data->getData()