1. Go to this page and download the library: Download cekta/di 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/ */
cekta / di example snippets
// src/Example.php
class Example {
public function __construct(private \PDO $db) {}
}
// src/Project.php
class Project extends \Cekta\DI\AbstractProject
{
public function __construct(public readonly array $env = getenv())
{
parent::__construct(
filename: __DIR__ . '/../Container.php',
fqcn: 'App\Container',
params: [
\PDO::class . '$dsn' => $env['DB_DSN'] ?? 'sqlite:' . __DIR__ . '/../mydb.sqlite',
],
);
}
public function definition(): array
{
return ['entries' => [\App\Example::class]];
}
}
$project = new \App\Project();
file_put_contents(
$project->filename,
(new \Cekta\DI\ContainerGenerator())->compile($project)
);
$project = new \App\Project();
$container = (new \Cekta\DI\ContainerFactory())->create($project);
$example = $container->get(\App\Example::class);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.