Actually, after looking more closely at the PHP manual for callables (thanks to 
the suggestion of a colleague), there is a simple alternative: just use 
callable strings instead of callable arrays…

so:

array(‘My\Factory’, ‘myStaticMethod’)

becomes:

‘My\Factory::myStaticMethod’

Easy! I'll still consider the possibility of using separate factory classes 
under some circumstances, but when it makes sense to group stuff together, it 
looks like this offers the option to do so without breaking overriding.

- Demian

> -----Original Message-----
> From: Demian Katz [mailto:demian.k...@villanova.edu]
> Sent: Wednesday, March 12, 2014 8:31 AM
> To: Matthew Weier O'Phinney
> Cc: Zend Framework General
> Subject: RE: [fw-general] Configuration merging and callables
> 
> That certainly works, but it seems to add an awful lot of clutter – a separate
> factory class for every service. My application offers a lot of different
> options, so this would add hundreds of files and require PHP to do twice as
> much autoloading (which I realize isn’t that expensive, but it has to add up
> at some point). I considered putting a static factory method in each class to
> cut down on clutter, but this doesn’t seem like good design – it couples
> things unnecessarily. Having stand-alone factory classes that group together
> related objects seems like the most attractive option from an organizational
> perspective. Sounds like it may not be practical, and I know you’re the expert
> – but I would be curious to hear if anyone else has successfully approached
> this from another angle. If not, I’ll get to work moving all my factories
> around a second time. ☺
> 
> - Demian
> 
> From: Matthew Weier O'Phinney [mailto:matt...@zend.com]
> Sent: Tuesday, March 11, 2014 7:32 PM
> To: Demian Katz
> Cc: Zend Framework General
> Subject: Re: [fw-general] Configuration merging and callables
> 
> Use classes that implement __invoke() instead, and reference the class name.
> The SM is smart enough to autoload these when requested, making them a more
> robust solution than array callbacks - particularly for the use car of
> overriding.

Reply via email to