Quantcast

DI woes (cache)

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

DI woes (cache)

basz
Hi,

I must be doing something wrong. I have a class that needs to be 'aware' of some options, logging and caching. Options are injected via the constructor just fine. That constructor parameter is called $options. I have two setters, setLogger($logger), which works also works as expected. However setCache($cache) throws an exception - complaing about incorrect options fed to the Filesystem class.

Zend/Cache/Storage/Adapter/Filesystem is instantiated by the Zend/Cache/StorageFactory, however the setOptions method of the Filesystem adapter is called with the $options array. (see #2 of the backtrace) This is obviously wrong.

Is this a limitation of how DI works? A bug in DI? or should I go about this in a completely different way? It seems to me that DI is confused about the parameters it is passing the the various instances... The cache object

 
  'My\Service' => array( /* LocatorAware, LoggerAware, mimic CacheAware */
                'parameters' => array(
                    'options'      => 'my-service-configuration', /* is a My\ServiceOptions instance */
                    'logger'       => 'my-logger', /* is a Logger instance */
                    'cache'        => 'my-cache-adapter',  /* is a AdapterInteface instance */
                ),
            ),

#0 …/vendor/ZendFramework/library/Zend/Stdlib/Options.php(41): Zend\Stdlib\Options->setFromArray(Object(My\ServiceOptions))
#1 …/vendor/ZendFramework/library/Zend/Cache/Storage/Adapter/Filesystem.php(82): Zend\Stdlib\Options->__construct(Object(My\ServiceOptions))
#2 [internal function]: Zend\Cache\Storage\Adapter\Filesystem->setOptions(Object(My\ServiceOptions))
#3 …/vendor/ZendFramework/library/Zend/Di/Di.php(394): call_user_func_array(Array, Array)
#4 …/vendor/ZendFramework/library/Zend/Di/Di.php(212): Zend\Di\Di->handleInjectionMethodForInstance(Object(Zend\Cache\Storage\Adapter\Filesystem), 'setOptions', Array, 'ideal-cache-ada...', false)
#5 …/vendor/ZendFramework/library/Zend/Di/Di.php(130): Zend\Di\Di->newInstance('my-cache-ada...', Array)
#6 …/vendor/ZendFramework/library/Zend/Di/Di.php(609): Zend\Di\Di->get('my-cache-ada...', Array)
#7 …/vendor/ZendFramework/library/Zend/Di/Di.php(389): Zend\Di\Di->resolveMethodParameters('My\Service...', 'setCache', Array, false, 'my-service', false)
#8 …/vendor/ZendFramework/library/Zend/Di/Di.php(212): Zend\Di\Di->handleInjectionMethodForInstance(Object(My\Service), 'setCache', Array, 'my-service', false)
#9 …/vendor/ZendFramework/library/Zend/Di/Di.php(130): Zend\Di\Di->newInstance('my-service', Array)
#10 …/module/MyService/Module.php(46): Zend\Di\Di->get('my-service')


for the complete DI.conf for this moudle : https://gist.github.com/2568952

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: DI woes (cache)

Marco Pivetta
It would be interesting to know the exact type hinting of your setters :)
If the type hinting is not in place, you have to force it using class definitions in Di.
Marco Pivetta

http://twitter.com/Ocramius     

http://marco-pivetta.com    



On 1 May 2012 17:42, Bas Kamer <[hidden email]> wrote:
Hi,

I must be doing something wrong. I have a class that needs to be 'aware' of some options, logging and caching. Options are injected via the constructor just fine. That constructor parameter is called $options. I have two setters, setLogger($logger), which works also works as expected. However setCache($cache) throws an exception - complaing about incorrect options fed to the Filesystem class.

Zend/Cache/Storage/Adapter/Filesystem is instantiated by the Zend/Cache/StorageFactory, however the setOptions method of the Filesystem adapter is called with the $options array. (see #2 of the backtrace) This is obviously wrong.

Is this a limitation of how DI works? A bug in DI? or should I go about this in a completely different way? It seems to me that DI is confused about the parameters it is passing the the various instances... The cache object


 'My\Service' => array( /* LocatorAware, LoggerAware, mimic CacheAware */
               'parameters' => array(
                   'options'      => 'my-service-configuration', /* is a My\ServiceOptions instance */
                   'logger'       => 'my-logger', /* is a Logger instance */
                   'cache'        => 'my-cache-adapter',  /* is a AdapterInteface instance */
               ),
           ),

#0 …/vendor/ZendFramework/library/Zend/Stdlib/Options.php(41): Zend\Stdlib\Options->setFromArray(Object(My\ServiceOptions))
#1 …/vendor/ZendFramework/library/Zend/Cache/Storage/Adapter/Filesystem.php(82): Zend\Stdlib\Options->__construct(Object(My\ServiceOptions))
#2 [internal function]: Zend\Cache\Storage\Adapter\Filesystem->setOptions(Object(My\ServiceOptions))
#3 …/vendor/ZendFramework/library/Zend/Di/Di.php(394): call_user_func_array(Array, Array)
#4 …/vendor/ZendFramework/library/Zend/Di/Di.php(212): Zend\Di\Di->handleInjectionMethodForInstance(Object(Zend\Cache\Storage\Adapter\Filesystem), 'setOptions', Array, 'ideal-cache-ada...', false)
#5 …/vendor/ZendFramework/library/Zend/Di/Di.php(130): Zend\Di\Di->newInstance('my-cache-ada...', Array)
#6 …/vendor/ZendFramework/library/Zend/Di/Di.php(609): Zend\Di\Di->get('my-cache-ada...', Array)
#7 …/vendor/ZendFramework/library/Zend/Di/Di.php(389): Zend\Di\Di->resolveMethodParameters('My\Service...', 'setCache', Array, false, 'my-service', false)
#8 …/vendor/ZendFramework/library/Zend/Di/Di.php(212): Zend\Di\Di->handleInjectionMethodForInstance(Object(My\Service), 'setCache', Array, 'my-service', false)
#9 …/vendor/ZendFramework/library/Zend/Di/Di.php(130): Zend\Di\Di->newInstance('my-service', Array)
#10 …/module/MyService/Module.php(46): Zend\Di\Di->get('my-service')


for the complete DI.conf for this moudle : https://gist.github.com/2568952


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: DI woes (cache)

basz

class My/Service {
/**
 * @param My/ServiceOptions
 */
public function __construct(ServiceOptions $options)
    {
        $this->options = $options;
    }

/**
 * @param Zend\Log\Logger
 */
public function setLogger(Logger $logger)
    {
    }

/**
 * @param Zend\Cache\Storage\Adapter\AdapterInterface
 */
public function setCache(AdapterInterface $cache)
    {
    }
}

On 1 mei 2012, at 19:08, Marco Pivetta wrote:

It would be interesting to know the exact type hinting of your setters :)
If the type hinting is not in place, you have to force it using class definitions in Di.
Marco Pivetta

http://twitter.com/Ocramius     

http://marco-pivetta.com    



On 1 May 2012 17:42, Bas Kamer <[hidden email]> wrote:
Hi,

I must be doing something wrong. I have a class that needs to be 'aware' of some options, logging and caching. Options are injected via the constructor just fine. That constructor parameter is called $options. I have two setters, setLogger($logger), which works also works as expected. However setCache($cache) throws an exception - complaing about incorrect options fed to the Filesystem class.

Zend/Cache/Storage/Adapter/Filesystem is instantiated by the Zend/Cache/StorageFactory, however the setOptions method of the Filesystem adapter is called with the $options array. (see #2 of the backtrace) This is obviously wrong.

Is this a limitation of how DI works? A bug in DI? or should I go about this in a completely different way? It seems to me that DI is confused about the parameters it is passing the the various instances... The cache object


 'My\Service' => array( /* LocatorAware, LoggerAware, mimic CacheAware */
               'parameters' => array(
                   'options'      => 'my-service-configuration', /* is a My\ServiceOptions instance */
                   'logger'       => 'my-logger', /* is a Logger instance */
                   'cache'        => 'my-cache-adapter',  /* is a AdapterInteface instance */
               ),
           ),

#0 …/vendor/ZendFramework/library/Zend/Stdlib/Options.php(41): Zend\Stdlib\Options->setFromArray(Object(My\ServiceOptions))
#1 …/vendor/ZendFramework/library/Zend/Cache/Storage/Adapter/Filesystem.php(82): Zend\Stdlib\Options->__construct(Object(My\ServiceOptions))
#2 [internal function]: Zend\Cache\Storage\Adapter\Filesystem->setOptions(Object(My\ServiceOptions))
#3 …/vendor/ZendFramework/library/Zend/Di/Di.php(394): call_user_func_array(Array, Array)
#4 …/vendor/ZendFramework/library/Zend/Di/Di.php(212): Zend\Di\Di->handleInjectionMethodForInstance(Object(Zend\Cache\Storage\Adapter\Filesystem), 'setOptions', Array, 'ideal-cache-ada...', false)
#5 …/vendor/ZendFramework/library/Zend/Di/Di.php(130): Zend\Di\Di->newInstance('my-cache-ada...', Array)
#6 …/vendor/ZendFramework/library/Zend/Di/Di.php(609): Zend\Di\Di->get('my-cache-ada...', Array)
#7 …/vendor/ZendFramework/library/Zend/Di/Di.php(389): Zend\Di\Di->resolveMethodParameters('My\Service...', 'setCache', Array, false, 'my-service', false)
#8 …/vendor/ZendFramework/library/Zend/Di/Di.php(212): Zend\Di\Di->handleInjectionMethodForInstance(Object(My\Service), 'setCache', Array, 'my-service', false)
#9 …/vendor/ZendFramework/library/Zend/Di/Di.php(130): Zend\Di\Di->newInstance('my-service', Array)
#10 …/module/MyService/Module.php(46): Zend\Di\Di->get('my-service')


for the complete DI.conf for this moudle : https://gist.github.com/2568952




bushbaby
bushbaby multimedia 
ontwerp & uitvoering
[hidden email] | +31(0)6 2897 7426 | kvk 34125878

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: DI woes (cache)

Marco Pivetta
This looks like a bug caused by $callTimeParameters...
Could you get a better look at what the parameters are at
#4 …/vendor/ZendFramework/library/Zend/Di/Di.php(212): Zend\Di\Di->handleInjectionMethodForInstance(Object(Zend\Cache\Storage\Adapter\Filesystem), 'setOptions', Array, 'ideal-cache-ada...', false) ?
That's where most probably the problem happens. Di is re-using the parameter 'options' for the un-typed $options parameter of the filesystem adapter...

Marco Pivetta

http://twitter.com/Ocramius     

http://marco-pivetta.com    



On 1 May 2012 19:56, Bas Kamer <[hidden email]> wrote:

class My/Service {
/**
 * @param My/ServiceOptions
 */
public function __construct(ServiceOptions $options)
    {
        $this->options = $options;
    }

/**
 * @param Zend\Log\Logger
 */
public function setLogger(Logger $logger)
    {
    }

/**
 * @param Zend\Cache\Storage\Adapter\AdapterInterface
 */
public function setCache(AdapterInterface $cache)
    {
    }
}

On 1 mei 2012, at 19:08, Marco Pivetta wrote:

It would be interesting to know the exact type hinting of your setters :)
If the type hinting is not in place, you have to force it using class definitions in Di.
Marco Pivetta

http://twitter.com/Ocramius     

http://marco-pivetta.com    



On 1 May 2012 17:42, Bas Kamer <[hidden email]> wrote:
Hi,

I must be doing something wrong. I have a class that needs to be 'aware' of some options, logging and caching. Options are injected via the constructor just fine. That constructor parameter is called $options. I have two setters, setLogger($logger), which works also works as expected. However setCache($cache) throws an exception - complaing about incorrect options fed to the Filesystem class.

Zend/Cache/Storage/Adapter/Filesystem is instantiated by the Zend/Cache/StorageFactory, however the setOptions method of the Filesystem adapter is called with the $options array. (see #2 of the backtrace) This is obviously wrong.

Is this a limitation of how DI works? A bug in DI? or should I go about this in a completely different way? It seems to me that DI is confused about the parameters it is passing the the various instances... The cache object


 'My\Service' => array( /* LocatorAware, LoggerAware, mimic CacheAware */
               'parameters' => array(
                   'options'      => 'my-service-configuration', /* is a My\ServiceOptions instance */
                   'logger'       => 'my-logger', /* is a Logger instance */
                   'cache'        => 'my-cache-adapter',  /* is a AdapterInteface instance */
               ),
           ),

#0 …/vendor/ZendFramework/library/Zend/Stdlib/Options.php(41): Zend\Stdlib\Options->setFromArray(Object(My\ServiceOptions))
#1 …/vendor/ZendFramework/library/Zend/Cache/Storage/Adapter/Filesystem.php(82): Zend\Stdlib\Options->__construct(Object(My\ServiceOptions))
#2 [internal function]: Zend\Cache\Storage\Adapter\Filesystem->setOptions(Object(My\ServiceOptions))
#3 …/vendor/ZendFramework/library/Zend/Di/Di.php(394): call_user_func_array(Array, Array)
#4 …/vendor/ZendFramework/library/Zend/Di/Di.php(212): Zend\Di\Di->handleInjectionMethodForInstance(Object(Zend\Cache\Storage\Adapter\Filesystem), 'setOptions', Array, 'ideal-cache-ada...', false)
#5 …/vendor/ZendFramework/library/Zend/Di/Di.php(130): Zend\Di\Di->newInstance('my-cache-ada...', Array)
#6 …/vendor/ZendFramework/library/Zend/Di/Di.php(609): Zend\Di\Di->get('my-cache-ada...', Array)
#7 …/vendor/ZendFramework/library/Zend/Di/Di.php(389): Zend\Di\Di->resolveMethodParameters('My\Service...', 'setCache', Array, false, 'my-service', false)
#8 …/vendor/ZendFramework/library/Zend/Di/Di.php(212): Zend\Di\Di->handleInjectionMethodForInstance(Object(My\Service), 'setCache', Array, 'my-service', false)
#9 …/vendor/ZendFramework/library/Zend/Di/Di.php(130): Zend\Di\Di->newInstance('my-service', Array)
#10 …/module/MyService/Module.php(46): Zend\Di\Di->get('my-service')


for the complete DI.conf for this moudle : https://gist.github.com/2568952




bushbaby
bushbaby multimedia 
ontwerp & uitvoering
[hidden email] | <a href="tel:%2B31%280%296%202897%207426" value="+31628977426" target="_blank">+31(0)6 2897 7426 | kvk 34125878


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: DI woes (cache)

basz

On 1 mei 2012, at 21:09, Marco Pivetta wrote:

This looks like a bug caused by $callTimeParameters...
Could you get a better look at what the parameters are at
#4 …/vendor/ZendFramework/library/Zend/Di/Di.php(212): Zend\Di\Di->handleInjectionMethodForInstance(Object(Zend\Cache\Storage\Adapter\Filesystem), 'setOptions', Array, 'ideal-cache-ada...', false) ?



That's where most probably the problem happens. Di is re-using the parameter 'options' for the un-typed $options parameter of the filesystem adapter...

What I was thinking yes...

    protected function handleInjectionMethodForInstance($instance, $method, $params, $alias, $methodIsRequired, $methodClass = null)
    {
        if ($instance instanceof \My\Service)
            var_dump($method, $params, $alias, $methodIsRequired, $methodClass = null);

I receive the following output:

string(10) "setLocator"
array(0) {
}
string(13) "my-service"
bool(true)
NULL
string(8) "setCache"
array(0) {
}
string(13) "my-service"
bool(false)
NULL


Please note that I attempted to generalize all strings. If you still see 'IDeal' somewere, it should be replaced with 'my'. (#4 still contains ideal)


Marco Pivetta

http://twitter.com/Ocramius     

http://marco-pivetta.com    



On 1 May 2012 19:56, Bas Kamer <[hidden email]> wrote:

class My/Service {
/**
 * @param My/ServiceOptions
 */
public function __construct(ServiceOptions $options)
    {
        $this->options = $options;
    }

/**
 * @param Zend\Log\Logger
 */
public function setLogger(Logger $logger)
    {
    }

/**
 * @param Zend\Cache\Storage\Adapter\AdapterInterface
 */
public function setCache(AdapterInterface $cache)
    {
    }
}

On 1 mei 2012, at 19:08, Marco Pivetta wrote:

It would be interesting to know the exact type hinting of your setters :)
If the type hinting is not in place, you have to force it using class definitions in Di.
Marco Pivetta

http://twitter.com/Ocramius     

http://marco-pivetta.com    



On 1 May 2012 17:42, Bas Kamer <[hidden email]> wrote:
Hi,

I must be doing something wrong. I have a class that needs to be 'aware' of some options, logging and caching. Options are injected via the constructor just fine. That constructor parameter is called $options. I have two setters, setLogger($logger), which works also works as expected. However setCache($cache) throws an exception - complaing about incorrect options fed to the Filesystem class.

Zend/Cache/Storage/Adapter/Filesystem is instantiated by the Zend/Cache/StorageFactory, however the setOptions method of the Filesystem adapter is called with the $options array. (see #2 of the backtrace) This is obviously wrong.

Is this a limitation of how DI works? A bug in DI? or should I go about this in a completely different way? It seems to me that DI is confused about the parameters it is passing the the various instances... The cache object


 'My\Service' => array( /* LocatorAware, LoggerAware, mimic CacheAware */
               'parameters' => array(
                   'options'      => 'my-service-configuration', /* is a My\ServiceOptions instance */
                   'logger'       => 'my-logger', /* is a Logger instance */
                   'cache'        => 'my-cache-adapter',  /* is a AdapterInteface instance */
               ),
           ),

#0 …/vendor/ZendFramework/library/Zend/Stdlib/Options.php(41): Zend\Stdlib\Options->setFromArray(Object(My\ServiceOptions))
#1 …/vendor/ZendFramework/library/Zend/Cache/Storage/Adapter/Filesystem.php(82): Zend\Stdlib\Options->__construct(Object(My\ServiceOptions))
#2 [internal function]: Zend\Cache\Storage\Adapter\Filesystem->setOptions(Object(My\ServiceOptions))
#3 …/vendor/ZendFramework/library/Zend/Di/Di.php(394): call_user_func_array(Array, Array)
#4 …/vendor/ZendFramework/library/Zend/Di/Di.php(212): Zend\Di\Di->handleInjectionMethodForInstance(Object(Zend\Cache\Storage\Adapter\Filesystem), 'setOptions', Array, 'ideal-cache-ada...', false)
#5 …/vendor/ZendFramework/library/Zend/Di/Di.php(130): Zend\Di\Di->newInstance('my-cache-ada...', Array)
#6 …/vendor/ZendFramework/library/Zend/Di/Di.php(609): Zend\Di\Di->get('my-cache-ada...', Array)
#7 …/vendor/ZendFramework/library/Zend/Di/Di.php(389): Zend\Di\Di->resolveMethodParameters('My\Service...', 'setCache', Array, false, 'my-service', false)
#8 …/vendor/ZendFramework/library/Zend/Di/Di.php(212): Zend\Di\Di->handleInjectionMethodForInstance(Object(My\Service), 'setCache', Array, 'my-service', false)
#9 …/vendor/ZendFramework/library/Zend/Di/Di.php(130): Zend\Di\Di->newInstance('my-service', Array)
#10 …/module/MyService/Module.php(46): Zend\Di\Di->get('my-service')


for the complete DI.conf for this moudle : https://gist.github.com/2568952




bushbaby
bushbaby multimedia 
ontwerp & uitvoering
[hidden email] | <a href="tel:%2B31%280%296%202897%207426" value="+31628977426" target="_blank">+31(0)6 2897 7426 | kvk 34125878




bushbaby
bushbaby multimedia 
ontwerp & uitvoering
[hidden email] | +31(0)6 2897 7426 | kvk 34125878

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: DI woes (cache)

basz
In reply to this post by Marco Pivetta
Loading...