I'm using Composer for a project that needs to handle some dependencies but I got a really weird issue. Composer is ignoring the composer.json file contained in child packages.
My project needs to retrieve some custom zip packages, in these packages a composer.json file defines other requirements. The repositories of these requirements are declared in the root composer.json file since Composer cant recursively fetch repositories.
The thing is that after my zip package is downloaded, unpacked and placed in the vendor dir, composer totally ignores its composer.json where other requirements are defined...
The zip archive is something like this:
To give you an idea this is how my root composer.json looks like:
{
"name": "myproject/project",
"type": "library",
"repositories": [
{
"packagist" : false
},
{
"type": "package",
"package": {
"name" : "giulianobundles/mybundle",
"version" : "1",
"dist": {
"url": "http://url/to/zip/file",
"type": "zip"
}
}
},
{
"type": "package",
"package": {
"name" : "giulianobundles/mybundlerequirement",
"version" : "1",
"dist": {
"url": "http://url/to/zip/file",
"type": "zip"
},
}
},
],
"require": {
"php": ">=5.3.2",
"giulianobundles/mybundle": "*"
},
"autoload": {
"psr-0": {
"config": "./"
}
},
}
and the bundle's composer.json package looks like
{
"name": "giulianobundles/mybundle",
"type":"library",
"require": {
"giulianobundles/mybundlerequirement": "1"
}
}
Mybundle package get succesfully installed but its composer.json file is totally ignored. Any idea? What am I missing?
composer. json is a JSON file placed in the root folder of PHP project.
To configure Composer for your PHP app json file specifies required packages. Verify that a composer. json file is present in the root of your git repository. Run composer install (on your local machine) to install the required packages and generate a composer.
Indeed, Composer will not recursively look at composer.json files in the file system. It needs to see the composer.json files in the repository. The way it usually works is that a package has a git or svn URL somewhere. Composer will fetch, for instance, git://<host>/<package>/composer.json
directly from the repository to figure out that package's dependencies before it's even installed to calculate the overall dependencies.
In your case, you are defining a package
inline in your own composer.json file. This is used instead of a composer.json file in the dependency. This means Composer takes the "package": { ... }
to be the canonical composer.json file for that package, it will not look into the code itself; especially not after unpacking it. It treats the Zip file as if it had no composer.json file of its own.
Define the dependencies in the "package": { ... }
or host the code in a version control system from which Composer can fetch the composer.json file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With