I just looked at the Zend\Db\Adapter\AdapterServiceFactory as an example:

namespace Zend\Db\Adapter;

use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;

class AdapterServiceFactory implements FactoryInterface
{
    /**
     * Create db adapter service
     *
     * @param ServiceLocatorInterface $serviceLocator
     * @return Adapter
     */
    public function createService(ServiceLocatorInterface $serviceLocator)
    {
        $config = $serviceLocator->get('Config');
        return new Adapter($config['db']);
    }
}




On Sat, Nov 9, 2013 at 3:53 PM, Alexander Torrijos <[email protected]>wrote:

> Hi
>
> I was wondering if there are examples on how the factory class composes
> dependencies.
>
> Should it expect to be passed a service manager in it's constructor in the
> same function a closure does?
>
> Should a factory create new instances of objects or should it also
> retrieve them from the service manager?
>
> Or should a factory import(use)/reference other factories as well?
>
> Much appreciated,
>
> Alex
>
>
> On Fri, Nov 8, 2013 at 12:25 AM, Ben Scholzen 'DASPRiD' 
> <[email protected]>wrote:
>
>> Hi Daniel,
>>
>> > Am I correct in thinking that if I have a ServiceManager defined with
>> > anonymous functions like so: (Added to 'factories' configuration key)
>> >
>> > ...
>> >
>> > it will be called upon every request?
>>
>> The closure will only be called when the controller "Foo" is actually
>> requested. But the function itself is loaded every time.
>>
>> > As opposed to defining a factory class:
>> >
>> > 'Album\Controller\Foo' => 'Album\Service\FooControllerFactory'
>> >
>> > Which will be called when we use the service key:
>>  'Album\Controller\Foo'
>>
>> The factory will actually just be loaded when the controller is
>> requested. So it makes more sense to really define all factories as
>> classes, instead of closures. Closures are just great for rapid
>> prototyping.
>>
>> --
>> Ben Scholzen 'DASPRiD'
>> Community Review Team Member | [email protected]
>> Zend Framework               | http://www.dasprids.de
>>
>> --
>> List: [email protected]
>> Info: http://framework.zend.com/archives
>> Unsubscribe: [email protected]
>>
>>
>>
>
>
> --
> ------------------------------
>
> Alexander R. Torrijos
> Web Developer
> Mobile: +63 919 991 5653
> Res: +63 2 822 7219
> http://alex.stormwild.com
> Skype/YM: artorrijos
>
> ------------------------------
>



-- 
------------------------------

Alexander R. Torrijos
Web Developer
Mobile: +63 919 991 5653
Res: +63 2 822 7219
http://alex.stormwild.com
Skype/YM: artorrijos

------------------------------

Reply via email to