PHP code example of lee / simple-container

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

    

lee / simple-container example snippets



class Profile
{
    protected $userName;

    public function __construct($userName = 'lee')
    {
        $this->userName = $userName;
    }

    public function getUserName()
    {
        return $this->userName;
    }
}


use Lee\Container\Container;

$container = new Container();
$container->set(Profile::class);
$profile = $container->get(Profile::class);

echo $profile->getUserName(); // lee

class Profile
{
    protected $userName;

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

    public function getUserName()
    {
        return $this->userName;
    }
}

use Lee\Container\Container;

$container = new Container();
$container->set(Profile::class);
$profile = $container->get(Profile::class, ['userName' => 'Peter']);

echo $profile->getUserName(); // Peter