Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/7'
Browse files Browse the repository at this point in the history
Close #7
  • Loading branch information
weierophinney committed Feb 22, 2017
2 parents fb53061 + cab3ce7 commit 14503ee
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
52 changes: 27 additions & 25 deletions src/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand All @@ -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':
Expand All @@ -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:
Expand All @@ -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(
Expand Down

0 comments on commit 14503ee

Please sign in to comment.