1. Go to this page and download the library: Download coroq/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/ */
use Coroq\Container\StaticContainer;
use Coroq\Container\ArgumentsResolver\TypeBasedArgumentsResolver;
$resolver = new TypeBasedArgumentsResolver($container);
$container = new StaticContainer($resolver);
// Register entries
$container->setValue('appName', 'My App');
$container->setFactory('userService', function($userRepository) {
return new UserService($userRepository);
});
$container->setSingletonClass('mailer', Mailer::class);
// Get entries
$service = $container->get('userService');
use Coroq\Container\DynamicContainer;
$container = new DynamicContainer();
$container->addNamespace('App\\Domain');
// Auto-creates instances from registered namespaces
$userService = $container->get(App\Domain\UserService::class);
use Coroq\Container\CompositeContainer;
$container = new CompositeContainer();
$container->addContainer($staticContainer);
$container->addContainer($dynamicContainer);
// Searches containers in order until entry is found
$service = $container->get('service');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.