1

I have a module that integrates with other modules from other developers. These other modules may or may not be installed, it is different for each user.

As an example, the MSG_InstantSearch module takes an array of search item objects. By default it has an item for products, categories, blog etc but it's possible to inject additional items into this array using DI. This works in the same way you can inject Router objects in using DI.

This works great because I inject the object via DI so if the module is not installed then nothing happens.

The issue occurs when compiling the DI. Each search item has to implement an interface provided by the MSG_InstantSearch module and if the module isn't installed then the interface isn't available and the DI throws an exception and won't compile.

My questions are:

  1. Is there a way to provide a fallback for a class that doesn't exist? I could specify an empty interface if the module isn't installed and the DI would compile
  2. Is there a way to exclude certain files from DI compilation?
  3. Is there anything else I can do or something I have missed?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.