Search the Community
Showing results for tags 'dependency injection'.
-
Hello, An object, used by my module had this code : private function fetchData($exporter) { $fetched_data = file_get_contents($exporter->getFetchFullUrl()); \Logger::addLog("fetching from " . $exporter->getFetchFullUrl(), 1, null, null, null, true); return $fetched_data; } But it now throw an exception : UndefinedMethodException on the \Logger line. So I replace it with this code : public function __construct($definition_class_name) { $this->logger = new LegacyLogger(); ... } and private function fetchData($exporter) { $fetched_data = file_get_contents($exporter->getFetchFullUrl()); $this->logger->info("fetching from " . $exporter->getFetchFullUrl()); return $fetched_data; } That works fine. However, I'd like to know if this is the correct way to do it. Is it ? Can I rely on some dependency injection ? Or rely on (global) Container ?
- 2 replies
-
- dependency injection
- 1.7.4
-
(and 2 more)
Tagged with:
-
Hi All, We are new to PrestaShop shop and are developing a Module that will sync a 3rd Part POS to the local Catalogue of PrestaShop . We are mainly .Net devs and work with Nunit and Ninject in our projects for Unit testing and Dependency Injection. I have looked around the forum and Googled a fair bit and i don't see many comments/blogs/posts about how developers are testing their modules. Are there any guides on pointers that can be provided on how to develop a module using Dependency Injection as well as any php unit test framework. I have read about the PHP compatible Unit test and Dependency Injection frameworks but i can't see how to integrate it using the PrestaShop module structure We would like to keep our normal coding principals in place and develop the module using dependency Injection so we can swap our classes depending on the POS we are developing for. We would like to have our code unit tested to allow us to implement new concrete versions of our interface and have them work correctly with the underlying code that would not change between deployments.
-
- Development
- module
-
(and 4 more)
Tagged with: