Question

My project consist of multiple bundles some of them are necessary and some i will be using on specific servers. now i need to add dependencies for a non-required bundle. i feel its a waste to add it as a project dependency in the main composor.json since i might not use that code if i don't use the bundle.

is it possible to have a composer.json file inside that bundle? if it's not possible how can i handle my case ?

Example

src/
   Project/
      RequiredFirstBundle/
      RequiredSecondBundle/
      Non-RequiredBundle/
              composor.json 

I tried:

//Path: src/Project/Non-RequiredBundle/composer.json

{
    "name": "project/non-requiredbundle",
    "description": "desc",
    "type": "symfony-bundle",
    "license": "MIT",
    "authors": [
        {
            "name": "name",
            "email": "email"
        }
    ],
    "require": {
        "symfony/framework-bundle": "~2.2",
        "another/dependency": "*"
    },
    "autoload": {
        "psr-0": { "Project\\Non-RequiredBundle": "" }
    },
    "target-dir": "Project/Non-RequiredBundle"
}

but i don't see that the file is used when i execute composer.phar update

Thanks

Was it helpful?

Solution

If I understand you correctly, you are thinking about either having ONE software version containing everything and deploy it everywhere, or have MULTIPLE versions with different dependencies deployed on that software's individual server.

I don't think the reason should be to save a few bytes on the harddrive.

But composer cannot help you with this. In fact, you are forced to include any dependency you want to use somewhere in that composer.json to make Composer include it in the autoloader.

I'd go with the "one version fits all" and simply include whatever dependency is needed. There is no need to worry about deploying software parts that are unused. You will do that all the time, even with the parts you think users will use.

OTHER TIPS

If you want to share some of your bundles you should develop them as vendorbundles like those from third partys. Therefore you should create a Version-Control repository for each of your bundles and add a composer.json for each bundle. To make your bundles available for the symfony composer-file you need to add your VersionControl url as a Resource. It might look something like this:

"repositories": [
    {
        "type": "vcs"
        "url": "https://github.com/igorw/monolog"
    }
],

Happy coding :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top