When baking a vendor-namespaced plugin (bin/cake bake plugin YourVendor/YourPlugin) the plugin class is never
actually loaded, and in 5.3 you now get a deprecation warning about it:
The class does exist (bake generated it). The problem is the autoloader doesn't know about it.
In CakePHP 4 / bake 2.x this worked because bake generated a composer.json inside the plugin directory with the PSR-4
mapping. In bake 3.x that file is no longer generated for app plugins, presumably because preAutoloadDump() in
plugin-installer v2 was meant to cover it. And it does but only for flat plugins (plugins/YourPlugin/src/).
For a vendor-namespaced plugin the structure is plugins/YourVendor/YourPlugin/src/. preAutoloadDump() iterates one
level deep, finds YourVendor/, checks whether plugins/YourVendor/src/ exists (it doesn't), and moves on. The
YourVendor\YourPlugin\ namespace never gets registered.
The fix is to detect that a first-level directory has no src/ and recurse one level deeper to find plugins inside it.
The existing !isset() guard already means manually-added entries in composer.json take precedence, so it wouldn't
break anything.
Workaround for now: manually add the mapping to the root composer.json:
"autoload": {
"psr-4": {
"App\\": "src/",
"YourVendor\\YourPlugin\\": "plugins/YourVendor/YourPlugin/src/"
}
}
Then composer dump-autoload.
When baking a vendor-namespaced plugin (bin/cake bake plugin YourVendor/YourPlugin) the plugin class is never
actually loaded, and in 5.3 you now get a deprecation warning about it:
The class does exist (bake generated it). The problem is the autoloader doesn't know about it.
In CakePHP 4 / bake 2.x this worked because bake generated a composer.json inside the plugin directory with the PSR-4
mapping. In bake 3.x that file is no longer generated for app plugins, presumably because preAutoloadDump() in
plugin-installer v2 was meant to cover it. And it does but only for flat plugins (plugins/YourPlugin/src/).
For a vendor-namespaced plugin the structure is plugins/YourVendor/YourPlugin/src/. preAutoloadDump() iterates one
level deep, finds YourVendor/, checks whether plugins/YourVendor/src/ exists (it doesn't), and moves on. The
YourVendor\YourPlugin\ namespace never gets registered.
The fix is to detect that a first-level directory has no src/ and recurse one level deeper to find plugins inside it.
The existing !isset() guard already means manually-added entries in composer.json take precedence, so it wouldn't
break anything.
Workaround for now: manually add the mapping to the root composer.json:
Then composer dump-autoload.