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
- PHP - Including External Packages
- Private PHP Packages - Setup Your Own Satis Server
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
Responsibilities of these folders.
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""download
alternative link download