0

I'd like to use Composer to install some libraries inside my app directory but the src/app/composer.json lists CakePHP as non-dev dependency:

"require": {
    "php": ">=5.3.0",
    "ext-mcrypt": "*",
    "cakephp/cakephp": "~2.9"
},
"require-dev": {
    "phpunit/phpunit": "3.7.*"
},

That causes a second copy of CakePHP getting installed into my app/Vendor directory. It's annoying because it uses disc space and gets on the way of IDE's code intelligence.

What's the best way to prevent that? Is it safe to just remove the dependency altogether?

Álvaro González
  • 142,137
  • 41
  • 261
  • 360
  • Just remove CakePHP from the composer.json file if you don't want it? Disk space? Seriously? It's 2017. Get me an address and I'll donate you an old 16gb SD card, you can install plenty of CakePHP copies then. ;) Or add a script in composers post install file that will remove the CakePHP folder. – floriank May 08 '17 at 08:52
  • 1
    Would it not be better to start using Composer to install CakePHP and remove your local copy of the library? It would make it a lot easier to maintain your app and keep CakePHP up to date. You could then use Composer to install any CakePHP plugins you need too. – drmonkeyninja May 08 '17 at 08:57
  • @drmonkeyninja Is that even possible? Remember we're talking about version 2. At least, docs don't even mention it. – Álvaro González May 08 '17 at 09:31
  • Removing the `"cakephp/cakephp": "~2.9"` line doesn't seem to do any harm so far... – Álvaro González May 08 '17 at 09:33
  • 1
    @ÁlvaroGonzález yes it is possible, I've been installing CakePHP 2 for a few years via Composer now. Details can be found in the [docs](https://book.cakephp.org/2.0/en/installation/advanced-installation.html#installing-cakephp-with-composer). You will find that some Cake plugins will include a `cakephp/cakephp` requirement, so if you install them via Composer you really need to install the core library via Composer too. – drmonkeyninja May 08 '17 at 09:42
  • 1
    @burzum Most people have messy habits and don't care about project source trees full of junk (and sometimes junk even gets deployed to production and sent to browser) but I'm kind of maniac. When I ask my IDE to open AppController I don't want to decide every time which one is the good one ;-) – Álvaro González May 08 '17 at 09:42
  • 1
    @drmonkeyninja That's most likely the solution—I had overlooked that chapter. The resulting instalation is slightly different (now CakePHP core is a subdirectory in my app rather than the other way round) but it possibly makes more sense. – Álvaro González May 08 '17 at 10:53
  • @ÁlvaroGonzález Then fix the issue: Bad habits and lack of development discipline instead of working around the true issue. :) – floriank May 08 '17 at 11:36

1 Answers1

0

The reason why CakePHP is listed as core dependency in the first place it that it's actually possible to install CakePHP/2.x itself. It's explained in the Advanced Installation chapter.

Apart from the use of Composer, initial set-up needs some additional manual steps that are not required in tarball installations but nothing that is not clearly documented. You also have to use the cake bake shell to create your initial app files (rather than just start typing in already present files), what produces a different structure than you may be used to:

my_project/  My stuff comes here
    <my app files>
    Vendor/
        cakephp/
            cakephp/

... instead of:

my_project/
   <cakephp files>
   app/  My stuff used to be here 

If you opt for traditional (aka manual) installation you are no longer meeting the dependency so it's up to you what to do:

  • Leave it as is and mark the extra copy as ignored in your editor/IDE
  • Delete the dependency from app/composer.json and pray you don't need a library that requires it
Álvaro González
  • 142,137
  • 41
  • 261
  • 360