seb776 Posted September 26, 2018 Share Posted September 26, 2018 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 ? Link to comment Share on other sites More sharing options...
seb776 Posted September 27, 2018 Author Share Posted September 27, 2018 I guess using the serviceLocator is a better Option. ServiceLocator::get(LegacyLogger::class); but finaly, no because it should be removed ( :confused: ) /** * @internal * * To be removed in 1.7.1. */ class ServiceLocator { ... } Any idea / guidelines ? Link to comment Share on other sites More sharing options...
seb776 Posted October 1, 2018 Author Share Posted October 1, 2018 Finaly : The service locator can be used, in admin, until prestashop 1.8. correct way is : ServiceLocator::get('prestashop.adapter.legacy.logger'); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now