PHP code example of initphp / container

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

    

initphp / container example snippets



use InitPHP\Container\Container;

class UserModel
{
    private string $name;

    public function set(string $name)
    {
        $this->name = $name;
    }
    
    public function get()
    {
        return $this->name ?? null;
    }
}

class User
{
    private $model;

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

    public function getModel()
    {
        return $this->model;
    }
}

$container = new Container();
$user = $container->get(\Example\User::class);
$model = $user->getModel();
$model->set('Muhammet');
echo $user->getModel()->get();