reflexive / core
Lazy PDO connection and some enums…
Requires
- php: ^8.4
- composer-runtime-api: ^2.0.0
Requires (Dev)
- phpunit/phpunit: ^13.1
- vimeo/psalm: ^6.0
This package is auto-updated.
Last update: 2026-06-10 22:26:58 UTC
README
$$ {{∀ x ∈ X : x R x}} $$
Shared building blocks for the Reflexive PHP packages.
This package contains:
Reflexive\Core\Database: a lazyPDOwrapper that opens the connection on first real use.Reflexive\Core\ConditionandReflexive\Core\ConditionGroup: abstract condition primitives used by higher-level packages.Reflexive\Core\ComparatorandReflexive\Core\Operator: enums for SQL comparisons and boolean chaining.Reflexive\Core\Strings::quote(): a small helper that backticks SQL identifiers.
Requirements
- PHP
^8.4
Installation
composer require reflexive/core
Lazy database connections
Database extends PDO, but it does not call the parent constructor until you actually use the connection.
That means you can pass a configured database object around without opening the socket immediately.
use Reflexive\Core\Database; $db = new Database( 'mysql:host=127.0.0.1;dbname=app;charset=utf8mb4', 'user', 'secret', ); // No connection yet. $stmt = $db->prepare('SELECT 1'); $stmt->execute();
The class also exposes Database::once() to keep one lazy instance per DSN:
$db = Database::once('sqlite:/tmp/app.sqlite');
Default PDO options applied on connect:
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJPDO::ATTR_EMULATE_PREPARES => falsePDO::ATTR_PERSISTENT => falsePDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
Conditions and operators
The abstract condition API is intentionally small and is meant to be subclassed by query layers.
use Reflexive\Core\Comparator; use Reflexive\Core\Operator;
Available comparators:
EQUALNOTEQUALGREATERLESSGREATEROREQUALLESSOREQUALINBETWEENLIKENULLNOTNULL
Available boolean operators:
ANDOR
ConditionGroup enforces explicit chaining: once a condition has been added, the next one must be preceded by and() or or().
Identifier quoting
Strings::quote() wraps bare identifiers in backticks while leaving SQL functions and already-quoted names alone.
use Reflexive\Core\Strings; Strings::quote('users.email'); // `users`.`email` Strings::quote('COUNT(*)'); // COUNT(*)
Scope
This package is mostly infrastructure. On its own it does not build SQL or hydrate models; those features live in:
reflexive/queryreflexive/model