Skip to content

Commit

Permalink
Merge pull request #6 from M165437/symfony-v4
Browse files Browse the repository at this point in the history
Update dependencies
  • Loading branch information
hendrikmaus authored Jun 16, 2018
2 parents eac26a0 + caff323 commit 3026183
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ The change log itself is written the way that [keepachangelog.com](http://keepac

## [Unreleased]

## [5.0.0] - 2018-03-05
## Changed
- Allow v4 of Symfony component
- Update Robo task runner

## [4.0.1] - 2016-09-20
## Changed
- Removed the cumbersome way to install drafter and added a reference to hmaus/drafter-installer
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
"minimum-stability": "stable",
"require": {
"php": ">=5.6",
"symfony/process": "^2.7|^3.1.4"
"symfony/process": "^2.7|^3.1.4|^4"
},
"require-dev": {
"phpunit/phpunit": "^5.0",
"codegyre/robo": "^0.7.2",
"consolidation/robo": "^1.2.2",
"codeclimate/php-test-reporter": "^0.3",
"hmaus/drafter-installer": "^1.0"
},
Expand Down
30 changes: 14 additions & 16 deletions src/Drafter.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
namespace Hmaus\DrafterPhp;

use Symfony\Component\Process\Process;
use Symfony\Component\Process\ProcessBuilder;

class Drafter implements DrafterInterface
{
Expand Down Expand Up @@ -145,16 +144,13 @@ public function useLineNum()

public function build()
{
$builder = new ProcessBuilder();
$builder->setPrefix($this->binary);

$this->validateOptionsAndArguments();

$builder->setArguments(
$this->getProcessBuilderArguments()
$process = new Process(
$this->getProcessCommand()
);

return $builder->getProcess();
return $process;
}

public function run(Process $process = null)
Expand Down Expand Up @@ -241,37 +237,39 @@ private function isVersionOptionSet()
}

/**
* Get arguments array to pass it into the process builder.
* Get command to pass it into the process.
*
* The method will append the input file path argument to the end, like
* described in the `drafter --help` output.
*
* @return array|\string[]
* @return string
*/
private function getProcessBuilderArguments()
private function getProcessCommand()
{
$options = $this->transformOptions();
$options[] = $this->input;

return $options;
$command = $this->binary . ' ' . implode(' ', $options);

return $command;
}

/**
* Return options prepared to be passed into the ProcessBuilder.
* Return options prepared to be passed into the Process.
*
* E.g.: ["--output" => "path/to/file"] -> ["--output=path/to/file"]
*
* The original format is an associative array, where the key is the
* option name and the value is the respective value.
* The process builder will want those as single strings to escape them
* The process will want those as single strings to escape them
* for the command line. Hence, we have to turn ["--output" => "path/to/file"]
* into ["--output=path/to/file"].
*
* @return \string[]
*/
private function transformOptions()
{
$builderOptions = [];
$processOptions = [];

foreach ($this->options as $key => $value) {
$option = $key;
Expand All @@ -280,9 +278,9 @@ private function transformOptions()
$option .= '=' . $value;
}

$builderOptions[] = $option;
$processOptions[] = $option;
}

return $builderOptions;
return $processOptions;
}
}

0 comments on commit 3026183

Please sign in to comment.