DI and native classes

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

DI and native classes

macest
I'm trying to use a native class (SphinxClient installed via PECL) with the dependency injector to set the server:

'definition' => array(
        'class' => array(
                'SphinxClient' => array(
                        'methods' => array(
                                'setServer' => array(
                                        'host' => array(
                                                'type' => false,
                                                'required' => true
                                        ),
                                        'port' => array(
                                                'type' => false,
                                                'required' => true
                                        ),
                                ),
                        ),
                ),
        ),
),
'instance' => array(
        'SphinxClient' => array(
                'injections' => array(
                        'setServer' => array(
                                'host' => 'localhost',
                                'port' => 3312,
                        ),
                ),
        ),
),

This does not work seem to work, the method is not called. however if I simply extend it with my own empty class it does.

'definition' => array(
        'class' => array(
                'My\SphinxClient' => array(
                        'methods' => array(
                                'setServer' => array(
                                        'host' => array(
                                                'type' => false,
                                                'required' => true
                                        ),
                                        'port' => array(
                                                'type' => false,
                                                'required' => true
                                        ),
                                ),
                        ),
                ),
        ),
),
'instance' => array(
        'My\SphinxClient' => array(
                'injections' => array(
                        'setServer' => array(
                                'host' => 'localhost',
                                'port' => 3312,
                        ),
                ),
        ),
),

Why won't it work with the native class?
Reply | Threaded
Open this post in threaded view
|

Re: DI and native classes

weierophinney
Administrator
-- macest <[hidden email]> wrote
(on Friday, 16 March 2012, 06:28 AM -0700):
> I'm trying to use a native class (SphinxClient installed via PECL) with the
> dependency injector to set the server:
>
> 'definition' => array(
> 'class' => array(
> 'SphinxClient' => array(
> 'methods' => array(
> 'setServer' => array(

add a

    "required" => true

at the method level, and it will force it to be injected.

One thing I've noticed is that a lot of pecl extensions do not do
reflection properly, which makes it necessary to do these definitions.
Bug the extension authors to do it correctly (I did this with Mongo, and
it now has decent reflection).

> 'host' => array(
> 'type' => false,
> 'required' => true
> ),
> 'port' => array(
> 'type' => false,
> 'required' => true
> ),
> ),
> ),
> ),
> ),
> ),
> 'instance' => array(
> 'SphinxClient' => array(
> 'injections' => array(
> 'setServer' => array(
> 'host' => 'localhost',
> 'port' => 3312,
> ),
> ),
> ),
> ),
>
> This does not work seem to work, the method is not called. however if I
> simply extend it with my own empty class it does.
>
> 'definition' => array(
> 'class' => array(
> 'My\SphinxClient' => array(
> 'methods' => array(
> 'setServer' => array(
> 'host' => array(
> 'type' => false,
> 'required' => true
> ),
> 'port' => array(
> 'type' => false,
> 'required' => true
> ),
> ),
> ),
> ),
> ),
> ),
> 'instance' => array(
> 'My\SphinxClient' => array(
> 'injections' => array(
> 'setServer' => array(
> 'host' => 'localhost',
> 'port' => 3312,
> ),
> ),
> ),
> ),
>
> Why won't it work with the native class?
>
> --
> View this message in context: http://zend-framework-community.634137.n4.nabble.com/DI-and-native-classes-tp4478165p4478165.html
> Sent from the Zend Framework mailing list archive at Nabble.com.
>
> --
> List: [hidden email]
> Info: http://framework.zend.com/archives
> Unsubscribe: [hidden email]
>
>

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

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: DI and native classes

macest
Oddly enough when I went to do this I removed my wrapper class and it magically started working without having to put that required parameter on. Not sure what happened there, just one of those things I guess lol.