Depending on packages without composer.json in Composer (PHP dependency manager)
Composer is a great way to manage your PHP dependencies. The documentation is still a bit scarce, so you could imagine that it took a while to find out how to add an external dependency (in my case from github) which doesn’t have a composer.json file and is not registered on packagist. There are different solutions, but Composer seems to be under active development and none worked for me.
So – in my project’s composer.json – this is how I’m loading the FOSFacebookBundle:
- Define it as an external repository:
"repositories": {
"symfony-unofficial": {
"type": "package",
"package": {
"name": "fos/facebookbundle",
"version": "2.0",
"source": {
"url": "git://github.com/FriendsOfSymfony/FOSFacebookBundle.git",
"type": "git",
"reference": "origin/2.0"
}
}
}
}
- Add it to your project’s dependencies:
"require": {
...
"fos/facebookbundle": "2.0.*"
}
- And register the (PSR-0 conform) namespace with the autoloader:
"autoload": {
"psr-0": {
"MyBundleNamespace": "src/",
"FOS": "vendor/"
}
}
Et voila! By the way, my composer.json would look like this:
{
"name": "My app",
"description": "My Facebook App",
"repositories": {
"symfony-unofficial": {
"type": "package",
"package": {
"name": "fos/facebookbundle",
"version": "2.0",
"source": {
"url": "git://github.com/FriendsOfSymfony/FOSFacebookBundle.git",
"type": "git",
"reference": "origin/2.0"
}
}
}
},
"require": {
"php": ">=5.3.2",
"symfony/symfony": ">=2.0.10,<2.1.0-dev",
"doctrine/orm": ">=2.1.0,<2.2.0-dev",
"twig/extensions": "*",
"symfony/assetic-bundle": "2.0.*",
"sensio/generator-bundle": "2.0.*",
"sensio/framework-extra-bundle": "2.0.*",
"sensio/distribution-bundle": "2.0.*",
"jms/security-extra-bundle": "1.0.*",
"fos/facebookbundle": "2.0.*"
},
"autoload": {
"psr-0": {
"MyBundleNamespace": "src/",
"FOS": "vendor/"
}
}
}