PHP code example of ride / lib-common

1. Go to this page and download the library: Download ride/lib-common library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ride / lib-common example snippets




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

// decorate dates into a formatted date
$decorator = new DateFormatDecorator();
$decorator->setDateFormat('y-m-d');
$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'



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

e1/src');
$autoloader->addIncludePath('module2/src');
$autoloader->addIncludePath('application/src'); // last added path will be checked first
$autoloader->registerAutoloader();

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



use ride\library\ErrorHandler;

$errorHandler = new ErrorHandler();
$errorHandler->registerErrorHandler();

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



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



use ride\library\Timer;

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