Hello everyone!

We have been investing plenty of personal time and energy for many years to share our knowledge with you all. However, we now need your help to keep this blog running. All you have to do is just click one of the adverts on the site, otherwise it will sadly be taken down due to hosting etc. costs. Thank you.

If you follow the example below you can create an application independent composer package and use it in applications. This is a very basis example so you can enhance it based on your needs.


Structure


src
Helper
HelloHelper.php
.gitignore
.php_cs
build.xml
composer.json
composer.phar
Readme.md

composer.json


{
"name": "inanzzz/hello-util",
"description": "I say hello!",
"type": "library",
"autoload": {
"psr-4": {
"Inanzzz\\HelloUtil\\": "src"
}
},
"require": {
},
"require-dev": {
"phing/phing": "2.11.0",
"friendsofphp/php-cs-fixer": "2.0.*@dev"
},
"config": {
"bin-dir": "bin"
},
"minimum-stability": "stable"
}

HelloHelper.php


namespace Inanzzz\HelloUtil\Helper;

class HelloHelper
{
public function sayHello()
{
return 'Hello!';
}
}

.gitignore


bin
vendor
composer.lock

.php_cs


return PhpCsFixer\Config::create()
->setUsingCache(false)
->setRules([
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => true,
])
->setFinder(
PhpCsFixer\Finder::create()
->exclude(['bin', 'vendor'])
->in(__DIR__)
);

build.xml


<?xml version = "1.0" encoding = "UTF-8"?>

<project name="hello-util" default="build">

<fileset id="src-files" dir=".">
<include name="**/*.php" />
<include name="*.php" />
<exclude name="vendor/**" />
</fileset>

<target name="build" depends="clean, composer, php-cs-fixer" />

<target name="clean" description="Cleaning in progress ...">
<delete file="composer.lock" quiet="true"/>
</target>

<target name="composer" description="Composer update ...">
<exec logoutput="true" checkreturn="true" passthru="true" command="composer self-update" dir="./" />
<exec logoutput="true" checkreturn="true" passthru="true" command="composer install" dir="./" />
</target>

<target name="php-cs-fixer" description="Checking coding standard ...">
<exec executable="php" passthru="true" checkreturn="true">
<arg value="bin/php-cs-fixer"/>
<arg value="fix"/>
<arg value="--dry-run"/>
<arg value="--verbose"/>
<arg value="--diff"/>
</exec>
</target>
</project>

Test


# Install vendors
$composer install

# Run PSR coding standards tests
$ bin/phing php-cs-fixer