Skip to content

Commit

Permalink
Default / Additional layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
phoenix128 committed Nov 20, 2017
1 parent 2bd0fe8 commit 6afc006
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 10 deletions.
73 changes: 64 additions & 9 deletions Model/PageInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
use Magento\Framework\Interception\DefinitionInterface;
use Magento\Framework\App\ResourceConnection;

/**
* Class PageInfo
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class PageInfo
{
/**
Expand Down Expand Up @@ -97,6 +101,23 @@ class PageInfo
*/
private $collectionRegistry;

/**
* PageInfo constructor.
* @param ProductMetadataInterface $productMetadata
* @param LayoutInterface $layout
* @param RequestInterface $request
* @param EventRegistry $eventRegistry
* @param ElementRegistry $elementRegistry
* @param DataModelRegistry $dataModelRegistry
* @param CollectionRegistry $collectionRegistry
* @param DesignInterface $designInterface
* @param Http $httpRequest
* @param Config $config
* @param Stat $stat
* @param ResourceConnection $resource
* @param PluginList $pluginList
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
*/
public function __construct(
ProductMetadataInterface $productMetadata,
LayoutInterface $layout,
Expand Down Expand Up @@ -129,16 +150,32 @@ public function __construct(

/**
* Get page information
*
* @return array
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function getPageInfo()
{
$layoutUpdates = $this->layout->getUpdate();
$request = $this->request;
$httpRequest = $this->httpRequest;
$design = $this->design;

try {
$layoutUpdates = $this->layout->getUpdate();
$allLayoutHandles = $layoutUpdates->getHandles();
} catch (\Exception $e) {
$allLayoutHandles = [];
}

$addedLayoutHandles = [];
$layoutHandles = [];
foreach ($allLayoutHandles as $layoutHandle) {
if (in_array($layoutHandle, ['default', $httpRequest->getFullActionName()])) {
$layoutHandles[] = $layoutHandle;
} else {
$addedLayoutHandles[] = $layoutHandle;
}
}

$themeInheritance = [];

$theme = $design->getDesignTheme();
Expand Down Expand Up @@ -184,7 +221,12 @@ public function getPageInfo()
[
'id' => 'handles',
'label' => 'Layout Handles',
'value' => $layoutUpdates->getHandles(),
'value' => $layoutHandles,
'type' => 'complex'
], [
'id' => 'additional_handles',
'label' => 'Additional Handles',
'value' => $addedLayoutHandles,
'type' => 'complex'
], [
'id' => 'theme_code',
Expand Down Expand Up @@ -212,11 +254,17 @@ public function getPageInfo()
return $info;
}


/**
* Get a list of plugins
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
public function getPluginsList()
{
$plugins = [];
// @codingStandardsIgnoreStart
$reflection = new \ReflectionClass($this->pluginList);
// @codingStandardsIgnoreEnd

$processed = $reflection->getProperty('_processed');
$processed->setAccessible(true);
Expand All @@ -243,13 +291,15 @@ public function getPluginsList()
$method = $matches[2];

if (!empty($inherited[$type])) {
foreach($processDef as $keyType => $pluginsNames) {
foreach ($processDef as $keyType => $pluginsNames) {
if (!is_array($pluginsNames)) {
$pluginsNames = [$pluginsNames];
}

$classMethod = $type . '::' . $method;
// @codingStandardsIgnoreStart
$key = md5($classMethod);
// @codingStandardsIgnoreEnd

if (!isset($plugins[$key])) {
$fileName = $this->config->getPhpClassFile($type);
Expand All @@ -275,7 +325,7 @@ public function getPluginsList()

foreach ($pluginsNames as $pluginName) {
if (!empty($inherited[$type][$pluginName])) {
$sortOrder = intval($inherited[$type][$pluginName]['sortOrder']);
$sortOrder = (int) $inherited[$type][$pluginName]['sortOrder'];

$fileName = $this->config->getPhpClassFile(
$inherited[$type][$pluginName]['instance']
Expand Down Expand Up @@ -304,7 +354,12 @@ public function getPluginsList()
return $plugins;
}

protected function getSqlProfilerData()
/**
* Get a list of plugins
* @return array
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
private function getSqlProfilerData()
{
$allQueries = [];
$sqlProfiler = $this->resource->getConnection('read')->getProfiler();
Expand Down Expand Up @@ -342,7 +397,7 @@ protected function getSqlProfilerData()

$squareSum = 0;

foreach ($allQueries as $index=>$query) {
foreach ($allQueries as $index => $query) {
$squareSum = pow($query['time'] - $average, 2);
}

Expand All @@ -353,7 +408,7 @@ protected function getSqlProfilerData()
foreach ($allQueries as $index => $query) {
if ($query['time'] < ($shortestQueryTime + 2*$standardDeviation)) {
$allQueries[$index]['grade'] = 'good';
} elseif($query['time'] > ($longestQueryTime - 2*$standardDeviation)) {
} elseif ($query['time'] > ($longestQueryTime - 2*$standardDeviation)) {
$allQueries[$index]['grade'] = 'bad';
}

Expand Down
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="MSP_DevTools" setup_version="1.2.8">
<module name="MSP_DevTools" setup_version="1.2.9">
<sequence>
<module name="MSP_Common"/>

Expand Down

0 comments on commit 6afc006

Please sign in to comment.