Documentation Tools
Handy modules
Dates, money, strings, images, email, logs, files and editable texts.
All modules live in olala/modules/, belong to the olala\modules namespace
and are loaded automatically on first use. Modules you don't use cost nothing.
date — localized dates
Formatting via ICU (requires the intl extension). The time zone comes from the timezone setting. Out of the box, month and weekday names are in Russian (the locale is set by setlocale() in index.php).
use olala\modules\date;
date::format('d MMMM yyyy', time()); // 28 сентября 2026
date::format('EEEE, HH:mm', time()); // понедельник, 14:30
date::$months[9]; // 'Сентября'
date::$weekDays[1]; // 'пн'Format patterns are described in the ICU documentation.
money — amounts
use olala\modules\money;
money::format(1250000); // '1 250 000'
money::format(1990.5, 2); // '1 990.50'
money::format(990); // 990 — short numbers aren't formatted
money::getDiscountVal(['oldPrice' => 5000, 'newPrice' => 3990]); // -20 (discount percentage)stringTools — strings
| Method | What it does |
|---|---|
translit($text) | Cyrillic-to-Latin transliteration for URLs: 'Привет мир' → 'privet_mir' |
truncate($s, $len = 30) | cuts a long string and appends ... |
filterAlNum($s) | keeps only Latin letters and digits |
randString($len = 32) | a random string |
getVersion() | site version from site/VERSION or the git commit in site/.git |
bundledJs($path, $name) | JS file URL with browser cache busting by version |
jsEncode($data) | data for passing to JS: JSON in base64 |
image — image thumbnails
Creates a scaled-down copy of an image once and then serves the ready file. Requires the cwebp (for WebP) and ImageMagick convert (for PNG) utilities.
<?php
use olala\modules\image;
// width 400, the thumbnail is saved to /img/preview/product/15/…
$src = image::preview('img/products/15.jpg', 400, 0, 'product', 15);
?>
<img src="<?= $src ?>" alt="">The height is calculated from the original's proportions. The sixth parameter $format = 'base64' returns a data URI instead of a path.
email — sending mail
Sends via SMTP using PHPMailer — put the library in libs/PHPMailer in the site root.
SMTP parameters are taken from editable texts (see below): email_host, email_port,
email_login, email_pass, email_sender.
use olala\modules\email;
// right away
email::send([
'to' => 'client@example.com',
'subject' => 'Order received',
'message' => $this->render('mail/order', ['order' => $order]),
]);
// via a queue in the store.emails table — the page doesn't wait for SMTP
email::sendBackground([...]);
// in a cron script: send what has piled up (up to 4 attempts per email)
email::backgroundSender();Log — error log
use olala\modules\Log;
try {
Payment::charge($order);
} catch (\Exception $e) {
Log::error(Log::parseException($e)); // message, file, GET/POST, session, stack trace
}Entries go into the site.logs table. The core itself writes all uncaught exceptions there.
editable\text — texts from the database
Small texts (the phone number in the header, company details, mail settings) can be stored in the site.items table and changed without touching the code. All values are cached in a single file, cache/textItems.json.
use olala\modules\editable\text;
text::display('footer_address'); // with line breaks replaced by <br>
text::raw('phone'); // as is
text::set('phone', '+1 555 000-0000'); // save and reset the cachefiles and git
| Method | What it does |
|---|---|
files::copy_dir($src, $dst) | copies a folder recursively |
files::remove_dir($dir) | deletes a folder recursively |
files::realpath($path) | normalizes a path with . and .. without touching the disk |
git::lastCommitDate() | date of the last commit in site/ — e.g. for the Last-Modified header |
request
request::getPath() — the current path without the query string, request::getUrl() — the request URL.