Skip to content

Commit fa9517b

Browse files
committed
Code style changes + improvements
1 parent 61338d0 commit fa9517b

File tree

10 files changed

+122
-73
lines changed

10 files changed

+122
-73
lines changed
+11-28
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © 2017 Ihor Vansach (ihor@magefan.com). All rights reserved.
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
44
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
55
*
66
* Glory to Ukraine! Glory to the heroes!
@@ -11,42 +11,25 @@
1111
use Magento\Store\Model\ScopeInterface;
1212

1313
/**
14-
* Admin blog configurations information block
14+
* Admin configurations information block
1515
*/
16-
class Info extends \Magento\Config\Block\System\Config\Form\Field
16+
class Info extends \Magefan\Community\Block\Adminhtml\System\Config\Form\Info
1717
{
1818
/**
19-
* @var \Magento\Framework\Module\ModuleListInterface
20-
*/
21-
protected $moduleList;
22-
23-
/**
24-
* @param \Magento\Framework\Module\ModuleListInterface $moduleList
25-
* @param \Magento\Backend\Block\Template\Context $context
26-
* @param array $data
19+
* Return extension url
20+
* @return string
2721
*/
28-
public function __construct(
29-
\Magento\Framework\Module\ModuleListInterface $moduleList,
30-
\Magento\Backend\Block\Template\Context $context,
31-
array $data = []
32-
) {
33-
parent::__construct($context, $data);
34-
$this->moduleList = $moduleList;
22+
protected function getModuleUrl()
23+
{
24+
return 'https://magefan.com/rocket-javascript-deferred-javascript?utm_source=m2admin_rocket_javascript_config&utm_medium=link&utm_campaign=regular';
3525
}
3626

3727
/**
38-
* Return info block html
39-
* @param \Magento\Framework\Data\Form\Element\AbstractElement $element
28+
* Return extension title
4029
* @return string
4130
*/
42-
public function render(\Magento\Framework\Data\Form\Element\AbstractElement $element)
31+
protected function getModuleTitle()
4332
{
44-
$m = $this->moduleList->getOne($this->getModuleName());
45-
$html = '<div style="padding:10px;background-color:#f8f8f8;border:1px solid #ddd;margin-bottom:7px;">
46-
Rocket JavaScript Extension v' . $m['setup_version'] . ' was developed by <a href="http://magefan.com/" target="_blank">Magefan</a>.
47-
</div>';
48-
49-
return $html;
33+
return 'Rocket JavaScript Extension';
5034
}
51-
5235
}

Model/Controller/ResultPlugin.php

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © 2017 Ihor Vansach (ihor@magefan.com). All rights reserved.
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
44
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
55
*
66
* Glory to Ukraine! Glory to the heroes!
@@ -17,7 +17,7 @@ class ResultPlugin
1717
{
1818
const EXCLUDE_FLAG_PATTERN = 'data-rocketjavascript="false"';
1919

20-
/**
20+
/**
2121
* Request
2222
* @var \Magento\Framework\App\RequestInterface
2323
*/
@@ -69,7 +69,7 @@ public function aroundRenderResult(
6969
$jsHtml = [];
7070

7171
foreach ($patterns as $pattern) {
72-
$matches = array();
72+
$matches = [];
7373
$success = preg_match_all($pattern, $html, $matches);
7474
if ($success) {
7575
foreach ($matches[0] as $i => $js) {
@@ -105,21 +105,21 @@ private function isEnabled()
105105

106106
/* check if Plumrocket AMP enabled */
107107
if ($enabled) {
108-
$isAmpRequest = $this->scopeConfig->getValue(
109-
'pramp/general/enabled',
110-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
111-
);
108+
$isAmpRequest = $this->scopeConfig->getValue(
109+
'pramp/general/enabled',
110+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
111+
);
112112

113-
if ($isAmpRequest) {
114-
/* We know that using objectManager is not a not a good practice,
113+
if ($isAmpRequest) {
114+
/* We know that using objectManager is not a not a good practice,
115115
but if Plumrocket_AMP is not installed on your magento instance
116116
you'll get error during di:compile */
117-
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
118-
$isAmpRequest = $objectManager->get('\Plumrocket\Amp\Helper\Data')
119-
->isAmpRequest();
120-
}
117+
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
118+
$isAmpRequest = $objectManager->get('\Plumrocket\Amp\Helper\Data')
119+
->isAmpRequest();
120+
}
121121

122-
$enabled = !$isAmpRequest;
122+
$enabled = !$isAmpRequest;
123123
}
124124

125125
return $enabled;
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,59 @@
11
<?php
2+
/**
3+
* Copyright © Magefan ([email protected]). All rights reserved.
4+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
5+
*
6+
* Glory to Ukraine! Glory to the heroes!
7+
*/
8+
29
namespace Magefan\RocketJavaScript\Plugin\Deploy\Package\Bundle;
310

411
use Magento\Deploy\Package\Bundle\RequireJs;
12+
use Magento\Framework\App\Config\ScopeConfigInterface;
13+
use Magento\Store\Model\ScopeInterface;
514

615
class RequireJsPlugin
716
{
17+
18+
/**
19+
* @var string
20+
*/
21+
const BUNDLING_OPTIMIZATION_ENABLED = 'mfrocketjavascript/general/enable_js_bundling_optimization';
22+
23+
/**
24+
* @var string
25+
*/
26+
const INCLUDE_IN_BUNDLING = 'mfrocketjavascript/general/included_in_bundling';
27+
28+
/**
29+
* @var \Magento\Framework\App\Config\ScopeConfigInterface
30+
*/
831
protected $scopeConfig;
932

10-
public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig)
33+
/**
34+
* mixed
35+
*/
36+
protected $allowedFiles;
37+
38+
/**
39+
* Construct
40+
*
41+
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
42+
*/
43+
public function __construct(ScopeConfigInterface $scopeConfig)
1144
{
1245
$this->scopeConfig = $scopeConfig;
1346
}
1447

15-
public function aroundAddFile(RequireJs $subject, callable $proceed, $filePath, $sourcePath, $contentType) {
48+
/**
49+
* Improve bundling
50+
*/
51+
public function aroundAddFile(RequireJs $subject, callable $proceed, $filePath, $sourcePath, $contentType)
52+
{
1653

17-
$jsOptimization = $this->scopeConfig->getValue('mfrocketjavascript/general/enable_javaScript_bundling_optimization', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
54+
$jsOptimization = $this->scopeConfig->getValue(self::BUNDLING_OPTIMIZATION_ENABLED, ScopeInterface::SCOPE_STORE);
1855
if ($jsOptimization) {
19-
$includeInBundling = $this->scopeConfig->getValue('mfrocketjavascript/general/included_in_bundling', \Magento\Store\Model\ScopeInterface::SCOPE_STORE);
20-
$allowedFiles = str_replace("\r","\n", $includeInBundling);
21-
$allowedFiles = explode("\n", $allowedFiles);
22-
23-
foreach ($allowedFiles as $key => $allowedFile) {
24-
$allowedFiles[$key] = trim($allowedFile);
25-
if (empty($allowedFiles[$key])) {
26-
unset($allowedFiles[$key]);
27-
}
28-
}
29-
30-
foreach ($allowedFiles as $allowed) {
31-
$allowedFiles[] = str_replace('.min.js', '.js', $allowed);
32-
}
56+
$allowedFiles = $this->getAllowedFiles();
3357

3458
$include = false;
3559
foreach ($allowedFiles as $allowedFile) {
@@ -42,8 +66,35 @@ public function aroundAddFile(RequireJs $subject, callable $proceed, $filePath,
4266
if (!$include) {
4367
return true;
4468
}
45-
4669
}
4770
return $proceed($filePath, $sourcePath, $contentType);
4871
}
49-
}
72+
73+
public function getAllowedFiles()
74+
{
75+
if (null === $this->allowedFiles) {
76+
$includeInBundling = $this->scopeConfig->getValue(self::INCLUDE_IN_BUNDLING, ScopeInterface::SCOPE_STORE);
77+
$allowedFiles = str_replace("\r", "\n", $includeInBundling);
78+
$allowedFiles = explode("\n", $allowedFiles);
79+
80+
foreach ($allowedFiles as $key => $allowedFile) {
81+
$allowedFiles[$key] = trim($allowedFile);
82+
if (empty($allowedFiles[$key])) {
83+
unset($allowedFiles[$key]);
84+
}
85+
}
86+
87+
foreach ($allowedFiles as $allowed) {
88+
if (false !== strpos($allowed, '.min.js')) {
89+
$allowedFiles[] = str_replace('.min.js', '.js', $allowed);
90+
} else {
91+
$allowedFiles[] = str_replace('.js', '.min.js', $allowed);
92+
}
93+
}
94+
95+
$this->allowedFiles = $allowedFiles;
96+
}
97+
98+
return $this->allowedFiles;
99+
}
100+
}

composer.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
{
22
"name": "magefan/module-rocketjavascript",
33
"description": "Move all javascripts to the footer on Magento 2 store.",
4+
"require": {
5+
"php": "~5.6.5 || >=7.0",
6+
"magefan/module-community" : ">=2.0.1"
7+
},
48
"type": "magento2-module",
5-
"version": "2.0.0",
9+
"version": "2.1.0",
610
"license": "OSL-3.0",
711
"authors": [
812
{

etc/acl.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" ?>
22
<!--
33
/**
4-
* Copyright © 2017 Ihor Vansach (ihor@magefan.com). All rights reserved.
4+
* Copyright © Magefan (support@magefan.com). All rights reserved.
55
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
66
*
77
* Glory to Ukraine! Glory to the heroes!

etc/adminhtml/system.xml

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
11
<?xml version="1.0" ?>
22
<!--
33
/**
4-
* Copyright © 2017 Ihor Vansach (ihor@magefan.com). All rights reserved.
4+
* Copyright © Magefan (support@magefan.com). All rights reserved.
55
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
66
*
77
* Glory to Ukraine! Glory to the heroes!
88
*/
99
-->
1010
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
1111
<system>
12-
<tab id="magefan" sortOrder="110" translate="label">
13-
<label>Magefan Extensions</label>
14-
</tab>
1512
<section id="mfrocketjavascript" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="10" translate="label">
1613
<label>Rocket JavasSript</label>
1714
<tab>magefan</tab>
@@ -27,15 +24,17 @@
2724
<comment>If enabled all JavaScript on storefront will be moved to the end of the page.</comment>
2825
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
2926
</field>
30-
<field id="enable_javaScript_bundling_optimization" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="30" translate="label" type="select">
27+
<field id="enable_js_bundling_optimization" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="30" translate="label" type="select">
3128
<label>Enable JavaScript Bundling Optimization</label>
29+
<comment>Please note that this option only works with enabled JavaScript Bundling (Configuration > Advanced > Developer > JavaScript Settings > Enable JavaScript Bundling).</comment>
3230
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
3331
</field>
3432
<field id="included_in_bundling" showInDefault="1" showInStore="1" showInWebsite="1" sortOrder="40" translate="label" type="textarea">
3533
<label>Included In Bundling</label>
3634
<depends>
37-
<field id="enable_javaScript_bundling_optimization">1</field>
35+
<field id="enable_js_bundling_optimization">1</field>
3836
</depends>
37+
<comment>List of files that included in JS bundle.</comment>
3938
</field>
4039
</group>
4140
</section>

etc/di.xml

+8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magefan ([email protected]). All rights reserved.
5+
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
6+
*
7+
* Glory to Ukraine! Glory to the heroes!
8+
*/
9+
-->
210
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
311
<type name="Magento\Deploy\Package\Bundle\RequireJs">
412
<plugin name="magefan_rocketjavascript_plugin_deploy_package_bundle_requirejs"

etc/frontend/di.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0"?>
22
<!--
33
/**
4-
* Copyright © 2017 Ihor Vansach (ihor@magefan.com). All rights reserved.
4+
* Copyright © Magefan (support@magefan.com). All rights reserved.
55
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
66
*
77
* Glory to Ukraine! Glory to the heroes!

etc/module.xml

+6-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
<?xml version="1.0" ?>
22
<!--
33
/**
4-
* Copyright © 2017 Ihor Vansach (ihor@magefan.com). All rights reserved.
4+
* Copyright © Magefan (support@magefan.com). All rights reserved.
55
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
66
*
77
* Glory to Ukraine! Glory to the heroes!
88
*/
99
-->
1010
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
11-
<module name="Magefan_RocketJavaScript" setup_version="2.0.0"/>
11+
<module name="Magefan_RocketJavaScript" setup_version="2.1.0">
12+
<sequence>
13+
<module name="Magefan_Community"/>
14+
</sequence>
15+
</module>
1216
</config>

registration.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22
/**
3-
* Copyright © 2017 Ihor Vansach (ihor@magefan.com). All rights reserved.
3+
* Copyright © Magefan (support@magefan.com). All rights reserved.
44
* See LICENSE.txt for license details (http://opensource.org/licenses/osl-3.0.php).
55
*
66
* Glory to Ukraine! Glory to the heroes!

0 commit comments

Comments
 (0)