1. Go to this page and download the library: Download aeris/zf-di-config 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/ */
[
'$factory' => [
// Object class ( // services to inject in constructor (optional)
'args' => ['@SomeService'],
// Service to inject using setters
'setters' => [
// This will inject 'SomeService'
// using the FooService::setBar() method
'bar' => '@SomeService'
]
]
]
[
'@NameOfService`, // resolves to $serviceLocator->get('NameOfService')
'@NameOfService::foo' // resolves to $serviceLocator->get('NameOfService')->getFoo()
]
[
'$serviceManager' => [
// Will validate all services of this service manager as belonging
// to SomeInterface
'service_type' => '\MyApp\SomeInterface',
'config' => [
'invokables' => [
'Foo' => '\MyApp\Foo'
],
// You can use ZfDiConfig here, too!
'di' => [
'Bar' => [
'class' => '\Bar',
'args' => ['%my_app.bar']
]
]
],
// or, you could use a config reference
// 'config' => '%my_app.custom_manager'
]
]
namespace MyApp\ServiceManager\ConfigPlugin;
use Aeris\ZfDiConfig\ServiceManager\ConfigPlugin\AbstractConfigPlugin;
class DoctrineRepositoryPlugin extends AbstractConfigPlugin {
public function resolve($pluginConfig) {
// Grab the Doctrine EntityManager from the service locator
$entityManager = $this->serviceLocator->get('entity_manager');
// Return the configured repository
return $entityManager->get($pluginConfig['entity_class']);
}
public function configFromString($string) {
// Convert a short-form config into an array
return [
'entity_class' => $string;
]
}
}