diff --git a/CHANGELOG.md b/CHANGELOG.md index fb6a0e4..96e89cf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,10 @@ All notable changes to this project will be documented in this file, in reverse validation for the number of arguments, ensuring that no flags have empty values. +- [#7](https://github.com/zfcampus/zf-composer-autoloading/pull/7) adds + validation of the composer binary in a cross-platform way; an exception is + now raised if it is not executable. + ## 1.1.0 - 2017-02-16 ### Added diff --git a/src/Command.php b/src/Command.php index e3c65d1..6ef366d 100644 --- a/src/Command.php +++ b/src/Command.php @@ -230,10 +230,6 @@ private function parseArguments(array $args) $this->module = $module = array_pop($args); // Parse arguments - if (empty($args)) { - return $this->checkModulePath(); - } - $args = array_values($args); $count = count($args); @@ -249,14 +245,6 @@ private function parseArguments(array $args) // fall-through case '-c': $this->composer = $args[$i + 1]; - if (! is_executable($this->composer)) { - fwrite( - STDERR, - 'Provided composer binary does not exist or is not executable' . PHP_EOL . PHP_EOL - ); - $this->help(STDERR); - return false; - } break; case '--type': @@ -276,15 +264,6 @@ private function parseArguments(array $args) // fall-through case '-p': $this->modulesPath = preg_replace('/^\.\//', '', str_replace('\\', '/', $args[$i + 1])); - if (! is_dir(sprintf('%s/%s', $this->path, $this->modulesPath))) { - fwrite( - STDERR, - 'Provided path to modules directory does not exist or is not a directory' - . PHP_EOL . PHP_EOL - ); - $this->help(STDERR); - return false; - } break; default: @@ -294,17 +273,40 @@ private function parseArguments(array $args) } } - return $this->checkModulePath(); + $this->modulePath = sprintf('%s/%s/%s', $this->path, $this->modulesPath, $this->module); + + return $this->checkArguments(); } /** - * Checks if the module path exists and is a directory. + * Checks if arguments of the script are correct. * * @return bool */ - private function checkModulePath() + private function checkArguments() { - $this->modulePath = sprintf('%s/%s/%s', $this->path, $this->modulesPath, $this->module); + $output = []; + $returnVar = null; + exec($this->composer, $output, $returnVar); + + if ($returnVar !== 0) { + fwrite( + STDERR, + 'Provided composer binary does not exist or is not executable' . PHP_EOL . PHP_EOL + ); + $this->help(STDERR); + return false; + } + + if (! is_dir(sprintf('%s/%s', $this->path, $this->modulesPath))) { + fwrite( + STDERR, + 'Provided path to modules directory does not exist or is not a directory' + . PHP_EOL . PHP_EOL + ); + $this->help(STDERR); + return false; + } if (! is_dir($this->modulePath)) { fwrite(