Let's say that we have a structure like this:
Application
-- Modules
--Module1
-- Controller
-- PublicHelper
--Module2
-- Controller
-- PublicHelper
Whereby a module's Public Helper can provide helper functions.
In nearly every module helper, the helper needs to access another module's public helper methods.
Let's say for instance, in a PHP application:
Module1 provides functionality to create a sale, and as part of the
class Module1PublicHelper extends AbstractModuleHelper {
public function createSale($customerId, $param, $param)
{
$userPublicHelper = // grab an instance of the user public helper
$currentUser = $userPublicHelper->getCurrentUser();
}
}
class Module2PublicHelper extends AbstractModuleHelper {
public function getCurrentUser()
{
//do something
return $user;
}
}
In this situation, the method needs to obtain an instance, either new or whatever of the user public helper.
Given that all of Module Public Helper classes are instantiated with a minimum set of constructor params, e.g. EntityManager, what would be the best way to get a copy of it?
Obviously, we can't really inject the user public helper class into the class containing createSale
One solution would be to use a service locator or registry, however, testing the application isn't exactly easy.