ZF2: setting up new abstract factories

Zend Framework 2.2.0 adds a group of new abstract factories . I want to set up a database logger, but I'm not sure how to do this. The link gives the following example of configuring a stream recorder:

'log' => array( 'Application\Log' => array( 'writers' => array( array( 'name' => 'stream', 'priority' => 1000, 'options' => array( 'stream' => 'data/logs/app.log', ), ), ), ), ), 

I tried to copy the configuration to config/global.php , and I also tried to attach it under the service_manager key. It says that I should get the logger directly from the service manager, but I get an error saying that it could not create an instance of Application\Log . Am I misunderstood something? Where should the configuration be added?

Also, in my specific example, I want to use a database creator. How is this set up in a similar style with the above (i.e. with arrays)? When you look at the Zend\Writer\Db constructor , you need to pass an adapter instance to it. I'm not sure how to do this without creating a factory, because my database adapter uses an abstract factory; Zend\Db\Adapter\AdapterServiceFactory . It seems to me that I need to contact the service manager in the configuration file in order to extract the database adapter in order to insert it into the db record. I am not sure if this is possible.

I can make a custom factory just fine, but I like the idea of ​​these sequential abstract factories; I'm just confused about how to use them.

+4
source share
1 answer

You will also need to include an abstract factory that creates the registrar, for example. with the following configuration

 // ... snip ... 'service_manager' => array( 'abstract_factories' => array( 'Zend\Log\LoggerAbstractServiceFactory', ), ) // ... snip ... 
+2
source

Source: https://habr.com/ru/post/1484034/


All Articles