How to make a package that works with Composer and Packagist, following PSR-0.

Composer

The Composer is an awesome tool for PHP dependency management. It's useful both for building software as well as for maintaing your own packages (open-source or not).

Composer for your Applicaton

Crazy simple here, bring in composer, & define a bunch of stuff you require. Simply start composer and follow the prompts. Enter "proprietary" for License and "stable" for

curl -sS https://getcomposer.org/installer | php
./composer.phar init

Package name (/) [atom/composer]: edoceo/composer-demo
Description []: A demo of Composer
Author [edoceo ]: 
Minimum Stability []: stable 
License []: proprietary

{
    "name": "edoceo/composer-demo",
    "description": "A demo of Composer",
    "license": "proprietary",
    "authors": [
        {
            "name": "edoceo",
            "email": "code@edoceo.com"
        }
    ],
    "minimum-stability": "stable",
    "require": {

    }
}

Composer for your Packages

{
    "name": "edoceo/radix",
    "type": "library",
    "description": "Simple MVC and Toolkit for Rapid Application Prototyping",
    "keywords": ["mvc","toolkit"],
    "homepage": "http://radix.edoceo.com/",
    "license": "MIT",
    "authors": [
        {
            "name": "David Busby",
            "email": "code@edoceo.com",
            "homepage": "http://edoceo.com/",
            "role": "Developer"
        }
    ],
    "require": {
        "php": ">=5.4.0",
        "ext-apc": "*"
    },
    "autoload": {
        "psr-0": {
            "radix\\": "",
            "edoceo\\radix\\": ""
        }
    }
}

And the composer tool can validate this file for you.

php composer.phar validate

Packagist

Create an account at packagist.org and then point them to your project.

It's best to create a proper version for your project.

git tag ....
git push tag

How visit your Packagist profile and Submit a Package.

About PSR-0

PSR-0 and Packagist and Composer rely on this system for vendor supplied auto-loading. It's best to read-up the official documentation on this. A quick overview is that you have to use proper namespaces with your class names. And the autoloader builds directories from said namespace and class names.



See Also