1. Go to this page and download the library: Download parable-php/di 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/ */
parable-php / di example snippets
use \Parable\Di\Container;
$container = new Container();
$app = $container->get(App::class);
$app->run();
use \Parable\Di\Container;
$container = new Container();
class App
{
public function __construct(ThatInterface $classWithThatInterface)
{
}
public function run()
{
echo "Run? RUN!";
}
}
$container->map(ThatInterface::class, ClassWithThatInterface::class);
$app = $container->get(App::class);
$app->run();
use \Parable\Di\Container;
$container = new Container();
class App
{
public $container;
public function __construct(
public Container $container
) {}
}
$app = $container->get(App::class);
var_dump($app->container->has(App::class)); // output: bool(true)
bash
$ composer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.