Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ only need to specify the `type` in their composer config:
"type": "cakephp-plugin"
```

## App Plugins

Plugins in your application's `plugins/` directory are added to the generated
`cakephp-plugins.php` as well. If a plugin exists both there and in `vendor/`,
the one in `plugins/` is used. This lets you work on a local copy of a plugin
that is also installed through composer.

## Multiple Plugin Paths

If your application uses multiple plugin paths. In addition to configuring your
Expand Down
9 changes: 7 additions & 2 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,24 @@ public function findPlugins(
continue;
}

$ns = $this->getPrimaryNamespace($package);
// Same key format as app plugins, so `Vendor/Plugin` in plugins/ can replace it.
$ns = str_replace('\\', '/', $this->getPrimaryNamespace($package));
$path = $vendorDir . DIRECTORY_SEPARATOR . $package->getPrettyName();
$plugins[$ns] = $path;
}

$appPlugins = [];
foreach ($pluginDirs as $path) {
$path = $this->getFullPath($path, $vendorDir);
if (!is_dir($path)) {
continue;
}
$plugins += $this->findAppPlugins($path, true);
$appPlugins += $this->findAppPlugins($path, true);
}

// App plugins take priority over vendor plugins of the same name.
$plugins = $appPlugins + $plugins;

ksort($plugins);

return $plugins;
Expand Down
39 changes: 39 additions & 0 deletions tests/TestCase/PluginTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,45 @@ public function testFindPlugins()
$this->assertSame($expected, $return, 'Composer and application plugins should be listed');
}

public function testFindPluginsAppPluginOverridesVendorPlugin()
{
$package = new Package('cakephp/fee', '1.0', '1.0');
$package->setType('cakephp-plugin');
$package->setAutoload([
'psr-4' => [
'Fee' => 'src/',
],
]);

$return = $this->plugin->findPlugins(
[$package],
[$this->path . '/plugins'],
$this->path . '/vendor',
);

$this->assertSame($this->path . '/plugins/Fee', $return['Fee']);
}

public function testFindPluginsNamespacedAppPluginOverridesVendorPlugin()
{
$package = new Package('your-vendor/your-plugin', '1.0', '1.0');
$package->setType('cakephp-plugin');
$package->setAutoload([
'psr-4' => [
'YourVendor\\YourPlugin\\' => 'src/',
],
]);

$return = $this->plugin->findPlugins(
[$package],
[$this->path . '/plugins'],
$this->path . '/vendor',
);

$this->assertSame($this->path . '/plugins/YourVendor/YourPlugin', $return['YourVendor/YourPlugin']);
$this->assertArrayNotHasKey('YourVendor\\YourPlugin', $return);
}

public function testWriteConfigFile()
{
$plugins = [
Expand Down
Loading