sclable/php-toolbox

This package is abandoned and no longer maintained. No replacement package was suggested.

A set of small and useful helpers you should not miss in your project.

0.0.4.2 2016-03-02 12:42 UTC

This package is not auto-updated.

Last update: 2016-06-29 12:30:00 UTC


README

A set of small and useful helpers you should not miss in your project.

Build Status Latest Stable Version Total Downloads Latest Unstable Version License

Usage

Installation with BOB

To use this library in your Sclable Business Application Development Platform project, ask BOB (BOB Our Builder) to add the package:

# add dependency
bob package-add sclable-php-toolbox

# download & install
bob build

Installation with Composer

If you'd like to include this library in your project with composer, simply run:

composer require "sclable/php-toolbox"

Tools

Range

Create ranges of an arbitrary length derived from a custom base range.

API Documentation

The API Documentation of the Range object is located here.

Example

Re-index your array with upper case letters from A - Z:

$values = range(1,32); // integers from 1 to 32
$range = new Range();  
$range->upper();
$result = $range->combine($values);

var_dump($result);

/* prints 
array(32) {
  'A' => int(1)
  'B' => int(2)
  [...]
  'AE' => int(31)
  'AF' => int(32)
}
*/

ArrayColumn

API Documentation

The API Documentation of the ArrayColumn object is located here.

Example

Extract the key and the value for the array element from a multidimensional array:

$data = [
    ['id' => 1, 'column' => 'a'],
    ['id' => 2, 'column' => 'b'],
    ['id' => 3, 'column' => 'c'],
];
$result = ArrayColumn::create()
    ->index('id')
    ->data('column')
    ->from($data)
    ->get();

var_dump($result);

// array(3) {
//    [1] => string(1) "a"
//    [2] => string(1) "b"
//    [3] => string(1) "c"
// }

ObjectColumn

API Documentation

The API Documentation of the ObjectColumn object is located here.

Example

Extract the key and the value for the array element from an object property:

$data = [
    (object) ['id' => 1, 'column' => 'a'],
    (object) ['id' => 2, 'column' => 'b'],
    (object) ['id' => 3, 'column' => 'c'],
];
$result = ObjectColumn::create()
    ->from($data)     // the list of objects
    ->assignById()    // a shortcut for ->assignBy('id')
    ->with('column')  // the object property containing the data
    ->get();

var_dump($result);

// array(3) {
//    [1] => string(1) "a"
//    [2] => string(1) "b"
//    [3] => string(1) "c"
// }

Initials

API Documentation

The API Documentation of the Initials object is located here.

Example

Get the initials for any text:

$initials = new Initials( 'Sclable Business Application Development Platform' );

echo $initials;
// echo 'SB'

echo $initials->setLength(5);
// echo 'SBADP'
$initials = new Initials( 'sclable-domain-designer' );

echo $initials->setLength(3)->setCase(Initials::CASE_SENSITIVE)->addSeparator('-');
// echo 'sdd'

License

For the license and copyright see the LICENSE file