This commit is contained in:
2026-09-15 10:35:56 +08:00
commit 782f8ea7aa
4086 changed files with 631288 additions and 0 deletions
+29
View File
@@ -0,0 +1,29 @@
<?php
namespace WeltPixel\Backend\Model\Config\Source;
/**
* @api
* @since 100.0.2
*/
class Yesno implements \Magento\Framework\Option\ArrayInterface
{
/**
* Options getter
*
* @return array
*/
public function toOptionArray()
{
return [['value' => 1, 'label' => __('Yes (Recommended)')], ['value' => 0, 'label' => __('No')]];
}
/**
* Get options in "key-value" format
*
* @return array
*/
public function toArray()
{
return [0 => __('No'), 1 => __('Yes (Recommended)')];
}
}
@@ -0,0 +1,227 @@
<?php
namespace WeltPixel\Backend\Model\ResourceModel\Debugger\Grid;
use Magento\Framework\Api\Search\SearchResultInterface;
use Magento\Framework\Search\AggregationInterface;
/**
* Class Collection
* @package WeltPixel\Bakcend\Model\ResourceModel\Debugger\Grid
*/
class Collection extends \Magento\Framework\Data\Collection implements SearchResultInterface
{
/**
* @var AggregationInterface
*/
protected $aggregations;
/**
* @var \WeltPixel\Backend\Model\Scanner
*/
protected $scanner;
/**
* @var \Magento\Backend\Model\Session
*/
protected $backendSession;
/**
* @var \Magento\Framework\DataObjectFactory
*/
protected $_dataObjectFactory;
/**
* @param \Magento\Backend\Model\Session $backendSession
* @param \WeltPixel\Backend\Model\Scanner $scanner
* @param \Magento\Framework\DataObjectFactory $dataObjectFactory
* @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
\Magento\Backend\Model\Session $backendSession,
\WeltPixel\Backend\Model\Scanner $scanner,
\Magento\Framework\DataObjectFactory $dataObjectFactory,
\Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory
)
{
parent::__construct(
$entityFactory
);
$this->_dataObjectFactory = $dataObjectFactory;
$this->scanner = $scanner;
$this->backendSession = $backendSession;
}
/**
* @return AggregationInterface
*/
public function getAggregations()
{
return $this->aggregations;
}
/**
* @param AggregationInterface $aggregations
* @return $this
*/
public function setAggregations($aggregations)
{
$this->aggregations = $aggregations;
}
/**
* Retrieve all ids for collection
* Backward compatibility with EAV collection
*
* @param int $limit
* @param int $offset
* @return array
*/
public function getAllIds($limit = null, $offset = null)
{
return $this->getConnection()->fetchCol($this->_getAllIdsSelect($limit, $offset), $this->_bindParams);
}
/**
* Get search criteria.
*
* @return \Magento\Framework\Api\SearchCriteriaInterface|null
*/
public function getSearchCriteria()
{
return null;
}
/**
* Set search criteria.
*
* @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
* @return $this
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function setSearchCriteria(?\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria = null)
{
return $this;
}
/**
* Get total count.
*
* @return int
*/
public function getTotalCount()
{
return $this->getSize();
}
/**
* Set total count.
*
* @param int $totalCount
* @return $this
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function setTotalCount($totalCount)
{
return $this;
}
/**
* Set items list.
*
* @param \Magento\Framework\Api\ExtensibleDataInterface[] $items
* @return $this
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function setItems(?array $items = null)
{
return $this;
}
/**
* @return \Magento\Framework\DataObject[]
*/
public function getItems()
{
$this->_populateCollection();
return parent::getItems();
}
public function _populateCollection()
{
$rewritesOption = $this->backendSession->getDebuggerRewite(false);
$rewrites = $this->scanner->getRewrites($rewritesOption);
$filterCondition = $this->scanner->getData('filterCondition') ?? '';
$searchKey = str_replace("\\\\\\\\", "\\", $filterCondition);
if ($searchKey) {
foreach ($rewrites as $key => $value) {
if (strpos(strtolower($key), strtolower($searchKey)) === false) {
unset($rewrites[$key]);
}
}
}
foreach ($rewrites as $originalClass => $rewriteOptions) {
foreach ($rewriteOptions as $areaCode => $rewriteClasses) {
if (count($rewriteClasses) > 1) {
$status = false;
} else {
$status = true;
}
/**
* Exceptions
* Magento\Catalog\Block\Product\ImageBuilder class we rewrite in LazyLoading, OwlCarousel modules as well
* these modules are sold as standalone ones, so we rewrite the class also in CategoryPage module
* where we merge the functionalities from those 2 modules, in this case this rewrite is marked as Ok,
*/
if (($originalClass == 'Magento\Catalog\Block\Product\ImageFactory') &&
($areaCode == 'frontend')
) {
$checkRewriteStatus = true;
foreach ($rewriteClasses as $className) {
if (strpos($className, 'WeltPixel\\') === false ) {
$checkRewriteStatus = false;
}
}
$status = $checkRewriteStatus;
}
foreach ($rewriteClasses as $key => $rewriteClass) {
$item = $this->_dataObjectFactory->create();
if ($key) {
$item->setArea('');
$item->setOriginalClass('');
} else {
$item->setArea($areaCode);
$item->setOriginalClass($originalClass);
}
$item->setRewriteClass($rewriteClass);
$item->setStatus($status);
$this->addItem($item);
}
}
}
}
/**
* Filter applied only on the original_class column
*
* @param array|string $field
* @param array|int|string $condition
* @return $this
*/
public function addFieldToFilter($field, $condition)
{
$conditionValue = substr($condition['like'], 2, -2);
$this->scanner->setData('filterCondition', $conditionValue);
return $this;
}
}
+124
View File
@@ -0,0 +1,124 @@
<?php
namespace WeltPixel\Backend\Model;
class Scanner extends \Magento\Framework\Model\AbstractModel
{
/**
* @var \Magento\Framework\App\Config\FileResolver
*/
protected $fileResolver;
/**
* @var \Magento\Framework\App\AreaList
*/
protected $areaList;
/**
* Direct usage of \Magento\Setup\Module\Di\Code\Scanner\ConfigurationScanner
* caused error on compilation
* Argument 1 passed to Magento\\Setup\\Module\\Di\\Code\\Scanner\\ConfigurationScanner::__construct()
* must be an instance of Magento\\Framework\\App\\Config\\FileResolver,
* instance of Magento\\Framework\\ObjectManager\\ObjectManager given
*
* so FileResolver and AreaList injected directly insetad
*
* @param \Magento\Framework\Model\Context $context
* @param \Magento\Framework\Registry $registry
* @param \Magento\Framework\App\Config\FileResolver $fileResolver
* @param \Magento\Framework\App\AreaList $areaList
*/
public function __construct(
\Magento\Framework\Model\Context $context,
\Magento\Framework\Registry $registry,
\Magento\Framework\App\Config\FileResolver $fileResolver,
\Magento\Framework\App\AreaList $areaList
)
{
parent::__construct($context, $registry);
$this->fileResolver = $fileResolver;
$this->areaList = $areaList;
}
/**
* \Magento\Setup\Module\Di\Code\Scanner\ConfigurationScanner scan usage,
* because the original class injection is causing error on compilation
*
* @param $fileName
* @return array
*/
public function getScannedFiles($fileName) {
$files = [];
$areaCodes = array_merge(
['primary', \Magento\Framework\App\Area::AREA_GLOBAL],
$this->areaList->getCodes()
);
foreach ($areaCodes as $area) {
$files = array_merge_recursive(
$files,
$this->fileResolver->get($fileName, $area)->toArray()
);
}
return array_keys($files);
}
/**
* @param bool $all
* @return array
*/
public function getRewrites($all = false)
{
$diFiles = $this->getScannedFiles('di.xml');
$moduleFiles = $this->getScannedFiles('module.xml');
array_walk($moduleFiles, function (&$item) {
$item = str_replace('/module.xml', '', $item);
});
if (!$all) {
foreach ($diFiles as $key => $file) {
preg_match('/(.*\/etc)/', $file, $matches);
$resultKey = $matches[1];
if (!in_array($resultKey, $moduleFiles) ||
(strpos($file, '/vendor/magento') !== false)
) {
unset($diFiles[$key]);
}
}
}
$rewrites = $this->_collectRewriteEntities($diFiles);
return $rewrites;
}
/**
* @param array $files
* @return array
*/
protected function _collectRewriteEntities(array $files)
{
$rewrites = [];
foreach ($files as $fileName) {
$areaCode = 'global';
preg_match('/\/etc\/(.*)\/di.xml/', $fileName, $matches);
if (isset($matches[1])) {
$areaCode = $matches[1];
}
$dom = new \DOMDocument();
$dom->loadXML(file_get_contents($fileName));
$xpath = new \DOMXPath($dom);
/** @var $node \DOMNode */
foreach ($xpath->query('//preference') as $node) {
$originalClass = $node->getAttribute('for');
$rewriteClass = $node->getAttribute('type');
if (!isset($rewrites[$originalClass]) || !isset($rewrites[$originalClass][$areaCode]) || !in_array($rewriteClass, $rewrites[$originalClass][$areaCode])) {
$rewrites[$originalClass][$areaCode][] = $rewriteClass;
}
}
}
return $rewrites;
}
}