entry point manager use factory

This commit is contained in:
Yuri Kuznetsov
2020-06-20 17:23:20 +03:00
parent 5483919dd3
commit 80ab030c4a
2 changed files with 17 additions and 15 deletions

View File

@@ -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);

View File

@@ -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);
}
}