Skip to content

Instantly share code, notes, and snippets.

@uzyn
Created June 20, 2012 07:00
Show Gist options
  • Save uzyn/2958518 to your computer and use it in GitHub Desktop.
Save uzyn/2958518 to your computer and use it in GitHub Desktop.

About Composer

Composer is a tool for dependency management in PHP. It allows you to declare the dependent libraries your project needs and it will install them in your project for you.

With Packagist, you get access to a vast library of reusable PHP components that will help a lot in your development work.

About this plugin

This is a CakePHP plugin to use Composer conveniently with your CakePHP 2.x project.

There is no need to pre-install Composer.
This plugin will automatically download the latest version if Composer is not installed at your system.

Packages downloaded via this Composer plugin will be installed at APP/Vendor as per CakePHP convention.

Quick links

How to use

  1. Download the plugin and place it at APP/Plugin/Composer.

    Or via Git:

    cd APP/Plugin
    git clone git://github.com/uzyn/cakephp-composer.git Composer
  2. Load the plugin by adding this line to the bottom of your app's Config/bootstrap.php:

    <?php
    CakePlugin::load('Composer', array('bootstrap' => true));
  3. That's all! Composer is ready for use.

    composer.json is located at APP/composer.json. It is automatically created if it is not found.
    Packages are installed to APP/Vendor as per CakePHP convention.
    Invoke Composer from command line with Console/cake composer.composer.

    For example, to install opauth/opauth using Composer's require command.

    cd APP
    Console/cake composer.composer require opauth/opauth:0.*

    To install packages defined at composer.json

    Console/cake composer.composer install
  4. This plugin also makes use of Composer's autoloader.
    Start using a Composer-loaded classes right away without needing require(), include() or App::import().

    For example, to instantiate a new Opauth object, simply instantiate Opauth from anywhere (model, controller, view, literally anywhere) in your CakePHP application:

    <?php
    $Opauth = new Opauth();

Issues & questions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment