Code Monkey home page Code Monkey logo

Comments (5)

marc-mabe avatar marc-mabe commented on June 14, 2024

@MatthiasKuehneEllerhold Sorry but I don't get it. Is this a question for the zend-cache component? If so please provide more information.

from zend-cache.

MatthiasKuehneEllerhold avatar MatthiasKuehneEllerhold commented on June 14, 2024

Yes its for zend-cache and its integration with zend-mvc.

I want to use my own cache-plugins (e. g. a logger) that may need dependencies to work properly (e. g. a Zend/Log instance). Ideally I want to setup a factory for this plugin in order to retrieve all dependencies and set them via constructor. See the view-helper example above.

But I found no way to register my own plugins (in zend-mvc) that aren't invokable.

Im using the StorageCacheAbstractServiceFactory with the array notation to create the zend-cache instance:

// in config/autoload/caches.php
return [
  // ...
  'caches' => [
    'my-cache' => [
      'adapter' => 'redis',
      'options' => [
        'host' => '127.0.0.1',
        'port' => 6379,
      ],
      'plugins' => [
        \Zend\Cache\Storage\Plugin\Serializer::class => [],
      ]
    ]
];

The default plugins are registered in \Zend\Cache\Storage\PluginManager and I'd like to add some factories via configuration (like my view-helper example above).

from zend-cache.

marc-mabe avatar marc-mabe commented on June 14, 2024

@MatthiasKuehneEllerhold you need to add your plugin on bootstrap phase using
Zend\Cache\StorageFactory::getPluginManager()

Cheers

from zend-cache.

marc-mabe avatar marc-mabe commented on June 14, 2024

Closing this because of no response.
In case the provided help doesn't solve your issue please feel free to re-open it again.
Thanks

from zend-cache.

MatthiasKuehneEllerhold avatar MatthiasKuehneEllerhold commented on June 14, 2024

@marc-mabe
I've added this to my Module::onBootstrap() function:

StorageFactory::getPluginManager()->setFactory(
    ExceptionLogger::class,
    ExceptionLoggerFactory::class
);

And it still uses the invokable factory for my plugin instead of the factory.

I've debugged the SM quite a bit and the plugin manager that is returned onBootstrap from StorageFactory::getPluginManager() is different than the one actually used later. Because the
StorageCacheFactory uses the PluginManagerLookupTrait which sets a new plugin manager regardless if there is one already set.

After I knew that I used this and it worked.

$container->get(\Zend\Cache\Storage\PluginManager::class)->setFactory(
    ExceptionLogger::class,
    ExceptionLoggerFactory::class
);

This is by large harder to use than every other zend-module that allows you to register factories and the like via config instead of adding them programmatically. And the singleton function StorageFactory::getPluginManager() is really misleading because it isn't a real singleton because the "singleton" will be overwritten regardless if one is already set.

The next big downside is that now I have to instantiate the plugin manager on every request because I might use the cache and its plugin. Whereas with the configuration method (from other zend modules) I'll only have to instantiate the plugin manager when I'm using the cache.

What I'm trying to champion is a similar configuration for plugins like the other zend-modules have. I'd do it myself if I understood how it works. I've looked at the SM code from the zend-view-helper manager extensivly and couldn't find how the configuration array loaded.

from zend-cache.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.