Reputation: 23883
I would like my CakePHP project to use best practices. Currently we have our PHP dependencies checked into our project's repo, and i don't like that.
I want the project to leverage Composer, but i don't understand the proper strategy.
First, there is the official CakePHP repo:
composer.json
is in the project root./vendors/
and /plugins/
and they are under .gitignore
./app/Vendor/
and /app/Plugin/
are not ignored.Then, there's an app-template boilerplate from FriendsOfCake:
composer.json
is in the project root./vendors/
or /plugins/
./app/Vendor/
and /app/Plugin/
are under .gitignore
.Lastly, there's cakephp-composer, an active project. It implies that:
composer.json
is in /app/
./app/Plugin/
..gitignore
strategy, but plugin author says that /app/Vendor/
and /app/Plugin/
should be ignored.cakephp-composer is the weirdest thing. How am i supposed to fetch CakePHP and cakephp-composer after cloning my project?
I want to achieve the following:
I don't understand and request explanations for the following things:
.gitignore
?composer.json
to fetch plugins with Composer, especially if i don't use cakephp-composer? It might be as simple as just mentioning package names under require
, but how do i tell Composer whether plugins should go under app/Vendor/
and app/Plugin/
? Oh, and where should they go?For an example CakePHP plugin to be fetched by Composer, take haml. It's what i need for my frontend work and it has its own Composer dependency.
Upvotes: 3
Views: 3372
Reputation: 13952
OK, there's several questions there... I'll try to answer a few.
First and foremost, you should be clear on wether you want to use CakePHP 2.X, or CakePHP 3.0. I assume since you're talking about an existing project, you mean Cake 2.X - which wasn't built with composer in mind. Cake 3.0 was built with composer in mind, so if upgrading to that is an option, I assume it'll be nicer (I haven't used 3.0 yet myself)
Here's a simplified example composer.json
file from one of my projects:
{
"name": "my-project",
"require": {
"cakedc/migrations": "2.2.2",
"cakephp/debug_kit": "2.2.1",
},
"require-dev": {
"phpunit/phpunit": "3.7.*"
},
"config": {
"vendor-dir": "app/Vendor/"
},
"extra": {
"installer-paths": {
"app/Plugin/Migrations": ["cakedc/migrations"],
"app/Plugin/DebugKit": ["cakephp/debug_kit"],
}
}
}
see the line "vendor-dir": "app/Vendor/"
- that's where I've configured composer to put it's packages, by default, in my app/Vendor/
folder.
What goes in .gitignore... we'll come back to that.
No, you don't need this.
See the line "installer-paths": {
? That's where I've configured composer to put specific CakePHP plugins in Cake's plugins dir, as opposed to the default app/Vendor/
which I mentioned in 1.
For CakePHP Plugins - see 4. For CakePHP itself, I haven't personally done it. I did try at one point and found the setup to be not playing nicely with one of my plugins, so I gave up on it. However, you should be able to use the same principals as above.
Now, coming back to 2. what should be in your .gitignore? Anything that has contents completely maintained by composer - in my case, that's app/Vendor/
, and app/Plugin/
. That assumes that ALL the contents of those folders is maintained by composer. If you had eg. one plugin that you'd added manually, then you couldn't ignore the whole folder - you'd have to ignore only the specific plugins installed with composer.
PS - I personally delete the root vendor/
and plugins/
folders - I don't use them at all.
Upvotes: 4