sclable / php-toolbox
A set of small and useful helpers you should not miss in your project.
Requires (Dev)
- evert/phpdoc-md: ^0.1.1
- phing/phing: ^2.13
- phpdocumentor/phpdocumentor: ^2.8
- phpunit/phpunit: ^4.8
- sclable/coding-standards: ^0.1.0.2
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.
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 DocumentationThe API Documentation of the Range object is located here.
ExampleRe-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 DocumentationThe API Documentation of the ArrayColumn object is located here.
ExampleExtract 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 DocumentationThe API Documentation of the ObjectColumn object is located here.
ExampleExtract 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 DocumentationThe API Documentation of the Initials object is located here.
ExampleGet 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