PHP code example of chubbyphp / chubbyphp-laminas-config-factory
1. Go to this page and download the library: Download chubbyphp/chubbyphp-laminas-config-factory 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/ */
chubbyphp / chubbyphp-laminas-config-factory example snippets
declare(strict_types=1);
namespace MyProject\Factory;
use Chubbyphp\Laminas\Config\Factory\AbstractFactory;
use MyProject\Service\ServiceA;
use MyProject\Service\ServiceB;
use MyProject\Service\ServiceC;
use Psr\Container\ContainerInterface;
final class ServiceAFactory extends AbstractFactory
{
public function __invoke(ContainerInterface $container): ServiceA
{
return new ServiceA(
$this->resolveConfig($container->get('config')['serviceA'] ?? []),
$this->resolveDependency($container, ServiceB::class, ServiceBFactory::class),
$this->resolveDependency($container, ServiceC::class, ServiceCFactory::class)
);
}
}
/** @var ContainerInterface $container */
$container = ...;
// without name
$serviceA = (new ServiceAFactory())($container);
// with name
$serviceA = [ServiceAFactory::class, 'default']($container);