Skip to content

arenowebdev/presentation-composer

Repository files navigation

Introduction To Composer

http://presentations.wsi-services.com/PHPaaSA/Composer-Introduction/#/0/16

Presentation Outline

What I Want to Cover

What is it Dependency manager, NOT package manager Inspired by Ruby's Bundler and Node's npm Cross-platform compatible (requires >= PHP 5.3.2 optionally a VCS)

Why you should use it Your project has dependencies Those dependencies have dependencies Unzipping files sucks Updating those dependencies manually sucks Manually requiring those dependencies sucks You specify your project needs in writing

Installing it Locally curl -sS http://getcomposer.org/installer | php

Globally
    curl -sS https://getcomposer.org/installer | php
    mv composer.phar /usr/local/bin/composer

Using it Basics composer [screenshot]

    `composer --version`
        [screenshot]

    `composer self-update`
        [screenshot]

Finding Packages
    packagist.org

Project Setup
    All composer projects utilize a composer.json file in the root directory of the project. You can write it manually, or utilize the command line to create it for you.
    Command Line
        `composer init`
            [screenshot]
            (walk through each step:)
            * Package name (<vendor>/<name>)
            * Description:
            * Author:
            * Minimum Stability:
            * License:
            * Would you like to define your dependencies (require) interactively?
            * Would you like to define your dev dependencies (requiredev) interactively?

    What you end up with / Manually
        {
            "name": "Mosher/ComposerPresentation",
            "description": "Description of our project",
            "license": "proprietary",
            "authors": [
                {
                    "name": "David Mosher",
                    "email": "[email protected]"
                }
            ],
            "require": {
                "laravel/framework": "4.0.*"
            },
            "require-dev": {
                "mockery/mockery": "dev-master@dev"
            }
        }

    Break down require and require dev along with version constraints
        Exact version:
            `"require": {
                "laravel/framework": "4.0.0"
            }`
        Wildcard version:
            `"require": {
                "laravel/framework": "4.0.*"
            }`
            (equivalant to >= 4.0, < 4.1)
        Range of versions:
            `"require": {
                "laravel/framework": ">=4.0.0"
            }`
            (valid values: >, >=, <, <=, !=)
        Special stuff - Tilde:
            `"require": {
                "laravel/framework": "~4.0.0"
            }`
            (equivalant to >= 4.0.0, < 4.1.0)

    You can also utilize packages hosted in version control...public or private repos!
        {
            "name": "Mosher/ComposerPresentation",
            "require": {
                "": ""
            },
            "repositories": [
                {
                    "type": "vcs",
                    "url": "https://[email protected]/dmosher/composer-presentation.git"
                }
            ]
        }

    Virtual Packages
        You are also able to make sure components that aren't installable by Composer are present on the system.

        * php - Allows you to apply constraints on the PHP version
            `{
                "require": {
                    "php": ">=5.3.2"
                }
            }`
        * ext-<name> - Allows requiring of PHP extensions
            `{
                "require": {
                    "extcurl": "*"
                }
            }`
        * lib-<name> - Allows version constraints of PHP libraries
            `{
                "require": {
                    "libpcre": ">=7.8"
                }
            }`

    Autoloading
        There are currently three ways to auto-load files in PHP:
            1. PSR-0 (PSR-4...)
                `"autoload": {
                    "psr0": { "Mosher\\ComposerPresentation\\": "src/" }
                }`
            2. Classmap
                `"autoload": {
                    "classmap": [ "lib/", "ext/library.php" ]
                }`
            3. Files
                `"autoload": {
                    "files": [ "ext/functions.php" ]
                }`

    Install & Update
        `composer install`
        `composer update`

        This reads from composer.lock from the current directory if it exists
        else it reads composer.json
        It then resolves all dependencies
        Creates and updates composer.lock with exact version info
        Installs / Updates packages in /vendor
        The vendor directory defaults to /vendor in the root of the project, but you can change this behavior with the vendor-dir option
            `{
                "vendordir": "packages"
            }`

Let's Build Something Quickly
    `composer create-project laravel/laravel composer-presentation`

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages