PHP code example of jascha030 / dic

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

    

jascha030 / dic example snippets


class UserService
{
    public $user;

    public function __construct(User $user)
    {
        $this->user = $user;
    }

    public function printUserName()
    {
        echo "My name is " . $this->user->name;
    }
}

$container = new PsrServiceContainer(); // Instantiate container

$userService = $container->get(UserService::class); // Get service or class instance.

$userService->printUserName(); // Outputs: My name is Jeff