1. Go to this page and download the library: Download liquidrazor/diregistry 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/ */
liquidrazor / diregistry example snippets
declare(strict_types=1);
use LiquidRazor\DIRegistry\Bootstrap\RegistryCompiler;
use LiquidRazor\DIRegistry\Contract\DependencyValueProviderInterface;
use LiquidRazor\DIRegistry\Descriptor\DependencyDescriptor;
use LiquidRazor\DIRegistry\Instantiator\DescriptorInstantiator;
use LiquidRazor\DIRegistry\Resolver\DescriptorResolver;
use LiquidRazor\DIRegistry\Runtime\InMemoryRuntimeInstanceStore;
use LiquidRazor\DIRegistry\Value\RuntimeContext;
use LiquidRazor\DIRegistry\Enum\Environment;
interface MailerInterface
{
}
final class SmtpMailer implements MailerInterface
{
public function __construct(public string $dsn)
{
}
}
final class NewsletterService
{
public function __construct(public MailerInterface $mailer)
{
}
}
final class ArrayValueProvider implements DependencyValueProviderInterface
{
public function __construct(private array $values)
{
}
public function canProvide(DependencyDescriptor $dependency, RuntimeContext $context): bool
{
return array_key_exists($dependency->name, $this->values);
}
public function provide(DependencyDescriptor $dependency, RuntimeContext $context): mixed
{
return $this->values[$dependency->name];
}
}
$definitions = [
[
'id' => 'service.mailer.smtp',
'classPath' => SmtpMailer::class,
'contracts' => [MailerInterface::class],
'source' => 'config/services.php',
'lifecycle' => 'singleton',
'environments' => ['prod'],
'priority' => 0,
'isDefault' => true,
'constructionStrategy' => 'constructor',
'dependencies' => [
[
'name' => 'dsn',
'position' => 0,
'kind' => 'scalar',
'target' => 'mailer.dsn',
'
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.