From 9d3fbf8d2793f20c313be0efb2d02ff60c19a782 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Mon, 29 Jun 2020 14:24:49 +0300 Subject: [PATCH] controllers refactoring --- application/Espo/Controllers/GlobalSearch.php | 13 +++++++++++-- application/Espo/Controllers/I18n.php | 13 +++++++++++-- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/application/Espo/Controllers/GlobalSearch.php b/application/Espo/Controllers/GlobalSearch.php index 8327b3a6c0..6f9396eea1 100644 --- a/application/Espo/Controllers/GlobalSearch.php +++ b/application/Espo/Controllers/GlobalSearch.php @@ -29,8 +29,17 @@ namespace Espo\Controllers; -class GlobalSearch extends \Espo\Core\Controllers\Base +use Espo\Core\ServiceFactory; + +class GlobalSearch { + protected $serviceFactory; + + public function __construct(ServiceFactory $serviceFactory) + { + $this->serviceFactory = $serviceFactory; + } + public function actionSearch($params, $data, $request) { $query = $request->get('q'); @@ -38,6 +47,6 @@ class GlobalSearch extends \Espo\Core\Controllers\Base $offset = intval($request->get('offset')); $maxSize = intval($request->get('maxSize')); - return $this->getService('GlobalSearch')->find($query, $offset, $maxSize); + return $this->serviceFactory->create('GlobalSearch')->find($query, $offset, $maxSize); } } diff --git a/application/Espo/Controllers/I18n.php b/application/Espo/Controllers/I18n.php index 0a124ef0a0..da614c2abe 100644 --- a/application/Espo/Controllers/I18n.php +++ b/application/Espo/Controllers/I18n.php @@ -29,12 +29,21 @@ namespace Espo\Controllers; -class I18n extends \Espo\Core\Controllers\Base +use Espo\Core\ServiceFactory; + +class I18n { + protected $serviceFactory; + + public function __construct(ServiceFactory $serviceFactory) + { + $this->serviceFactory = $serviceFactory; + } + public function actionRead($params, $data, $request) { $default = $request->get('default') === 'true'; - return $this->getServiceFactory()->create('Language')->getDataForFrontend($default); + return $this->serviceFactory->create('Language')->getDataForFrontend($default); } }