PHP code example of reinfi / zf-dependency-injection

1. Go to this page and download the library: Download reinfi/zf-dependency-injection 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/ */

    

reinfi / zf-dependency-injection example snippets


    return [
        'modules' => [
            'Reinfi\DependencyInjection',
            // other modules
        ],
    ];

'service_manager' => [
    'factories' => [
        YourService::class => \Reinfi\DependencyInjection\Factory\AutoWiringFactory::class,
    ],
]

'service_manager' => [
    'abstract_factories' => [
        \Reinfi\DependencyInjection\AbstractFactory\FallbackAutoWiringFactory::class,
    ],
]

PluginManagerResolver::addMapping('MyInterfaceClass', 'MyPluginManager');

'reinfi.dependencyInjection' => [
    'autowire_resolver' => [
        AnotherResolver::class,
    ],
]

'service_manager' => [
    'factories' => [
        YourService::class => \Reinfi\DependencyInjection\Factory\InjectionFactory::class,
    ],
]

#[InjectFormElement(name="Service", options={"field": "value"}]

#[Inject("Namespace\MyService")] 
private MyService $service;

public function __construct(MyService $service) 
{
    $this->service = $service;
}

private MyService $service;

#[Inject("Namespace\MyService")] 
public function __construct(MyService $service) 
{
    $this->service = $service;
}

'service_manager' => [
    'factories' => [
        YourService::class => \Reinfi\DependencyInjection\Factory\InjectionFactory::class,
    ],
]

@InjectFormElement(name="Service", options={"field": "value"})

use Reinfi\DependencyInjection\Annotation\Inject;

/**
 * @Inject("Namespace\MyService")
 */
private MyService $service;

/**
 * @param MyService $service
 */
public function __construct(
    MyService $service,
) {
    $this->service = $service;
}

use Reinfi\DependencyInjection\Annotation\Inject;

/**
 * @Inject("Namespace\MyService")
 */
public function __construct(MyService $service) 
{
    $this->service = $service;
}

'reinfi.dependencyInjection' => [
    'extractor' => YamlExtractor::class,
    'extractor_options => [
        'file' => 'path_to_your_yaml_file.yml',
    ],
]

'reinfi.dependencyInjection' => [
    'cache' => \Laminas\Cache\Storage\Adapter\Memory::class,
]

'reinfi.dependencyInjection' => [
    'cache' => function() {
       return new \Laminas\Cache\Psr\SimpleCache\SimpleCacheDecorator(
           new \Laminas\Cache\Storage\Adapter\Memory()
       );
    },
]

$app = \Laminas\Mvc\Application::init($config);
return $app->getServiceManager();
neon
parameters:
    reinfiLaminasDependencyInjection:
       serviceManagerLoader: tests/service-manager.php