Skip to content

Commit 0476360

Browse files
committed
Allow the registration of command aliases to override 'which'
1 parent e04c3b8 commit 0476360

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/Engine/EngineBase.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,17 @@ public function shellWhich($command) {
274274
return $cache[$command];
275275
}
276276

277+
// Look at manual aliases.
278+
$alias = $this->converter->getCommandAlias($command);
279+
if (isset($alias)) {
280+
$path = realpath($alias);
281+
if ($path === FALSE) {
282+
$path = NULL;
283+
}
284+
$cache[$command] = $path;
285+
return $path;
286+
}
287+
277288
// Look in the bin folder for FileConverter-provided bins (symlinks work fine).
278289
$bin = realpath(__DIR__ . '/../../bin/' . $command);
279290
if ($bin !== FALSE && is_executable($bin)) {

src/FileConverter.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ static public function &factory($get_singleton = TRUE) {
4040
}
4141

4242
protected $configurations = array();
43-
protected $settings = array();
43+
protected $settings = array(
44+
'alias' => array(),
45+
);
4446
protected $missing_engines = array();
4547
protected $previous_engines = array();
4648
protected $conversion_depth = 0;
@@ -167,6 +169,13 @@ public function convertString($source, &$destination, $convert_path = 'null->nul
167169
return $this;
168170
}
169171

172+
public function getCommandAlias($command) {
173+
if (isset($this->settings['alias'][$command])) {
174+
return $this->settings['alias'][$command];
175+
}
176+
return NULL;
177+
}
178+
170179
public function getConvertedString($source, $convert_path = 'null->null') {
171180
$destination = '';
172181
$this->convertString($source, $destination, $convert_path);
@@ -274,7 +283,7 @@ public function getEngines($convert_path, $configuration_overrides = NULL, $conf
274283
// This is similar to setConverter('a->b', 'force_id'),
275284
// except that it might not be the first engine tried.
276285
if (isset($configuration['#final'])) {
277-
break(2);
286+
break (2);
278287
}
279288
}
280289
}
@@ -333,6 +342,10 @@ public function optimizeFile($source = NULL, $destination = NULL, $ext = NULL) {
333342
return $this->convert('file', "$ext->$ext", $source, $destination);
334343
}
335344

345+
public function &setCommandAlias($alias, $path) {
346+
$this->settings['alias'][$alias] = $path;
347+
}
348+
336349
public function &setConverter($convert_path = 'null->null', $configuration = 'null:default') {
337350
$conf = new ConfigurationOverride($this->settings);
338351
$conf->setConverter($convert_path, $configuration);

0 commit comments

Comments
 (0)