nikolaposa / phoundation
Facilitates the routine step of bootstrapping PHP applications.
Installs: 9 022
Dependents: 0
Suggesters: 0
Security: 0
Stars: 16
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- php: ^7.4 || ^8.0
- psr/container: ^1.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.1
- laminas/laminas-servicemanager: ^3.4
- phpstan/phpstan: ^0.12.18
- phpstan/phpstan-phpunit: ^0.12.6
- phpunit/phpunit: ^8.0
- psr/log: ^1.1
Suggests
- laminas/laminas-servicemanager: In order to use LaminasServiceManagerFactory
This package is auto-updated.
Last update: 2024-12-10 00:36:53 UTC
README
Phoundation (pronounced the same way as "foundation") facilitates the routine step of bootstrapping PHP applications.
Installation
The preferred method of installation is via Composer. Run the following
command to install the latest version of a package and add it to your project's composer.json
:
composer require nikolaposa/phoundation
Purpose
Bootstrapping of today's PHP applications typically comes down to:
- Configuration loading
- Dependency Injection Container initialization
Phoundation aims to reduce the amount of repetitive code needed for the application startup logic by abstracting bootstrapping process.
Usage
Given the configuration files:
config/global.php
return [ 'db' => [ 'driver' => 'pdo_mysql', 'host' => 'localhost', 'user' => 'root', 'password' => 'secret', 'dbname' => 'test', ], 'dependencies' => [ 'factories' => [ \PDO::class => function () { return new \PDO('sqlite::memory:'); }, 'My\\Web\\Application' => My\Web\ApplicationFactory::class, ] ], ];
config/local.php
return [ 'db' => [ 'user' => 'admin', 'password' => '1234', ], ];
Create bootstrap script which typically lives in src/bootstrap.php
:
use Phoundation\Bootstrap; use Phoundation\Config\FileConfigLoader; use Phoundation\DependencyInjection\LaminasServiceManagerFactory; $bootstrap = new Bootstrap( new FileConfigLoader(glob(sprintf('config/{{,*.}global,{,*.}%s}.php', getenv('APP_ENV') ?: 'local'), GLOB_BRACE)), new LaminasServiceManagerFactory() ); return $bootstrap();
Load bootstrap in your web application root (for example public/index.php
):
/* @var \Psr\Container\ContainerInterface $diContainer */ $diContainer = require __DIR__ . '/../src/bootstrap.php'; $diContainer->get('My\\Web\\Application')->run();
Credits
License
Released under MIT License - see the License File for details.