1. Go to this page and download the library: Download firehed/container library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
declare(strict_types=1);
// Include Composer's autoloader if not already done
{
Dotenv\Dotenv::create(__DIR__)->load();
}
*/
$isDevMode = getenv('ENVIRONMENT') === 'development';
if ($isDevMode) {
$builder = new Firehed\Container\Builder();
} else {
$builder = new Firehed\Container\Compiler();
}
// Each definition file must return a definition array (see below)
foreach (glob('config/*.php') as $definitionFile) {
$builder->addFile($definitionFile);
}
return $builder->build();
use Psr\Container\ContainerInterface;
return [
// This will provide a single connection to your database, deferring the
// connection until either directly accessed or a service with PDO as a
// dependency is accessed.
// Note: you may opt to elide the `ContainerInterface` typehint for brevity
PDO::class => function (ContainerInterface $c) {
// This example assumes pdo_dsn, database_user, and database_pass are
// defined elsewhere (probably using the `env` helper)
return new PDO(
$c->get('pdo_dsn'),
$c->get('database_user'),
$c->get('database_pass')
);
},
];
/**
class MySpecialClass
{
}
class MyOtherClass
{
public function __construct(MySpecialClass $
use function Firehed\Container\autowire;
return [
MySpecialClass::class => autowire(),
MyOtherClass::class => autowire(),
];
use function Firehed\Container\autowire;
return [
MySpecialClass::class => autowire(MySpecialClass::class),
MyOtherClass::class => autowire(MyOtherClass::class),
];
return [
MySpecialClass::class => function () {
return new MySpecialClass();
},
MyOtherClass::class => function (ContainerInterface $c) {
return new MyOtherClass($c->get(MySpecialClass::class));
},
];