diff --git a/application/Espo/Core/Application.php b/application/Espo/Core/Application.php index e49c45a61d..51e16ca949 100644 --- a/application/Espo/Core/Application.php +++ b/application/Espo/Core/Application.php @@ -91,16 +91,7 @@ class Application public function runClient() { - $config = $this->getContainer()->get('config'); - $themeManager = $this->getContainer()->get('themeManager'); - - $html = file_get_contents('main.html'); - $html = str_replace('{{cacheTimestamp}}', $config->get('cacheTimestamp', 0), $html); - $html = str_replace('{{useCache}}', $config->get('useCache') ? 'true' : 'false' , $html); - $html = str_replace('{{stylesheet}}', $themeManager->getStylesheet(), $html); - $html = str_replace('{{runScript}}', 'app.start();' , $html); - echo $html; - exit; + $this->getContainer()->get('clientManager')->display(); } public function runEntryPoint($entryPoint) diff --git a/application/Espo/Core/Container.php b/application/Espo/Core/Container.php index 2ef00ea576..d5da3d4cc2 100644 --- a/application/Espo/Core/Container.php +++ b/application/Espo/Core/Container.php @@ -295,6 +295,14 @@ class Container ); } + private function loadClientManager() + { + return new \Espo\Core\Utils\ClientManager( + $this->get('config'), + $this->get('themeManager') + ); + } + public function setUser($user) { $this->data['user'] = $user; diff --git a/application/Espo/Core/EntryPoints/Base.php b/application/Espo/Core/EntryPoints/Base.php index 42ae28284d..a3002cbc72 100644 --- a/application/Espo/Core/EntryPoints/Base.php +++ b/application/Espo/Core/EntryPoints/Base.php @@ -94,6 +94,11 @@ abstract class Base return $this->getContainer()->get('language'); } + protected function getClientManager() + { + return $this->getContainer()->get('clientManager'); + } + public function __construct(Container $container) { $this->container = $container; diff --git a/application/Espo/Core/Utils/ClientManager.php b/application/Espo/Core/Utils/ClientManager.php new file mode 100644 index 0000000000..aa237d6245 --- /dev/null +++ b/application/Espo/Core/Utils/ClientManager.php @@ -0,0 +1,84 @@ +config = $config; + $this->themeManager = $themeManager; + + if ($this->config->get('isDeveperMode')) { + $this->mainHtmlFilePath = $this->htmlFilePathForDeveloperMode; + } + } + + protected function getThemeManager() + { + return $this->themeManager; + } + + protected function getConfig() + { + return $this->config; + } + + public function display($runScript = null, $mainHtmlFilePath = null) + { + if (is_null($runScript)) { + $runScript = $this->runScript; + } + if (is_null($mainHtmlFilePath)) { + $mainHtmlFilePath = $this->mainHtmlFilePath; + } + + $html = file_get_contents($mainHtmlFilePath); + $html = str_replace('{{cacheTimestamp}}', $this->getConfig()->get('cacheTimestamp', 0), $html); + $html = str_replace('{{useCache}}', $this->getConfig()->get('useCache') ? 'true' : 'false' , $html); + $html = str_replace('{{stylesheet}}', $this->getThemeManager()->getStylesheet(), $html); + $html = str_replace('{{runScript}}', $runScript , $html); + + echo $html; + exit; + } +} + + diff --git a/application/Espo/EntryPoints/ChangePassword.php b/application/Espo/EntryPoints/ChangePassword.php index bdb3686819..afda700b4d 100644 --- a/application/Espo/EntryPoints/ChangePassword.php +++ b/application/Espo/EntryPoints/ChangePassword.php @@ -56,18 +56,12 @@ class ChangePassword extends \Espo\Core\EntryPoints\Base } $runScript = " - app.getController('PasswordChangeRequest', function (controller) { - controller.doAction('passwordChange', '{$requestId}'); - }); + app.getController('PasswordChangeRequest', function (controller) { + controller.doAction('passwordChange', '{$requestId}'); + }); "; - $html = file_get_contents('main.html'); - $html = str_replace('{{cacheTimestamp}}', $config->get('cacheTimestamp', 0), $html); - $html = str_replace('{{useCache}}', $config->get('useCache') ? 'true' : 'false' , $html); - $html = str_replace('{{stylesheet}}', $themeManager->getStylesheet(), $html); - $html = str_replace('{{runScript}}', $runScript , $html); - echo $html; - exit; + $this->getClientManager()->display($runScript); } protected function getThemeManager() diff --git a/frontend/index.php b/frontend/index.php index 9908b1361b..61f2426bdb 100644 --- a/frontend/index.php +++ b/frontend/index.php @@ -36,12 +36,6 @@ if (!empty($_GET['entryPoint'])) { exit; } -$themeManager = $app->getContainer()->get('themeManager'); - -$runScript = "app.start();"; -$html = file_get_contents("frontend/main.html"); -$html = str_replace('{{stylesheet}}', $themeManager->getStylesheet() , $html); -$html = str_replace('{{runScript}}', $runScript , $html); -echo $html; -exit; +$clientManager = $app->getContainer()->get('clientManager'); +$clientManager->display();