How to use a local directory as a dependency?

Asked

Viewed 133 times

2

I am designing a relatively large project in my company that consists of several packages in PHP. Some of these packages are normal packages and others are Bundles of Symfony applications.

When we work with Composer, we usually name a dependency the branch or version to use - however, this dependency usually has to be on Github and listed in Packagist. (this is the normal flow, although there are alternatives)

In my case, I still don’t want to have to commit any code, so the dependencies need to be local directories. I’ve already set the file composer.json of dependency so:

{
    "name": "rodrigorigotti/shared"
    "autoload": {
        "psr-0": {
            "RodrigoRigotti": "src/"
        }
    }
}

And the project that contains this dependency is with the composer.json that way:

{
    "name": "rodrigorigotti/app",
    "repositories": [
        {
            "type": "vcs",
            "url": "/var/www/rodrigorigotti/shared"
        }
    ],
    "require": {
        "php": ">=5.3.3",
        "symfony/symfony": "~2.4",
        "rodrigorigotti/shared": "*"
    },
    "autoload": {
        "psr-0": { "": "src/" }
    },
}

(note: the files composer.json are WELL simplified for the purpose of the question)

However, when rotating the command composer install or composer update in the application that has the dependency, I have received this error:

[InvalidArgumentException]                                        
No driver found to handle VCS repository /var/www/rodrigorigotti/shared

Does anyone know how to solve?

  • I use Satis to manage these packages: https://blog.adlermedrado.com.br/configurando-um-reposit%C3%B3rio-privado-usando-Composer-e-satis-f7a32fd4f804#. ou1oep27y adds the repository to Composer and use it normally as if it were in packagist. Some additional settings in Composer may be required such as: "config": { "Secure-http": false, "disable-tls": true }, if Satis is not on a server using https

1 answer

0


Dscobri. The directory to be used as a dependency needs to be a Git project (git init), even if I’m not in any remote repository. Then just commit.

In addition, you must reference the correct branch or version on composer.json of the project that will contain the other projects:

{
    "name": "rodrigorigotti/app",
    "repositories": [
        {
            "type": "vcs",
            "url": "/var/www/rodrigorigotti/shared"
        }
    ],
    "require": {
        "php": ">=5.3.3",
        "symfony/symfony": "~2.4",
        "rodrigorigotti/shared": "dev-master"
    },
    "autoload": {
        "psr-0": { "": "src/" }
    },
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.