Use Composer to Manage Your Library Dependencies for Php
If you use npm for Node, pypi for Python, or bundler for ruby, you will want to use composer, if you still use PHP.
To get started, install as per instruction.
For Mac, it will be a few brew
commands.
1 2 |
|
If you have some errors, you might need to brew install php53-intl
, brew update
and brew doctor
. I have to do that for some weird errors.
Next, prepare a basic composer.json
in your root directory. The below json is an example of a project that requires monolog.
1 2 3 4 5 |
|
Install the library and it’s dependencies (monolog in this example).
1 2 |
|
A vendor
directory will be created and it contains all the libraries. You can start using the libraries as per normal.
Or use autoload.
For developers with library/SDK to share..
If you have your library/SDK and you want to upload to composer repository, create a composer.json
in your project root directory.
Here’s one for reference.
Then go to packagist, register an account, and point it to your repository.