mirror of
https://github.com/espocrm/espocrm.git
synced 2026-06-28 06:56:05 +00:00
refactor
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"layout": {
|
||||
"className": "Espo\\Core\\Portal\\Utils\\Layout"
|
||||
"layoutProvider": {
|
||||
"className": "Espo\\Tools\\Layout\\PortalLayoutProvider"
|
||||
},
|
||||
"themeManager": {
|
||||
"className": "Espo\\Core\\Portal\\Utils\\ThemeManager"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,6 @@ use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Utils\File\Manager as FileManager;
|
||||
use Espo\Core\Utils\Language;
|
||||
use Espo\Core\Utils\Layout;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use RuntimeException;
|
||||
|
||||
@@ -46,7 +45,7 @@ class CustomLayoutService
|
||||
private Metadata $metadata,
|
||||
private FileManager $fileManager,
|
||||
private Language $baseLanguage,
|
||||
private Layout $layout,
|
||||
private LayoutProvider $layoutProvider,
|
||||
private DataManager $dataManager
|
||||
) {}
|
||||
|
||||
@@ -75,7 +74,7 @@ class CustomLayoutService
|
||||
if (
|
||||
$this->metadata->get(['clientDefs', $scope, 'additionalLayouts', $name]) ||
|
||||
$this->fileManager->exists("application/Espo/Resources/defaults/layouts/$name") ||
|
||||
$this->layout->get($scope, $name)
|
||||
$this->layoutProvider->get($scope, $name)
|
||||
) {
|
||||
throw Conflict::createWithBody(
|
||||
"Layout $name already exists.",
|
||||
|
||||
@@ -27,15 +27,16 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Utils;
|
||||
namespace Espo\Tools\Layout;
|
||||
|
||||
use Espo\Core\InjectableFactory;
|
||||
use Espo\Core\Utils\File\Manager as FileManager;
|
||||
use Espo\Core\Utils\Json;
|
||||
use Espo\Core\Utils\Resource\FileReader;
|
||||
use Espo\Core\Utils\Resource\FileReader\Params as FileReaderParams;
|
||||
use RuntimeException;
|
||||
|
||||
class Layout
|
||||
class LayoutProvider
|
||||
{
|
||||
private string $defaultPath = 'application/Espo/Resources/defaults/layouts';
|
||||
|
||||
@@ -27,13 +27,12 @@
|
||||
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
|
||||
************************************************************************/
|
||||
|
||||
namespace Espo\Core\Portal\Utils;
|
||||
namespace Espo\Tools\Layout;
|
||||
|
||||
use Espo\Core\Utils\Layout as LayoutBase;
|
||||
use Espo\Core\Utils\Resource\FileReader\Params as FileReaderParams;
|
||||
use RuntimeException;
|
||||
|
||||
class Layout extends LayoutBase
|
||||
class PortalLayoutProvider extends LayoutProvider
|
||||
{
|
||||
public function get(string $scope, string $name): ?string
|
||||
{
|
||||
@@ -37,7 +37,6 @@ use Espo\Core\Exceptions\Forbidden;
|
||||
use Espo\Core\Exceptions\NotFound;
|
||||
use Espo\Core\ORM\EntityManager;
|
||||
use Espo\Core\Utils\Json;
|
||||
use Espo\Core\Utils\Layout as LayoutUtil;
|
||||
use Espo\Core\Utils\Metadata;
|
||||
use Espo\Entities\LayoutSet;
|
||||
use Espo\Entities\Portal;
|
||||
@@ -52,7 +51,7 @@ class Service
|
||||
{
|
||||
public function __construct(
|
||||
private Acl $acl,
|
||||
private LayoutUtil $layout,
|
||||
private LayoutProvider $layoutProvider,
|
||||
private LayoutManager $layoutManager,
|
||||
private EntityManager $entityManager,
|
||||
private Metadata $metadata,
|
||||
@@ -81,7 +80,7 @@ class Service
|
||||
}
|
||||
|
||||
if (!$result) {
|
||||
$data = $this->layout->get($scope, $name) ?? 'false';
|
||||
$data = $this->layoutProvider->get($scope, $name) ?? 'false';
|
||||
|
||||
$result = Json::decode($data);
|
||||
}
|
||||
@@ -161,7 +160,7 @@ class Service
|
||||
}
|
||||
|
||||
if (!$data) {
|
||||
$dataString = $this->layout->get($scope, $name) ?? 'null';
|
||||
$dataString = $this->layoutProvider->get($scope, $name) ?? 'null';
|
||||
|
||||
$data = Json::decode($dataString);
|
||||
}
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace Espo\Tools\LayoutManager;
|
||||
use Espo\Core\Exceptions\Error;
|
||||
use Espo\Core\Utils\File\Manager as FileManager;
|
||||
use Espo\Core\Utils\Json;
|
||||
use Espo\Core\Utils\Layout;
|
||||
use Espo\Tools\Layout\LayoutProvider;
|
||||
|
||||
use const JSON_PRETTY_PRINT;
|
||||
use const JSON_UNESCAPED_UNICODE;
|
||||
@@ -44,15 +44,17 @@ class LayoutManager
|
||||
*/
|
||||
protected $changedData = [];
|
||||
|
||||
public function __construct(protected FileManager $fileManager, protected Layout $layout)
|
||||
{}
|
||||
public function __construct(
|
||||
protected FileManager $fileManager,
|
||||
protected LayoutProvider $layoutProvider
|
||||
) {}
|
||||
|
||||
/**
|
||||
* Get layout in string format.
|
||||
*/
|
||||
public function get(string $scope, string $name): ?string
|
||||
{
|
||||
return $this->layout->get($scope, $name);
|
||||
return $this->layoutProvider->get($scope, $name);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -138,6 +140,6 @@ class LayoutManager
|
||||
protected function sanitizeInput(string $name): string
|
||||
{
|
||||
/** @var string */
|
||||
return preg_replace("([\.]{2,})", '', $name);
|
||||
return preg_replace("([.]{2,})", '', $name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
namespace tests\unit\Espo\Core\Utils;
|
||||
|
||||
use Espo\Core\Utils\Layout;
|
||||
use Espo\Tools\Layout\LayoutProvider;
|
||||
use Espo\Core\Utils\File\Manager as FileManager;
|
||||
use Espo\Core\InjectableFactory;
|
||||
|
||||
@@ -41,7 +41,7 @@ use Espo\Core\{
|
||||
class LayoutTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
/**
|
||||
* @var Layout
|
||||
* @var LayoutProvider
|
||||
*/
|
||||
private $layout;
|
||||
|
||||
@@ -65,7 +65,7 @@ class LayoutTest extends \PHPUnit\Framework\TestCase
|
||||
|
||||
$this->fileReader = $this->createMock(FileReader::class);
|
||||
|
||||
$this->layout = new Layout($this->fileManager, $this->injectableFactory, $this->fileReader);
|
||||
$this->layout = new \Espo\Tools\Layout\LayoutProvider($this->fileManager, $this->injectableFactory, $this->fileReader);
|
||||
}
|
||||
|
||||
public function testGet1(): void
|
||||
|
||||
Reference in New Issue
Block a user