Question

I have a Symfony 2.3 project and I would like to use a custom vendor. I know that on Symfony versions 2.1 and 2.2, you can declare vendors in the deps file.

But how can I declare a custom vendor in Symfony 2.3 project? There is a composer.json file, but I don't really understand how it works.

EDIT:
The custom vendor's code is located on github.

Was it helpful?

Solution

composer.json manages dependencies through the composer tool (which you should have installed). It behaves similarly to npm if you have used that at all.

You can include a custom vendor in a couple of ways - although for the custom vendor code to be (auto)loaded & picked up by composer it will need to have a composer.json file.

Packagist

If the custom vendor has successfully submitted their to packagist then you life is easy, you can search for it and take note of the name (in the <vendor>/<package> format.

Open up your composer.json file and at the end of the "require": {} statement add your vendor. For example if our package was called peterjmit/awesome-package

// ...
"require": {
  // ...
  "peterjmit/awesome-package": "*"
},
// ...

You can replace the * with a version number if you wish. Once you have done that, you can run the composer update command to pull in your new package. If you only want to update the new package you can use composer update peterjmit/awesome-package.

Thanks to the composer autoloader, and the PSR-0 standard, classes from the package are auto-loaded so there is no other "plumbing" for you to do.

VCS repository

If the custom vendor is not on packagist, but does have a composer.json file then you can specify a custom repository to composer. You need to have the same require statement as before, but you need to add a new statement to composer.json

// ...
"require": {
  // ...
  "peterjmit/awesome-package": "*"
},
"repositories": [
  {
    "type": "vcs",
    "url": "git@bitbucket.org:peterjmit/awesome-package.git"
  },
  // .. etc.

If the package does not have a composer.json then you can always fork it and add your own. But if the code does not conform to PSR-0 then you will have to sort out your own auto-loading strategy for the package.

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