PHP code example of tihloh / prefab-core
1. Go to this page and download the library: Download tihloh/prefab-core 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/ */
tihloh / prefab-core example snippets
$name = val(' Christian ')->trim()->upper();
$age = val('42')->toInt();
$active = val('true')->toBool()->fallback(false);
$age = val($input)
->toInt()
->fallback(0);
$age = val('42')->toInt()->value();
$name = val($data)
->get('user.profile.name')
->default('Guest');
echo val(12500)->format('currency', ['currency' => 'PHP']);
echo val('09171234567')->format('phone');
$db->table('users')->insert([
'name' => val($_POST['name'] ?? null)->trim()->default('Unknown'),
'age' => val($_POST['age'] ?? null)->toInt()->fallback(0),
]);
$user = $db->table('users')
->where('age', val($_GET['age'] ?? null)->toInt()->fallback(0))
->first();
$host = prefab_env('DB_HOST');
$port = prefab_env('DB_PORT', 3306);
$debug = prefab_env('DEBUG', false);
use Tihloh\Prefab\Core\Environment\Env;
Env::load(__DIR__ . '/.env');
$when = prefab_datetime('2026-09-03 08:30:00');
echo $when->format('datetime');
$when = val('2026-09-03')->toDateTime();
use Tihloh\Prefab\Core\Database\DatabaseManager;
$db = new DatabaseManager(new PDO('sqlite::memory:'));
$rows = $db->table('users')->where('active', 1)->get();
use Tihloh\Prefab\Core\Session\NativeSession;
$session = new NativeSession();
$session->set('user_id', 42);
$id = $session->get('user_id');
use Tihloh\Prefab\Core\Cache\FileCache;
$cache = new FileCache(__DIR__ . '/cache');
$users = $cache->remember('users.all', 300, fn () => loadUsers());
use Tihloh\Prefab\Core\Console\Input;
use Tihloh\Prefab\Core\Console\Output;
prefab_command('user:create', function (Input $input, Output $output) {
$name = $input->argument(0);
$email = $input->option('email');
$admin = $input->flag('admin');
$output->info("Creating {$name}");
}, 'Create a user');
prefab_trace();
prefab_trace_detailed();