icanboogie/common

Common helpers and classes for ICanBoogie

Installs: 8 457

Dependents: 15

Watchers: 1

Open Issues: 1

Language: PHP

v1.2.2.1 2014-10-21 12:06 UTC

README

Release Build Status HHVM Code Quality Code Coverage Packagist

This package provides basic classes and helpers shared by many ICanBoogie packages. It provides offset exceptions, property exceptions, some interfaces, and helpers to transform strings and arrays.

Exceptions

Offset exceptions

The following exceptions related to array offset are defined by the package:

Property exceptions

The following exceptions related to object properties defined by the package:

<?php

use ICanBoogie\PropertyNotDefined;

class A
{
    private $id;

    public function __get($property)
    {
        if ($property == 'id')
        {
            return $this->id;
        }

        throw new PropertyNotDefined(array($property, $this));
    }
}

Interfaces

The following interfaces are defined by the package:

  • ToArray: Should be implemented by classes whose instances can be converted into arrays.
  • ToArrayRecursive: Should be implemented by classes whose instances can be converted into arrays recursively.
<?php

use ICanBoogie\ToArray;
use ICanBoogie\ToArrayRecursive;

class A implements ToArrayRecursive
{
    public function to_array()
    {
        return (array) $this;
    }

    public function to_array_recursive()
    {
        $array = $this->to_array();

        foreach ($array as $key => &$value)
        {
            if ($value instanceof ToArrayRecursive)
            {
                $value = $value->to_array_recursive();
            }
            else if ($value instanceof ToArray)
            {
                $value = $value->to_array();
            }
        }

        return $array;
    }
}

Traits

For PHP5.4 users, the ToArrayRecursiveTrait trait can be used to define the to_array_recursive() method.

<?php

use ICanBoogie\ToArray;
use ICanBoogie\ToArrayRecursive;

class A implements ToArrayRecursive
{
    use ToArrayRecursiveTrait;

    public function to_array()
    {
        return (array) $this;
    }
}

Requirement

The package requires PHP 5.3 or later.

Installation

The recommended way to install this package is through Composer. Create a composer.json file and run php composer.phar install command to install it:

$ composer require icanboogie/common

Cloning the repository

The package is available on GitHub, its repository can be cloned with the following command line:

$ git clone git://github.com/ICanBoogie/Common.git

Documentation

The package is documented as part of the ICanBoogie framework documentation. You can generate the documentation for the package and its dependencies with the make doc command. The documentation is generated in the docs directory. ApiGen is required. You can later clean the directory with the make clean command.

Testing

The test suite is ran with the make test command. Composer is automatically installed as well as all dependencies required to run the suite. You can later clean the directory with the make clean command.

The package is continuously tested by Travis CI.

Build Status

License

icanboogie/common is licensed under the New BSD License - See the LICENSE file for details.