Install plugins in CakePHP/2.5 using Composer

I’m (trying to) tidy up a pretty messed app built on CakePHP/2.5.5. My first refactoring was to get CakePHP itself installed with Composer and I currently have these directories (functional so far):

  • /app with all my custom code
  • /Vendor, fully managed with Composer

The app was already using Composer to some extent and I currently two sets of Composer settings and files:

  • /composer.json is the one I want to keep and currently installs cakephp/cakephp into /Vendor
  • /app/composer.json is the one I want to get rid of and installs packages between /app/Plugin and /app/Vendor.

When I move e.g. friendsofcake/cakepdf into main settings I get it into a brand new /Plugin directory and:

Missing Plugin

Error: The application is trying to load a file from the CakePdf plugin

Error: Make sure your plugin CakePdf is in the app\Plugin directory and was loaded

<?php CakePlugin::load('CakePdf');

I’ve got two questions:

  1. What’d be the “correct” plugin path in this situation?
  2. How do I need to configure it?

As far as I know the CakePdf plugin could even be in the /vendor dir considering it should be loaded using PSR-4 (was that already a thing in Cake2?).
Maybe you should try using the proper namespace of the app? (eg. friendsofcake/cakepdf)

I’m pretty sure that Cake/2.5 doesn’t rely on Composer for this. It loads all stuff with its own autoloader: models, controllers or plugins.

My findings so far… Composer installs stuff at /Plugins because of the composer/installers package’s know-how but that path is wrong and you need to configure installer-paths in Composer. Perhaps it’s a bug after all (I understand this is all very outdated software).


Edit: I can confirm that adding a section in your composer.json file like this, where installer-paths has a line for every package that happens to be a plugin, works like a charm:

"require": {
    // ...
    "cakephp/debug_kit": "2.2.*",
    "friendsofcake/cakepdf": "1.0.*"
},
"extra": {
    "installer-paths": {
        "app/Plugin/Cakepdf": ["friendsofcake/cakepdf"],
        "app/Plugin/DebugKit": ["cakephp/debug_kit"]
    }
},

I suspect that composer/installers picks a wrong path because it doesn’t take CakePHP version into account.

This is fairly likely yea