1. Go to this page and download the library: Download lss/yacontainer 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/ */
class DatabaseConnection extends \PDO {
public function __construct(string $databaseDSN, string $databaseUser, string $databasePassword)
{
$options = ['charset' => 'utf8',PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION];
parent::__construct($databaseDSN, $databaseUser, $databasePassword, $options);
}
// ... other utility functions
}
$container = new Container(['databaseDSN' => 'mysql:host=localhost;dbname=theDBName', 'databaseUser' => 'theUserName', 'databasePassword' => 'thePassword']);
$databaseConnection = $container->get(DatabaseConnection::class);
$container->addScalar('maximumPassengers', function (Configuration $config) {
return $config->getMaximumPassengers();
});
$fuelPercent = 75;
$container = new Container();
$container->addFactory(Car::class, function (EngineInterface $engine) use ($fuelPercent): Car {
$result = new Car($engine);
$result->refuel($fuelPercent);
return $result;
});