PHP code example of loophp / service-alias-autoregister-bundle

1. Go to this page and download the library: Download loophp/service-alias-autoregister-bundle 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/ */

    

loophp / service-alias-autoregister-bundle example snippets




declare(strict_types=1);

namespace App\Controller;

use App\Repository\UserRepository;

final class MyTestController
{
    // Here we inject a concrete implementation of a Doctrine repository.
    public function __invoke(UserRepository $userRepository): Response
    {
        // Do stuff.
    }
}



declare(strict_types=1);

namespace App\Controller;

use Doctrine\Persistence\ObjectRepository;

final class MyTestController
{
    // Here we inject the UserRepository (which implements ObjectRepository)
    // using the variable which has been created from the UserRepository class name.
    public function __invoke(ObjectRepository $userRepository): Response
    {
        // Do stuff.
    }
}



declare(strict_types=1);

namespace App\Controller;

use App\Repository\UserRepository;
use Doctrine\Persistence\ObjectRepository;

final class MyTestController
{
    private UserRepository $userRepository;

    public function __construct(ObjectRepository $userRepository)
    {
        $this->userRepository = $userRepository;
    }

    public function __invoke(): Response
    {
        // Do stuff.
    }
}