Getting Started
Maybe is a PHP library for explicit and predictable business logic. It combines five building blocks:
Option<T>— safe flow for optional valuesResult<T, E>— typed success/error without exceptions as control flowSchema— immutable parsing and validationDTO— validated mapping for input objectsAsync— concurrent execution via processes (proc_open), focused on PHP 7.4 + Windows + CodeIgniter 3
Requirements
- PHP
>= 7.4 - Composer
Installation
bash
composer require gabrielalmir/maybeFirst steps
If you work in a corporate or legacy environment, start with Schema, DTO and Result before adopting Async:
php
use Maybe\Schema\Schema;
$schema = Schema::shape([
'email' => Schema::string()->trimmed()->min(5),
'age' => Schema::int()->min(18),
]);
$result = $schema->safeParse([
'email' => ' user@example.com ',
'age' => 23,
]);
$result->match(
fn (array $data) => saveUser($data),
fn ($errors) => respondWithErrors($errors->toArray())
);Functional helpers
The following namespaced functions are auto-loaded:
- Option/Result:
some(),none(),fromNullable(),ok(),err() - Schema:
stringSchema(),intSchema(),boolSchema(),dateSchema(),enumSchema(),arraySchema(),objectSchema(),optionSchema() - Async:
async(),await()
Where to go next
- Tutorial — build a validated create-customer flow end to end
- Why Maybe? — the case against
nulland exceptions, and how Maybe compares - API Reference — every signature in one place
- Option — optional values without null checks
- Result — error handling as data
- Schema — validation and parsing
- DTO — validated input objects
- Async — process-based concurrency
- CodeIgniter 3 — integrating with legacy CI3 apps
- Incremental Migration — adopting Maybe in an existing codebase