PHP Composer: Import external repositories

Supose we are working on a project that requires a dependency made for you or other developer but it is not listed on packagist, you just want import a repository from a github link or a local path. Luckly this is a very easy taks to do! Just open you composer.json file and type:

Import from a github repostory

"repositories": [
        {
            "type": "vcs",
            "url" : "git@github.com:owner/package-name.git"
        }
    ],

Import from a local path

In this case, we are creating a link to the path of our repository, as soon as we change de repository files, it will be instantly updated in our project.

"repositories": [
        {
            "type": "path",
            "url" : "/home/gustavo/path/project",
            "options": {
                "symlink": true
            }
        }
    ],

Now that we have our repository listed in our composer.json file, just require de package:

composer require ownder/my-package-name

Autoload

Remember that in your package you should always set the autoload directives accordingly to psr-4 standard, this same namespace should be used to import you repository at the new project that imported the package.

Deixe um comentário

O seu endereço de e-mail não será publicado. Campos obrigatórios são marcados com *