Phoundation (pronounced the same way as "foundation") facilitates the routine step of bootstrapping PHP applications.
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
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.
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();
Released under MIT License - see the License File for details.