oihana / php-system
The Oihana PHP System library
0.0.0
2025-08-13 09:23 UTC
Requires
- php: >=8.4
- ext-pdo: *
- monolog/monolog: ^3.9
- oihana/php-core: dev-main
- oihana/php-files: dev-main
- oihana/php-reflect: dev-main
- php-di/php-di: ^7.0
- psr/log: ^3.0
- psr/simple-cache: ^3.0
Requires (Dev)
- mikey179/vfsstream: ^1.6
- nunomaduro/collision: ^8.8
- phpdocumentor/shim: ^3.8
- phpunit/phpunit: ^12
README
Provides a standard set of PHP helpers and tools to create web and command-line applications.
๐ Documentation
Full project documentation is available at:
๐ https://bcommebois.github.io/oihana-php-system
๐ฆ Installation
Requires PHP 8.4+ and ext-pdo
Install via Composer:
โจ Features
- Bootstrap helpers: initialize timezone, memory limit, error handling, and safe
ini_set
helpers - Configuration: load TOML configuration files with sensible fallbacks
- Dependency Injection: convenience functions for building a PHP-DI container and loading definitions
- Logging: PSR-3 compatible lightweight file logger, plus Monolog config enums
- HTTP helpers: constants for methods, headers and parameter strategies
- MySQL utilities: DSN builder and a robust
PDO
connection builder with safe defaults - Date utilities:
TimeInterval
to parse, format and convert durations
๐ Quick start
require __DIR__ . '/vendor/autoload.php'; use function oihana\init\{ initDefaultTimezone, initMemoryLimit, initErrors, initConfig, initDefinitions, initContainer }; use oihana\logging\Logger; use oihana\db\mysql\MysqlPDOBuilder; // Bootstrap initDefaultTimezone('UTC'); initMemoryLimit('256M'); initErrors([ 'display_errors' => '1', 'error_log' => 'var/logs/php_errors.log', ], __DIR__); // Load config and build the DI container $config = initConfig(__DIR__ . '/config', 'app.toml'); $definitions = initDefinitions(__DIR__ . '/definitions'); $container = initContainer($definitions, ['config' => $config]); // Logger $logger = new Logger(__DIR__ . '/var/logs', Logger::DEBUG); $logger->info('Application started'); // MySQL PDO $pdo = (new MysqlPDOBuilder([ 'host' => '127.0.0.1', 'dbname' => 'demo', 'username' => 'root', 'password' => 'secret', ]))();
๐งฐ Usage
Init helpers
use function oihana\init\{ initDefaultTimezone, initMemoryLimit, initErrors, setIniIfExists }; initDefaultTimezone('UTC'); initMemoryLimit('512M'); initErrors([ 'display_errors' => '1', 'display_startup_errors' => '1', 'error_log' => 'var/logs/php_errors.log', ], __DIR__); // Safe ini_set wrapper (no-op on empty values) setIniIfExists('upload_max_filesize', '64M');
Configuration and DI container
use function oihana\init\{ initConfig, initDefinitions, initContainer }; $config = initConfig(__DIR__ . '/config', 'app.toml'); $definitions = initDefinitions(__DIR__ . '/definitions'); $container = initContainer($definitions, ['config' => $config]);
Logging (PSR-3)
use oihana\logging\Logger; $logger = new Logger(__DIR__ . '/var/logs', Logger::INFO); $logger->info('App started'); $logger->error('An error occurred: {error}', ['error' => 'boom']); // Optional helpers $logger->clear(); // remove all log files in log directory $files = $logger->getLogFiles();
MySQL PDO builder
use oihana\db\mysql\MysqlPDOBuilder; $pdo = (new MysqlPDOBuilder([ 'host' => 'localhost', 'dbname' => 'test_db', 'username' => 'user', 'password' => 'secret', // 'validate' => false, // disable validation if needed // 'skipDbName' => true, // build DSN without dbname ]))();
HTTP helpers
use oihana\http\{ HttpMethod, HttpHeaders, HttpParamStrategy }; $method = HttpMethod::POST; $header = HttpHeaders::CONTENT_TYPE; $strategy = HttpParamStrategy::BOTH; // read from body and query
TimeInterval (durations)
use oihana\date\TimeInterval; $d = new TimeInterval('1h 2m 5s'); echo $d->humanize(); // 1h 2m 5s echo $d->formatted(); // 1:02:05 echo $d->toSeconds(); // 3725
โ Running Unit Tests
To run all tests:
composer run-script test
To run a specific test file:
composer run test ./tests/oihana/date/TimeIntervalTest.php
๐ค Contributing
Contributions are welcome! Please:
- Open an issue for discussion before large changes
- Write tests for new features and bug fixes
- Run the full test suite locally before submitting a PR
๐๏ธ Changelog
See CHANGELOG.md
for notable changes.
๐งพ License
This project is licensed under the Mozilla Public License 2.0 (MPL-2.0).
๐ค About the author
- Author: Marc ALCARAZ (aka eKameleon)
- Mail: marc@ooop.fr
- Website: http://www.ooop.fr
๐ ๏ธ Generate the Documentation
We use phpDocumentor to generate the documentation into the ./docs
folder.
composer doc
๐ Related packages
oihana/php-core
โ core helpers and utilities used by this library:https://github.com/BcommeBois/oihana-php-core
oihana/php-exceptions
โ a curated set of reusable custom exception classes for PHP:https://github.com/BcommeBois/oihana-php-exceptions
oihana/php-reflect
โ reflection and hydration utilities:https://github.com/BcommeBois/oihana-php-reflect
oihana/php-enums
โ a collection of strongly-typed constant enumerations for PHP:https://github.com/BcommeBois/oihana-php-enums
oihana/php-files
โ a versatile PHP library for seamless and portable file and path handling:https://github.com/BcommeBois/oihana-php-files