diff --git a/app/conf/services.yaml b/app/conf/services.yaml index 06c362c..dc93424 100644 --- a/app/conf/services.yaml +++ b/app/conf/services.yaml @@ -6,6 +6,9 @@ services: config: class: '\Magdev\Dossier\Service\ConfigService' + + system: + class: '\Magdev\Dossier\Service\SystemService' monolog: class: '\Magdev\Dossier\Service\MonologService' @@ -21,7 +24,7 @@ services: git: class: '\Magdev\Dossier\Service\GitService' - arguments: ['@config', '@monolog'] + arguments: ['@config', '@monolog', '@system'] translator: class: '\Magdev\Dossier\Service\TranslatorService' diff --git a/src/Service/GitService.php b/src/Service/GitService.php index b1acd5f..bfdd495 100644 --- a/src/Service/GitService.php +++ b/src/Service/GitService.php @@ -30,14 +30,8 @@ namespace Magdev\Dossier\Service; -// git branch | grep \* | cut -d ' ' -f2 - class GitService { - const MODE_OUTPUT = 1; - const MODE_RETURN = 2; - const MODE_LASTLINE = 3; - /** * Configuration service * @var \Magdev\Dossier\Service\ConfigService @@ -50,17 +44,25 @@ class GitService */ protected $logger = null; + /** + * System service + * @var \Magdev\Dossier\Service\SystemService + */ + protected $system = null; + /** * Constructor * * @param \Magdev\Dossier\Service\ConfigService $config * @param \Magdev\Dossier\Service\MonologService $logger + * @param \Magdev\Dossier\Service\SystemService $system */ - public function __construct(ConfigService $config, MonologService $logger) + public function __construct(ConfigService $config, MonologService $logger, SystemService $system) { $this->config = $config; $this->logger = $logger; + $this->system = $system; } @@ -72,7 +74,7 @@ class GitService public function init(): bool { if (!$this->isGitRepository()) { - $this->exec('git init'); + $this->system->exec('git init'); } return $this->isGitRepository(); } @@ -88,7 +90,7 @@ class GitService if (!$this->isGitRepository()) { return $this->config->get('output.docname'); } - return $this->exec('git branch | grep \\\* | cut -d \' \' -f2', self::MODE_LASTLINE); + return $this->system->exec('git branch | grep \\\* | cut -d \' \' -f2', self::MODE_LASTLINE); } @@ -101,25 +103,4 @@ class GitService { return is_dir(PROJECT_ROOT.'/.git') && file_exists(PROJECT_ROOT.'/.git/HEAD'); } - - - /** - * Execute a system command - * - * @param string $cmd - * @param int $mode - * @param array $output - * @param int $return - * @return string|int|array - */ - protected function exec(string $cmd, int $mode = self::MODE_OUTPUT, &$output = array(), int &$return = 0) - { - $lastline = exec($cmd, $output, $return); - switch ($mode) { - case self::MODE_LASTLINE: return $lastline; - case self::MODE_RETURN: return $return; - default: - case self::MODE_OUTPUT: return $output; - } - } } diff --git a/src/Service/SystemService.php b/src/Service/SystemService.php new file mode 100644 index 0000000..2d4c12e --- /dev/null +++ b/src/Service/SystemService.php @@ -0,0 +1,59 @@ +