PHP code example of acelot / resolver

1. Go to this page and download the library: Download acelot/resolver 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/ */

    

acelot / resolver example snippets


class UsersController
{
    public function __construct(UsersService $service)
    {
        // ...
    }
}

$service = new UsersService();
$controller = new UsersController($service);

class UsersService
{
    public function __construct(UsersRepository $repository)
    {
        // ...
    }
}

$repository = new UsersRepository();
$service = new UsersService($repository);
$controller = new UsersController($service);

class UsersRepository
{
    public function __construct(Database $db)
    {
        // ...
    }
}

$db = new Database('connection string here');
$repository = new UsersRepository($db);
$service = new UsersService($repository);
$controller = new UsersController($service);

$resolver = new Resolver([
    Database::class => ObjectDefinition::define(Database::class)->withArgument('connectionString', 'connection string here')
]);

$controller = $resolver->resolve(UsersController::class);