-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c74e221
commit 4ec3b5d
Showing
15 changed files
with
337 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
/** | ||
* Copyright (c) 2019. Volodymyr Hryvinskyi. All rights reserved. | ||
* @author: <mailto:[email protected]> | ||
* @github: <https://github.com/hryvinskyi> | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Hryvinskyi\DeferJs\Model\PassesValidator; | ||
|
||
/** | ||
* Class EntityList | ||
*/ | ||
class EntityList | ||
{ | ||
/** | ||
* @var string[] | ||
*/ | ||
private $entityTypes = []; | ||
|
||
|
||
/** | ||
* EntityList constructor. | ||
* | ||
* @param string[] $entityTypes | ||
*/ | ||
public function __construct( | ||
$entityTypes = [] | ||
) { | ||
$this->entityTypes = $entityTypes; | ||
} | ||
|
||
/** | ||
* Retrieve list of entities | ||
* | ||
* @return ValidatorInterface[] | ||
*/ | ||
public function getList(): array | ||
{ | ||
return $this->entityTypes; | ||
} | ||
|
||
/** | ||
* @param string $code | ||
* | ||
* @return ValidatorInterface | ||
*/ | ||
public function getEntityByCode(string $code): ValidatorInterface | ||
{ | ||
return $this->entityTypes[$code]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** | ||
* Copyright (c) 2019. Volodymyr Hryvinskyi. All rights reserved. | ||
* @author: <mailto:[email protected]> | ||
* @github: <https://github.com/hryvinskyi> | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Hryvinskyi\DeferJs\Model\PassesValidator; | ||
|
||
use Hryvinskyi\Base\Helper\VarDumper; | ||
use Magento\Framework\App\Response\Http; | ||
|
||
/** | ||
* Class Validate | ||
*/ | ||
class ValidateSkipper | ||
{ | ||
/** | ||
* @var EntityList | ||
*/ | ||
private $deferJsPassesValidators; | ||
|
||
/** | ||
* Validate constructor. | ||
* | ||
* @param EntityList $deferJsPassesValidators | ||
*/ | ||
public function __construct( | ||
EntityList $deferJsPassesValidators | ||
) { | ||
$this->deferJsPassesValidators = $deferJsPassesValidators; | ||
} | ||
|
||
/** | ||
* @param string $script | ||
* @param Http $http | ||
* | ||
* @return bool | ||
*/ | ||
public function execute(string $script, Http $http): bool | ||
{ | ||
foreach ($this->deferJsPassesValidators->getList() as $deferJsPassesValidator) { | ||
if($deferJsPassesValidator->validate($script, $http)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
/** | ||
* Copyright (c) 2019. Volodymyr Hryvinskyi. All rights reserved. | ||
* @author: <mailto:[email protected]> | ||
* @github: <https://github.com/hryvinskyi> | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Hryvinskyi\DeferJs\Model\PassesValidator; | ||
|
||
use Magento\Framework\App\Response\Http; | ||
|
||
interface ValidatorInterface | ||
{ | ||
/** | ||
* Validator function, handle javascript or not | ||
* | ||
* @param string $script | ||
* @param Http $http | ||
* | ||
* @return bool | ||
*/ | ||
public function validate(string $script, Http $http): bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
/** | ||
* Copyright (c) 2019. Volodymyr Hryvinskyi. All rights reserved. | ||
* @author: <mailto:[email protected]> | ||
* @github: <https://github.com/hryvinskyi> | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
|
||
namespace Hryvinskyi\DeferJs\Model\PassesValidator\Validators; | ||
|
||
use Hryvinskyi\DeferJs\Model\PassesValidator\ValidatorInterface; | ||
use Magento\Framework\App\Response\Http; | ||
|
||
/** | ||
* Class SkipGoogleTagManager | ||
*/ | ||
class SkipGoogleTagManager implements ValidatorInterface | ||
{ | ||
/** | ||
* Validator function, handle javascript or not | ||
* | ||
* @param string $script | ||
* @param Http $http | ||
* | ||
* @return bool | ||
*/ | ||
public function validate(string $script, Http $http): bool | ||
{ | ||
return !!preg_match("/.*?googletagmanager\.com.*?/s", $script); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
Model/PassesValidator/Validators/SkipScriptByAttribute.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
/** | ||
* Copyright (c) 2019. Volodymyr Hryvinskyi. All rights reserved. | ||
* @author: <mailto:[email protected]> | ||
* @github: <https://github.com/hryvinskyi> | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Hryvinskyi\DeferJs\Model\PassesValidator\Validators; | ||
|
||
use Hryvinskyi\DeferJs\Helper\Config; | ||
use Hryvinskyi\DeferJs\Model\PassesValidator\ValidatorInterface; | ||
use Magento\Framework\App\Response\Http; | ||
|
||
/** | ||
* Class SkipScriptByAttribute | ||
*/ | ||
class SkipScriptByAttribute implements ValidatorInterface | ||
{ | ||
/** | ||
* @var Config | ||
*/ | ||
private $config; | ||
|
||
/** | ||
* SkipScriptByAttribute constructor. | ||
* | ||
* @param Config $config | ||
*/ | ||
public function __construct(Config $config) { | ||
$this->config = $config; | ||
} | ||
|
||
/** | ||
* Validator function, handle javascript or not | ||
* | ||
* @param string $script | ||
* @param Http $http | ||
* | ||
* @return bool | ||
*/ | ||
public function validate(string $script, Http $http): bool | ||
{ | ||
$return = false; | ||
|
||
if (stripos($script, $this->config->getDisableAttribute()) !== false) { | ||
$return = true; | ||
} | ||
|
||
return $return; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.