On Tue, Dec 17, 2013 at 8:52 AM, Marco Pivetta <ocram...@gmail.com> wrote:
> Sorry for the late reply.
>
> No, factories are NOT passed to initializers, and shouldn't.
>
> Think of a factory as a named callback. Nothing else.

Actually, I'm going to clarify a bit further.

What gets passed to initializers are any objects the ServiceManager
_creates_. That means:

- an "invokable" class
- the result of a factory
- the result of an abstract factory

Essentially, as soon as the SM decides it doesn't have an instance
already, but has a definition for one, it calls the routine necessary
for creating the object, and then passes that result to each
initializer. It then stores it -- which means that the next time you
retrieve it, the instance will *not* be passed to the initializers.

> On 9 December 2013 17:06, Xander Guzman <thesha...@shadowpedia.info> wrote:
>
>> It does
>>
>> /**
>>  * Defines an initializer that knows how to inject a configuration object
>>  */
>> class ConfigInitializer implements InitializerInterface
>> {
>>     /**
>>      * Initialize
>>      *
>>      * @param $instance
>>      * @param ServiceLocatorInterface $serviceLocator
>>      *
>>      * @return mixed
>>      */
>>     public function initialize($instance, ServiceLocatorInterface
>> $serviceLocator)
>>     {
>>         if ($instance instanceof ConfigAwareInterface) {
>>             $config = $serviceLocator->get('Config');
>>             $instance->setConfig($config);
>>         }
>>     }
>> }
>>
>>
>> On Mon, Dec 9, 2013 at 8:52 AM, franz de leon <kelmad...@gmail.com> wrote:
>>
>> > Your factory should implement the interface in your initializer.
>> >
>> > array(
>> >     'factories' => array(
>> >         'solrconfig' => 'Solr\Config\ConfigInitializer',
>> >     ),
>> >     'initializers' => array(
>> >          function ($instance, $sm) {
>> >               if ($instance instanceof Configaware) {
>> >                    $instance->setConfig($sm->get('solrconfig'));
>> >               }
>> >          }
>> >     )
>> > )
>> >
>> >
>> > On Mon, Dec 9, 2013 at 10:24 AM, Xander Guzman
>> > <thesha...@shadowpedia.info>wrote:
>> >
>> > > Like the database configurations I have multiple Solr configurations so
>> > I'm
>> > > trying to create a factory that can return the connection to the one
>> > > specified.
>> > >
>> > > return array(
>> > >     "solr" => array(
>> > >         'media' => array( /** config */ ),
>> > >         'vendors' => array( /** config */ ),
>> > >     ),
>> > > );
>> > >
>> > > Right now, in my module, I have the Following configuration for the
>> > > getServiceConfig method
>> > >
>> > > return array(
>> > >     'factories' => array(
>> > >         'Solr\Service' => 'Solr\Service\Factory',
>> > >         'Solr\Client' => 'Solr\Client\Factory',
>> > >     ),
>> > >     'initializers' => array(
>> > >         'SolrConfig' => 'Solr\Config\ConfigInitializer',
>> > >     ),
>> > > );
>> > >
>> > > Here is how things are working.
>> > >
>> > > The factories work and are getting called and the initializer is being
>> > > called, but the initializer isn't being called on the factories.
>> > >
>> > > So first, why? Is this by design? Am I misunderstanding how this
>> > > relationship works?
>> > >
>> > > How can I get the same kind of multiple configurations to work I tried
>> > > digging through the DB ones but I don't think I've found the class that
>> > yet
>> > > reads the config to pass off to a specific adapter.
>> > >
>> > > Any help is appreciated.
>> > >
>> > > Cheers!
>> > >
>> > > Xander
>> > >
>> >
>>



-- 
Matthew Weier O'Phinney
Project Lead            | matt...@zend.com
Zend Framework          | http://framework.zend.com/
PGP key: http://framework.zend.com/zf-matthew-pgp-key.asc

-- 
List: fw-general@lists.zend.com
Info: http://framework.zend.com/archives
Unsubscribe: fw-general-unsubscr...@lists.zend.com


Reply via email to