PHP code example of mattferris / provider
1. Go to this page and download the library: Download mattferris/provider 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/ */
mattferris / provider example snippets
use MattFerris\Provider\ConsumerInterface;
use MattFerris\Provider\ProviderInterface;
// service container which contains service definitions
class ServiceContainer implements ConsumerInterface
{
public function register(ProviderInterface $provider)
{
$provider->provides($this);
return $this;
}
...
}
class DatabaseProvider implements ProviderInterface
{
public function provides(ConsumerInterface $consumer)
{
$consumer->set('DatabaseService', $databaseServiceDefinition);
}
}
$container = new ServiceContainer();
$container->register(new DatabaseProvider());
$db = $container->get('DatabaseService');
$db->query(...);
$container = new ServiceContainer();
$container
->register(new DatabasePackage\ServiceProvider())
->register(new Authentication\ServiceProvider())
->register(new EventDispatcher\ServiceProvider());