Skip to content

Commit

Permalink
Allow the registration of command aliases to override 'which'
Browse files Browse the repository at this point in the history
  • Loading branch information
stackpr committed Aug 14, 2018
1 parent e04c3b8 commit 0476360
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
11 changes: 11 additions & 0 deletions src/Engine/EngineBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,17 @@ public function shellWhich($command) {
return $cache[$command];
}

// Look at manual aliases.
$alias = $this->converter->getCommandAlias($command);
if (isset($alias)) {
$path = realpath($alias);
if ($path === FALSE) {
$path = NULL;
}
$cache[$command] = $path;
return $path;
}

// Look in the bin folder for FileConverter-provided bins (symlinks work fine).
$bin = realpath(__DIR__ . '/../../bin/' . $command);
if ($bin !== FALSE && is_executable($bin)) {
Expand Down
17 changes: 15 additions & 2 deletions src/FileConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ static public function &factory($get_singleton = TRUE) {
}

protected $configurations = array();
protected $settings = array();
protected $settings = array(
'alias' => array(),
);
protected $missing_engines = array();
protected $previous_engines = array();
protected $conversion_depth = 0;
Expand Down Expand Up @@ -167,6 +169,13 @@ public function convertString($source, &$destination, $convert_path = 'null->nul
return $this;
}

public function getCommandAlias($command) {
if (isset($this->settings['alias'][$command])) {
return $this->settings['alias'][$command];
}
return NULL;
}

public function getConvertedString($source, $convert_path = 'null->null') {
$destination = '';
$this->convertString($source, $destination, $convert_path);
Expand Down Expand Up @@ -274,7 +283,7 @@ public function getEngines($convert_path, $configuration_overrides = NULL, $conf
// This is similar to setConverter('a->b', 'force_id'),
// except that it might not be the first engine tried.
if (isset($configuration['#final'])) {
break(2);
break (2);
}
}
}
Expand Down Expand Up @@ -333,6 +342,10 @@ public function optimizeFile($source = NULL, $destination = NULL, $ext = NULL) {
return $this->convert('file', "$ext->$ext", $source, $destination);
}

public function &setCommandAlias($alias, $path) {
$this->settings['alias'][$alias] = $path;
}

public function &setConverter($convert_path = 'null->null', $configuration = 'null:default') {
$conf = new ConfigurationOverride($this->settings);
$conf->setConverter($convert_path, $configuration);
Expand Down

0 comments on commit 0476360

Please sign in to comment.