Creating A PHP Package

You may or may not already be using Packagist in order to create PHP packages. By converting your code into packages, it becomes faster and simpler to develop more complex applications. Since these packages will be re-used, less time will be spent writing and debugging "new" code. One of the best aspects of packages is that they can automatically updated through Composer with a call to

composer update
. This tutorial is going to cover the creation of a "package" repository in SVN that we will reference with a private Satis server, rather than using Packagist ion order to keep our packages private.

Related Posts

Steps

    Create a new repository on your SVN server
    svnadmin create my-repo
    Check the new repository out
    svn checkout svn://my.domain.com/my-repo
    Navigate to within the directory that was just checked out and create the default folders that are expected by the package program trunk,branches, and tags
    cd my-repo
    mkdir trunk
    mkdir branches
    mkdir tags
    Create the src directory this will be referenced later.
    mkdir trunk/src
    Create the composer.json file which provides all the relevant packaging details This must go in the top level of the codebase (e.g. top of trunk or any branch)
    editor trunk/composer.json

    Template

    {
        "name": "[vendor name]/[package name]",
        "type": "library",
        "description": "[description]",
        "keywords": ["log","logging"],
        "homepage": "[project homepage]",
        "license": "none",
        "authors": [
            {
                "name": "[author name]",
                "email": "[author email]",
                "homepage": "[authors website]",
                "role": "[authors role]"
            }
        ],
        "require": {
            "php": ">=5.x.x"
        },
        "autoload": {
            "psr-4": {
                "[vendor name]\\[package name]\\": ""
                "[vendor name]\\[package name]\\": "subfolder1",
                "[vendor name]\\[package name]\\": "subfolder2"
            }
        }
    }
    

    Example

    {
        "name": "Programster/CoreLibs",
        "type": "library",
        "description": "Core libraries for PHP 5.3+",
        "keywords": ["core","library"],
        "homepage": "http://www.programster.blogspot.co.uk",
        "license": "none",
        "authors": [
            {
                "name": "Programster",
                "email": "my.email@gmail.com",
                "homepage": "http://programster.blogspot.co.uk/",
                "role": "Developer"
            }
        ],
        "require": {
            "php": ">=5.3.0"
        },
        "autoload": {
            "psr-4": {
                "Programster\\CoreLibs\\": ""
            }
        }
    }
    
    Add everything to SVN and commit it
    svn add *
    svn commit .
    
    Now all you have to do is add all the actual source code to the trunk directory and commit to SVN!

References

No comments:

Post a Comment