Lately i have been hacking on Opauth and finally was
forced to learn more about composer.
Within the CakePHP community composer has not been adopted really,
composer-installer supports an easy way for installing
Many plugin maintainers have not added
composer.json files to their repositories, as CakePHP itself is not using it as well.
There is no need to stop you from using composer with your CakePHP application. You can install both plugins and 3rd party libraries easily.
Currently you would clone/download required libraries to the
For libraries that support composer install, here is the way to go:
1 2 3 4 5
Note: the following would also work, but would not add the vendor-dir to
This will create a
composer.json file with the required dependencies for your application.
--no-update is needed here to avoid installing directly to the default directory for composer, which is
You can also use the init command for creating the composer.json, only make sure you have configured the
When running install it would produce the following output
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
The opauth/twitter package had its own dependency on tmhOAuth, which will automatically get installed as well.
Besides installing the libraries to the
app/Vendor/ directory it also has generated
app/Config/bootstrap.php you will import the autoload file so you can instantiate all vendor classes directly
Opauth would be instantiated in your UsersController.php
Install cakephp-plugin with composer
1 2 3 4 5 6 7 8 9
Now the CakePdf plugin has been installed in app/Plugin/CakePdf
You can also run an interactive composer console
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
Check Packagist for more composer packages
One day you can’t imagine how you ever could live without a decent dependency manager for your PHP projects. I’m totally hooked on composer