oihana / php-init
The Oihana PHP Init library
Requires
- php: >=8.4
- devium/toml: ^1.0
- oihana/php-enums: dev-main
- oihana/php-files: dev-main
- oihana/php-reflect: dev-main
- php-di/php-di: ^7.0
Requires (Dev)
- nunomaduro/collision: ^8.8
- phpdocumentor/shim: ^3.8
- phpunit/phpunit: ^12
README
Application bootstrap helpers for PHP 8.4+ — config loading, DI container building and PHP runtime setup.
📚 Documentation
User guides (FR + EN), with narrative explanations and examples:
| 🇬🇧 English documentation | 🇫🇷 Documentation française |
|---|---|
| Getting started, configuration, container & definitions, runtime, testing. | Démarrage, configuration, conteneur & définitions, runtime, tests. |
Auto-generated API reference (phpDocumentor):
👉 https://bcommebois.github.io/oihana-php-init
🧠 What is it?
oihana/php-init is a small set of free functions that bootstrap a PHP
application: load and merge a TOML/array configuration, build a
PHP-DI container from definition files, and configure the
PHP runtime (timezone, error reporting, memory limit, ini directives).
use DI\Container; use function oihana\init\initConfig; use function oihana\init\initContainer; use function oihana\init\initDefinitions; // 1. Load configuration (config.toml under the given base path) $config = initConfig( __DIR__ . '/config' ); // 2. Build a DI container from all PHP definition files in a directory $definitions = initDefinitions( __DIR__ . '/definitions' ); $container = initContainer( $definitions );
🚀 Features
- ⚙️ Config loading & merging (TOML + PHP arrays) —
initConfig(). - 📦 PHP-DI container building from definitions —
initContainer(),initDefinitions(). - 🕐 PHP runtime setup —
initDefaultTimezone(),initErrors(),initMemoryLimit(),setIniIfExists(). - 🧩 Plain free functions, autoloaded — no framework lock-in.
- 🧪 Full unit-test coverage ensuring reliability and maintainability.
💡 Designed to be lightweight, testable, and compatible with any PHP 8.4+ project.
📦 Installation
Requires PHP 8.4+
Install via Composer:
composer require oihana/php-init
✅ Tests & coverage
Run the full unit-test suite (PHPUnit, strict mode):
composer test
Run a single test case:
./vendor/bin/phpunit --filter InitContainerTest
Measure coverage (requires Xdebug or PCOV):
composer coverage # text + Clover + HTML under build/coverage/ composer coverage:md # readable Markdown summary (build/coverage/COVERAGE.md)
The suite runs in strict mode and targets 100% line coverage.
🧾 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.
Usage
Run the command :
composer doc
🔗 Related packages
- oihana/php-files – file, path and TOML config helpers used to load configuration.
- oihana/php-enums – strongly-typed constant enumerations (
IniOptions, …). - oihana/php-reflect – reflection utilities and exception types.
