translateInline = $translateInline; $this->jsonSerializer = $jsonSerializer ?: ObjectManager::getInstance()->get(Json::class); $this->base64jsonSerializer = $base64jsonSerializer ?: ObjectManager::getInstance()->get(Base64Json::class); $this->layoutCacheKey = $layoutCacheKey ?: ObjectManager::getInstance()->get(LayoutCacheKeyInterface::class); $this->regexValidatorFactory = $regexValidatorFactory ?: ObjectManager::getInstance()->get(RegexFactory::class); $this->config = $scopeConfig ?: ObjectManager::getInstance()->get(ScopeConfigInterface::class); } /** * Get blocks from layout by handles * * @return array [\Element\BlockInterface] */ protected function _getBlocks() { $blocks = $this->getRequest()->getParam('blocks', ''); $handles = $this->getRequest()->getParam('handles', ''); if (!$handles || !$blocks) { return []; } $blocks = $this->jsonSerializer->unserialize($blocks); $handles = $this->base64jsonSerializer->unserialize($handles); $handleSize = (int) $this->config->getValue(self::XML_HANDLES_SIZE); $handles = ($handleSize && count($handles) > $handleSize) ? array_splice($handles, 0, $handleSize) : $handles; if (!$this->validateHandleParam($handles)) { return []; } $layout = $this->_view->getLayout(); $this->layoutCacheKey->addCacheKeys($this->layoutCacheKeyName); $this->_view->loadLayout($handles, true, true, false); $data = []; foreach ($blocks as $blockName) { $blockInstance = $layout->getBlock($blockName); if (is_object($blockInstance)) { $data[$blockName] = $blockInstance; } } return $data; } /** * Validates handles parameter * * @param array $handles * @return bool */ private function validateHandleParam($handles): bool { $validator = $this->regexValidatorFactory->create(['pattern' => self::VALIDATION_RULE_PATTERN]); foreach ($handles as $handle) { if ($handle && !$validator->isValid($handle)) { return false; } } return true; } }