About Features Downloads Getting Started Documentation Events Support GitHub

Love VuFind®? Consider becoming a financial supporter. Your support helps build a better VuFind®!

Site Tools


Warning: This page has not been updated in over over a year and may be outdated or deprecated.
development:plugins:auto_injection_interfaces

Auto Injection Interfaces

Any VuFind plugin accessed through a standard plugin interface can implement certain “-Aware” interfaces in order to be automatically injected with dependencies. This is a convenient way to gain access to other elements of the VuFind system.

Here are the relevant interfaces:

  • \Laminas\Log\LoggerAwareInterface - Get access to the VuFind\Log\Logger service
  • \VuFind\Db\Table\DbTableAwareInterface - Get access to the VuFind\Db\Table\PluginManager service
  • \VuFind\I18n\Translator\TranslatorAwareInterface - Get access to the Laminas\Mvc\I18n\Translator service
  • \VuFindHttp\HttpServiceAwareInterface - Get access to the VuFindHttp\HttpService service
  • \ZfcRbac\Service\AuthorizationServiceAwareInterface - Get access to the authorization service (for permission checks)

Traits

Starting with VuFind 2.4, Traits are provided which can be used in addition to interfaces to automatically implement interface-specific methods (and in some case, useful related utility methods). These Traits can help to reduce redundancy in your code:

  • \VuFind\Db\Table\DbTableAwareTrait
  • \VuFind\I18n\Translator\TranslatorAwareTrait
  • \VuFindHttp\HttpServiceAwareTrait
  • \VuFind\Log\LoggerAwareTrait
  • \ZfcRbac\Service\AuthorizationServiceAwareInterface

Deprecated/Removed Functionality

As the framework behind VuFind has evolved, auto-injection has been recognized as an anti-pattern in many situations, and it is now largely discouraged. Thus, some related capabilities have been scaled back or removed.

  • \Zend\ServiceManager\ServiceLocatorAwareTrait used to trigger auto-injection of the top-level service manager. As of VuFind 4.0, it is no longer supported.
  • You used to be able to implement a setPluginManager() method as an alternative to implementing the \Zend\ServiceManager\ServiceLocatorAwareInterface; the result was the same. Support for setPluginManager was removed starting with VuFind 5.0.
  • In VuFind 7.0, all Zend services were renamed to Laminas services because of the rebranding of the framework.
development/plugins/auto_injection_interfaces.txt · Last modified: 2020/03/03 20:26 by demiankatz