diff --git a/src/QUI/Bricks/Brick.php b/src/QUI/Bricks/Brick.php index b3b49aaece95de42c64b10944805398867474877..fab9cf4d4bbdeb2bf8a478ab8d1fcc9f0b61f93f 100644 --- a/src/QUI/Bricks/Brick.php +++ b/src/QUI/Bricks/Brick.php @@ -20,7 +20,7 @@ class Brick extends QUI\QDOM /** * internal brick id * - * @var + * @var int|bool */ protected $id = false; @@ -37,33 +37,33 @@ class Brick extends QUI\QDOM * * @var array */ - protected $settings = []; + protected array $settings = []; /** * Fields can be overwritten by another user * * @var array */ - protected $customfields = []; + protected array $customfields = []; /** * Internal control * * @var null|QUI\Control */ - protected $Control = null; + protected ?QUI\Control $Control = null; /** * List of extra css classes * * @var array */ - protected $cssClasses = []; + protected array $cssClasses = []; /** * @var string */ - protected $hash; + protected string $hash; /** * Constructor @@ -187,7 +187,7 @@ public function __construct($params = []) * * @return String */ - public function getType() + public function getType(): string { $Control = $this->getControl(); @@ -204,7 +204,7 @@ public function getType() * @param string $className * @return bool */ - public function isInstanceOf($className) + public function isInstanceOf($className): bool { $Control = $this->getControl(); @@ -216,12 +216,12 @@ public function isInstanceOf($className) } /** - * Check, if control canbe created + * Check, if control can be created * * @return QUI\Bricks\Brick * @throws QUI\Exception */ - public function check() + public function check(): Brick { if ($this->getAttribute('type') == 'content') { return $this; @@ -244,7 +244,7 @@ public function check() * * @return string */ - protected function createBrickHash() + protected function createBrickHash(): string { $attributes = $this->getAttributes(); $hashParams = []; @@ -270,13 +270,17 @@ protected function createBrickHash() * * @throws QUI\Exception */ - public function create() + public function create(): string { $cacheName = Manager::getBrickCacheNamespace() .\md5($this->getType()) .'/' .$this->hash; + if ($this->uniqueId) { + $cacheName .= '/'.$this->uniqueId; + } + if ($this->getAttribute('cacheable')) { try { $data = QUI\Cache\Manager::get($cacheName); @@ -446,7 +450,7 @@ protected function getControl() } - if (!($Control instanceof QUI\Control) || !$Control) { + if (!($Control instanceof QUI\Control)) { return false; } @@ -464,7 +468,7 @@ protected function getControl() * * @return array */ - public function getSettings() + public function getSettings(): array { $this->settings['classes'] = $this->getCSSClasses(); @@ -497,7 +501,7 @@ public function setSettings(array $settings) * * @return boolean|string|array */ - public function getSetting($name) + public function getSetting(string $name) { if ($name === 'classes') { return $this->getCSSClasses(); @@ -514,11 +518,11 @@ public function getSetting($name) * Set a brick setting * * @param string $name - name of the setting - * @param string $value - value of the setting + * @param mixed $value - value of the setting * * @return void */ - public function setSetting($name, $value) + public function setSetting(string $name, $value) { if (isset($this->settings[$name])) { $this->settings[$name] = $value; @@ -531,7 +535,7 @@ public function setSetting($name, $value) /** * @param string $name - * @return array|mixed + * @return mixed */ public function getAttribute($name) { @@ -545,7 +549,7 @@ public function getAttribute($name) /** * @return array */ - public function getAttributes() + public function getAttributes(): array { $attributes = parent::getAttributes(); $attributes['classes'] = $this->getCSSClasses(); @@ -558,7 +562,7 @@ public function getAttributes() * * @return array */ - public function getCustomFields() + public function getCustomFields(): array { return $this->customfields; } @@ -570,7 +574,7 @@ public function getCustomFields() * * @return void */ - public function addCSSClass($cssClass) + public function addCSSClass(string $cssClass) { if (\is_array($cssClass)) { $cssClass = \implode(' ', $cssClass); @@ -610,7 +614,7 @@ public function clearCSSClasses() * * @return array */ - public function getCSSClasses() + public function getCSSClasses(): array { return $this->cssClasses; } @@ -622,7 +626,7 @@ public function getCSSClasses() * * @return boolean */ - public function hasCSSClass($pattern) + public function hasCSSClass(string $pattern): bool { $cssClasses = $this->getAttribute('classes'); diff --git a/src/QUI/Bricks/Manager.php b/src/QUI/Bricks/Manager.php index 37f29d3a5db704d494b2395a94020840970efd7b..f7e7d5dcebe0cd9914240019683ef00233813e1f 100644 --- a/src/QUI/Bricks/Manager.php +++ b/src/QUI/Bricks/Manager.php @@ -38,31 +38,31 @@ class Manager * * @var array */ - protected $bricks = []; + protected array $bricks = []; /** * Brick UID temp collector * * @var array */ - protected $brickUIDs = []; + protected array $brickUIDs = []; /** * Initialized brick manager * - * @var null + * @var null|Manager */ - public static $BrickManager = null; + public static ?Manager $BrickManager = null; /** * Return the global QUI\Bricks\Manager * * @return Manager */ - public static function init() + public static function init(): ?Manager { if (self::$BrickManager === null) { - self::$BrickManager = new QUI\Bricks\Manager(true); + self::$BrickManager = new Manager(true); } return self::$BrickManager; @@ -86,7 +86,7 @@ public function __construct($init = false) * * @return String */ - public static function getTable() + public static function getTable(): string { return QUI::getDBTableName(self::TABLE); } @@ -94,7 +94,7 @@ public static function getTable() /** * @return string */ - public static function getUIDTable() + public static function getUIDTable(): string { return QUI::getDBTableName(self::TABLE_UID); } @@ -104,7 +104,7 @@ public static function getUIDTable() * * @return string */ - public static function getBrickCacheNamespace() + public static function getBrickCacheNamespace(): string { return 'quiqqer/package/quiqqer/bricks/'; } @@ -119,7 +119,7 @@ public static function getBrickCacheNamespace() * * @throws QUI\Exception */ - public function createBrickForProject(Project $Project, Brick $Brick) + public function createBrickForProject(Project $Project, Brick $Brick): int { QUI\Permissions\Permission::checkPermission('quiqqer.bricks.create'); @@ -134,9 +134,7 @@ public function createBrickForProject(Project $Project, Brick $Brick) ] ); - $lastId = QUI::getPDO()->lastInsertId(); - - return $lastId; + return QUI::getPDO()->lastInsertId(); } /** @@ -189,7 +187,7 @@ public function createUniqueSiteBrick(Site $Site, $brickData = []) * * @throws QUI\Exception */ - protected function createUniqueBrickId($brickId, $Site) + protected function createUniqueBrickId(int $brickId, Site $Site): bool { $Project = $Site->getProject(); $uuid = QUI\Utils\Uuid::get(); @@ -213,7 +211,7 @@ protected function createUniqueBrickId($brickId, $Site) * @param string $uid - Brick Unique ID * @return bool */ - public function existsUniqueBrickId($uid) + public function existsUniqueBrickId(string $uid): bool { try { $result = QUI::getDataBase()->fetch([ @@ -408,7 +406,7 @@ public function getAreasByProject(Project $Project, $layoutType = false) * * @return array */ - public function getAvailableBricks() + public function getAvailableBricks(): array { $cache = 'quiqqer/bricks/availableBricks'; @@ -461,7 +459,7 @@ public function getAvailableBricks() * @return Brick * @throws QUI\Exception */ - public function getBrickById($id) + public function getBrickById($id): Brick { if (isset($this->bricks[$id])) { return $this->bricks[$id]; @@ -558,7 +556,7 @@ public function getBrickByUID($uid) * * @return array */ - public function getAvailableBrickSettingsByBrickType($brickType) + public function getAvailableBrickSettingsByBrickType($brickType): array { $cache = 'quiqqer/bricks/brickType/'.\md5($brickType); @@ -653,7 +651,7 @@ public function getAvailableBrickSettingsByBrickType($brickType) * @param \DOMElement $Setting * @return array */ - protected function parseSettingToBrickArray(\DOMElement $Setting) + protected function parseSettingToBrickArray(\DOMElement $Setting): array { /* @var $Option \DOMElement */ $options = false; @@ -708,7 +706,7 @@ protected function parseSettingToBrickArray(\DOMElement $Setting) * * @return array */ - public function getBricksByArea($brickArea, QUI\Interfaces\Projects\Site $Site) + public function getBricksByArea($brickArea, QUI\Interfaces\Projects\Site $Site): array { if (empty($brickArea)) { return []; @@ -792,7 +790,7 @@ public function getBricksByArea($brickArea, QUI\Interfaces\Projects\Site $Site) * * @throws QUI\Exception */ - public function getBricksFromProject(Project $Project) + public function getBricksFromProject(Project $Project): array { $result = []; @@ -818,7 +816,7 @@ public function getBricksFromProject(Project $Project) * @param Brick $Brick * @return array */ - public function getSitesByBrick(Brick $Brick) + public function getSitesByBrick(Brick $Brick): array { try { $list = QUI::getDataBase()->fetch([ @@ -1067,7 +1065,7 @@ public function saveBrick($brickId, array $brickData) * * @throws QUI\Exception */ - public function copyBrick($brickId, $params = []) + public function copyBrick($brickId, $params = []): int { QUI\Permissions\Permission::checkPermission('quiqqer.bricks.create'); @@ -1102,9 +1100,7 @@ public function copyBrick($brickId, $params = []) QUI::getDataBase()->insert($this->getTable(), $data); - $lastId = QUI::getPDO()->lastInsertId(); - - return $lastId; + return QUI::getPDO()->lastInsertId(); } /** @@ -1112,7 +1108,7 @@ public function copyBrick($brickId, $params = []) * * @return array */ - protected function getBricksXMLFiles() + protected function getBricksXMLFiles(): array { return Utils::getBricksXMLFiles(); } @@ -1125,7 +1121,7 @@ protected function getBricksXMLFiles() * * @return array */ - protected function getInheritedBricks($brickArea, QUI\Interfaces\Projects\Site $Site) + protected function getInheritedBricks($brickArea, QUI\Interfaces\Projects\Site $Site): array { // inheritance ( vererbung ) $Project = $Site->getProject();