You are here:Home»KB»Programming»PHP»My Composer Notes
Tuesday, 12 December 2017 10:42

My Composer Notes

Written by

What is Composer?

This needs to be cleared up for us newbies. and to start with you will come across the following statements which are both true.

  • Composer is not a package manager
  • Composer is a dependency manager

Composer is not a package manager because you are not downloading complete software packages but dependencies/libraries for your own software package.

Composer is a cross-platform software package that can is used to manage libraries for your PHP software project allowing you to install, update and remove libraries/dependencies from a single point reducing the need to manually update all of the dependecies individually which reduces time and makes it easier to keep things upto date. composer calls on its own library to get the latest updates of the various depencies. A vendor of software can make their software available from this library for others to use.

It is composer of the program mentioned above to manage your dependecies and also a small library to control autoloading of classes and other things.

Composer is useful because some packages use mulitple dependancies to get them to work and composer allows you to always get the latest version of all of the packages, or specify package numbers for your project. This process also correctly sets up all the required includes up as needed. This can reduce the time needed to update all of the packages.

The Wonderful World of Composer - YouTube - This is brilliant video that will explain Composer completely.

How does it Work?

  • Installing Windows Composer  does the following
    • Installs Composer
    • Puts the Composer binary into path
    • autodetects your php.exe and allows you to choose which if you have more than one.
  • Files
    • Composer installs all of the libraries usually to a folder called /vendor/ and is controlled by a single JSON text file which is parsed by the particular version of Composer you are using.
    • Each package that is downloaded is registered with the Composer framework.
    • There is sha-1 string for both the whole 'Composer vendor library' and for the inidividual dependencies which are stored in the composer.lock file. this allows the tracking of the various assets to see if they have been updated or just to compare against packages withing the Packagist repository.
    • composer.json - Is the control files used for the composer packages used within your project. This file allows multiple packages to be downloaded and combined
    • The standard folder to use is /vendor/
    • All dependecies will be installed into the vendor folder. they all have a unique name so collisions will not be an issue.
  • Commands
    • Run the command  composer install in the folder where you want you dependencies to be installed and if the composer.json file is present it will use it for instruction.
    • I can install motranslator by navigating to where i want it and typing composer require phpmyadmin/motranslator as you can see this has the require command in the string.
    • This gets the latest stable version of the called software, in the case motranslator - composer require phpmyadmin/motranslator
    • composer require phpmyadmin/motranslator from the Windows commandline will add this dependency to your Composer library, or build a new library if there is not one already there.
  • You only need to include the autoload.php once in your software project and composer will load all dependancies. This is all you need in your PHP project to get Composer.
    require vendor/autoload.php
Read 787 times Last modified on Tuesday, 12 December 2017 12:03