From 80ab030c4aaf5bf1956d616114ec04603da146d1 Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Sat, 20 Jun 2020 17:23:20 +0300 Subject: [PATCH] entry point manager use factory --- application/Espo/Core/Application.php | 5 +++- application/Espo/Core/EntryPointManager.php | 27 ++++++++++----------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/application/Espo/Core/Application.php b/application/Espo/Core/Application.php index 65d1721967..7690ffdeac 100644 --- a/application/Espo/Core/Application.php +++ b/application/Espo/Core/Application.php @@ -111,7 +111,10 @@ class Application $slim->any('.*', function() {}); - $entryPointManager = new \Espo\Core\EntryPointManager($container); + $injectableFactory = $container->get('injectableFactory'); + $classFinder = $container->get('classFinder'); + + $entryPointManager = new \Espo\Core\EntryPointManager($injectableFactory, $classFinder); try { $authRequired = $entryPointManager->checkAuthRequired($entryPoint); diff --git a/application/Espo/Core/EntryPointManager.php b/application/Espo/Core/EntryPointManager.php index ecada6ef81..a8a49b98eb 100644 --- a/application/Espo/Core/EntryPointManager.php +++ b/application/Espo/Core/EntryPointManager.php @@ -29,29 +29,27 @@ namespace Espo\Core; -use Espo\Core\Exceptions\NotFound, - Espo\Core\Utils\Util; +use Espo\Core\Exceptions\NotFound; + +use Espo\Core\{ + InjectableFactory, + Utils\ClassFinder, +}; class EntryPointManager { - private $container; + private $injectableFactory; - public function __construct(\Espo\Core\Container $container) + public function __construct(InjectableFactory $injectableFactory, ClassFinder $classFinder) { - $this->container = $container; - } - - protected function getContainer() - { - return $this->container; + $this->injectableFactory = $injectableFactory; + $this->classFinder = $classFinder; } public function checkAuthRequired(string $name) : bool { $className = $this->getClassName($name); if (!$className) { - echo $name; - die; throw new NotFound(); } return $className::$authRequired; @@ -72,7 +70,8 @@ class EntryPointManager if (!$className) { throw new NotFound(); } - $entryPoint = new $className($this->container); + + $entryPoint = $this->injectableFactory->create($className); $entryPoint->run($data); } @@ -80,6 +79,6 @@ class EntryPointManager protected function getClassName(string $name) : ?string { $name = ucfirst($name); - return $this->getContainer()->get('classFinder')->find('EntryPoints', $name); + return $this->classFinder->find('EntryPoints', $name); } }