Shared classes of the Ride framework

1.1.0 2020-03-28 11:16 UTC

This package is auto-updated.

Last update: 2020-11-28 12:39:41 UTC


Shared classes of the PHP Ride framework.

What's In This Library


Decorators are used to convert values from one context into another. They should only act when the incoming value is handable.

Check this code sample:


use ride\library\decorator\DateFormatDecorator;
use ride\library\decorator\StorageSizeDecorator;
use ride\library\decorator\VariableDecorator;

// decorate dates into a formatted date
$decorator = new DateFormatDecorator();
$result = $decorator->decorate(1372582573); // 2013-06-30
$result = $decorator->decorate(new DateTime('30 June 2013')); // 2013-06-30

// decorate byte values into human readable format
$decorator = new StorageSizeDecorator();
$result = $decorator->decorate(5000); // 4.88 Kb

// decorate variables into a output string
$decorator = new VariableDecorator();
$result = $decorator->decorate(null); // 'null'
$result = $decorator->decorate(true); // 'true'
$result = $decorator->decorate(array('key' => 'value')); // '["key" => "value"]'
$result = $decorator->decorate($decorator); // 'ride\library\decorator\VariableDecorator'


The autoloader of the Ride framework is a PSR-0 autoloader.

It handles class names like:

  • ride\library\Autoloader: checked as ride/library/Autoloader.php
  • ride_library_Autoloader: checked as ride/library/Autoloader.php and ride_library_Autoloader.php

Check this code sample:


use ride\library\Autoloader;
use ride\library\StringHelper;


$autoloader = new Autoloader();
$autoloader->addIncludePath('application/src'); // last added path will be checked first

// go and use some classes
$string = StringHelper::generate();

Error Handler

The error handler of the Ride framework simply converts handable errors into exceptions.

Check this code sample:


use ride\library\ErrorHandler;

$errorHandler = new ErrorHandler();

try {
    $tokens = explode(null);
} catch (Exception $e) {
    // ErrorException thrown

String Helper

The string helper comes in handy when processing values.


use ride\library\StringHelper;

$string = "Let's create a stràngé STRING";
$result = StringHelper::safeString($string); // 'lets-create-a-strange-string'
$result = StringHelper::safeString($string, '_', false); // 'Lets_create_a_strange_STRING'
$result = StringHelper::startsWith($string, array('yes', 'no')); // false
$result = StringHelper::startsWith($string, array('yes', 'no', 'Let')); // true
$result = StringHelper::startsWith($string, 'let'); // false
$result = StringHelper::startsWith($string, 'let', true); // true
$result = StringHelper::truncate($string, 12); // 'Let's...'
$result = StringHelper::truncate($string, 12, '...', true); // 'Let's cre...'
$result = StringHelper::generate(10); // a random string of 10 characters


A timer can be used to track time of actions. It has a detail of microseconds.


use ride\library\Timer;

$timer = new Timer();
$time = $timer->getTime(); // get the current time and keep on going
$time = $timer->getTime(true); // get the current time and reset


You can use Composer to install this library.

composer require ride/lib-common