Skip to content

Commit

Permalink
Always add long alias for plugin shells.
Browse files Browse the repository at this point in the history
Always add the long alias for plugin shells for backwards compatibility
reasons. The ShellDispatcher implementatino would allow plugin shells to
either be called with their long name or short name if there were no
conflicts. Because we're building the list ahead of dispatch time we
need to include all the aliases now.

Bump up the logging as not being able to load classes is something
people will want to know.
  • Loading branch information
markstory committed Jun 13, 2017
1 parent 46c5e17 commit dd21cad
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 19 deletions.
34 changes: 21 additions & 13 deletions src/Console/CommandCollection.php
Expand Up @@ -158,23 +158,31 @@ public function autoDiscover()
$shells = $scanner->scanAll();

$adder = function ($shells, $key) {
if (!empty($shells[$key])) {
foreach ($shells[$key] as $info) {
$name = $info['name'];
// If the short name has been used, use the full name.
// This allows app shells to have name preference.
// and app shells to overwrite core shells.
if ($this->has($name) && $name !== $info['fullName']) {
$name = $info['fullName'];
}
try {
$this->add($name, $info['class']);
} catch (InvalidArgumentException $e) {
Log::debug("Could not add {$info['class']} via autodiscovery. " . $e->getMessage());
if (empty($shells[$key])) {
return;
}
foreach ($shells[$key] as $info) {
$name = $info['name'];
$addLong = $name !== $info['fullName'];

// If the short name has been used, use the full name.
// This allows app shells to have name preference.
// and app shells to overwrite core shells.
if ($this->has($name) && $addLong) {
$name = $info['fullName'];
}

try {
$this->add($name, $info['class']);
if ($addLong) {
$this->add($info['fullName'], $info['class']);
}
} catch (InvalidArgumentException $e) {
Log::warn("Could not add {$info['class']} via autodiscovery. " . $e->getMessage());
}
}
};

$adder($shells, 'CORE');
$adder($shells, 'app');
foreach (array_keys($shells['plugins']) as $key) {
Expand Down
13 changes: 7 additions & 6 deletions tests/TestCase/Console/CommandCollectionTest.php
Expand Up @@ -234,9 +234,9 @@ public function testAutoDiscoverPlugin()
$collection->has('example'),
'Used short name for unique plugin shell'
);
$this->assertFalse(
$this->assertTrue(
$collection->has('test_plugin.example'),
'Long names not stored for unique shells'
'Long names are stored for unique shells'
);
$this->assertTrue(
$collection->has('sample'),
Expand All @@ -246,16 +246,17 @@ public function testAutoDiscoverPlugin()
$collection->has('test_plugin.sample'),
'Duplicate shell was given a full alias'
);
$this->assertFalse(
$collection->has('company/test_plugin_three.company'),
'Long names not stored for unique shells'
);
$this->assertTrue(
$collection->has('company'),
'Used short name for unique plugin shell'
);
$this->assertTrue(
$collection->has('company/test_plugin_three.company'),
'Long names are stored as well'
);

$this->assertEquals('TestPlugin\Shell\ExampleShell', $collection->get('example'));
$this->assertEquals($collection->get('example'), $collection->get('test_plugin.example'));
$this->assertEquals(
'TestApp\Shell\SampleShell',
$collection->get('sample'),
Expand Down

0 comments on commit dd21cad

Please sign in to comment.