Jun 20, 2018
Every development project faces the same two constraints; time and budget. This means that the more project time is spent on maintaining third party code, the less time there is for developers to focus on building what differentiates a project and deliver value. To maximize the production of a development team there needs to be a way to reduce or remove the burden of maintaining third party libraries and code. For PHP projects that use a framework such as Drupal this can be done by using Composer.
Composer is a package manager that can be added to and utilized on any PHP project. Composer takes care of managing all the third party code and dependencies for a PHP project so that developers do not have to. Using it does not require in-depth time commitment or developer training. In fact by learning just five terminal commands any developer can master using Composer.
Composer uses a ‘composer.json’ file to define project metadata, properties and its third party dependencies. This file can be generated using the ‘init’ command. When run, it executes an interactive guide that prompts for property values and initial project dependencies.
The ‘require’ command is used to add dependencies to a project. When run without any parameters it prompts for a keyword search to find matching packages from packagist.org (the official composer package library). When an option is selected Composer downloads the code and any child dependencies to a ‘/vendor’ directory in the project codebase.
For any new developers or C.I. environments, the ‘install’ command is used for downloading all third party dependencies for a project. The command reads the composer.json (or composer.lock) file and downloads all defined packages into the project ‘/vendor’ directory.
The ‘update’ command downloads the latest version of project dependencies. Helpful for retrieving security updates. When run without any additional parameters, Composer will update all defined project dependencies to their latest versions based on the version constraint defined.
When a dependency is no longer required on a project the ‘remove’ command is used. This command deletes the specified package and any dependencies not used by other packages from the `/vendor` directory and composer.json file.
By adding Composer a PHP projects and using these basic commands, developers are able to use their time and budget on what matters most, the custom code/features that differentiates their project.
If you want to learn more about how straight forward it can be to use Composer on your PHP projects, you can catch my upcoming talk Composer 101 next week at the Design4Drupal conference.
Want to figure out how to deliver value while saving time and budget on your next PHP project? Reach out and we can figure out how Genuine can help with that.
- Mike Miles