Skip to content

Commit

Permalink
Merge branch 'release/1.0.8' into v1
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Apr 19, 2019
2 parents 76f4e4a + 56bcb25 commit 83a102d
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 21 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,12 @@

All notable changes to this project will be documented in this file.

## 1.0.8 - 2018.04.19
### Changed
* Fixed an issue where an empty **Exclude Patterns** table and the use of Project Config on Craft 3.1 or later could cause an exception to be thrown when a 404 is thrown
* Fixed an issue where Webperf would fire during Live Preview when it shouldn't
* Updated Twig namespacing to be compliant with deprecated class aliases in 2.7.x

## 1.0.7 - 2019-03-15
### Changed
* Fixed a potential `Undefined property` in the MetricsController
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Expand Up @@ -2,7 +2,7 @@
"name": "nystudio107/craft-webperf",
"description": "Webperf helps you build & maintain high quality websites through Real User Measurement of your website's performance",
"type": "craft-plugin",
"version": "1.0.7",
"version": "1.0.8",
"keywords": [
"craft",
"cms",
Expand Down
14 changes: 8 additions & 6 deletions src/Webperf.php
Expand Up @@ -237,7 +237,7 @@ public function clearAllCaches()
protected function addComponents()
{
$request = Craft::$app->getRequest();
if ($request->getIsSiteRequest() && !$request->getIsConsoleRequest()) {
if ($request->getIsSiteRequest() && !$request->getIsConsoleRequest() && !$request->getIsLivePreview()) {
$this->setRequestUrl();
try {
$uri = $request->getPathInfo();
Expand Down Expand Up @@ -365,7 +365,7 @@ function () {
// Install these only after all other plugins have loaded
$request = Craft::$app->getRequest();
// Only respond to non-console site requests
if ($request->getIsSiteRequest() && !$request->getIsConsoleRequest()) {
if ($request->getIsSiteRequest() && !$request->getIsConsoleRequest() && !$request->getIsLivePreview()) {
$this->handleSiteRequest();
}
// Respond to Control Panel requests
Expand Down Expand Up @@ -598,10 +598,12 @@ protected function renderSidebar(Element $element): string
protected function excludeUri($uri): bool
{
$uri = '/'.ltrim($uri, '/');
foreach (self::$settings->excludePatterns as $excludePattern) {
$pattern = '`'.$excludePattern['pattern'].'`i';
if (preg_match($pattern, $uri) === 1) {
return true;
if (!empty(self::$settings->excludePatterns)) {
foreach (self::$settings->excludePatterns as $excludePattern) {
$pattern = '`'.$excludePattern['pattern'].'`i';
if (preg_match($pattern, $uri) === 1) {
return true;
}
}
}

Expand Down
32 changes: 32 additions & 0 deletions src/models/Settings.php
Expand Up @@ -10,10 +10,16 @@

namespace nystudio107\webperf\models;

use nystudio107\webperf\Webperf;

use Craft;
use craft\base\Model;
use craft\behaviors\EnvAttributeParserBehavior;
use craft\validators\ArrayValidator;
use craft\validators\ColorValidator;

use yii\behaviors\AttributeTypecastBehavior;

use putyourlightson\blitz\Blitz;

/**
Expand Down Expand Up @@ -221,6 +227,7 @@ public function rules()
['rateLimitMs', 'integer'],
['rateLimitMs', 'default', 'value' => 500],
['webpageTestApiKey', 'string'],
['excludePatterns', ArrayValidator::class],
['includeCraftWarnings', 'boolean'],
['errorSamplesStoredLimit', 'integer'],
['errorSamplesStoredLimit', 'default', 'value' => 1000],
Expand Down Expand Up @@ -258,4 +265,29 @@ public function rules()
]
];
}

/**
* @return array
*/
public function behaviors()
{
$craft31Behaviors = [];
if (Webperf::$craft31) {
$craft31Behaviors = [
'parser' => [
'class' => EnvAttributeParserBehavior::class,
'attributes' => [
'webpageTestApiKey',
],
]
];
}

return array_merge($craft31Behaviors, [
'typecast' => [
'class' => AttributeTypecastBehavior::class,
// 'attributeTypes' will be composed automatically according to `rules()`
],
]);
}
}
28 changes: 14 additions & 14 deletions src/variables/ManifestVariable.php
Expand Up @@ -60,10 +60,10 @@ public function __construct()
* @param bool $async
* @param null|array $config
*
* @return \Twig_Markup
* @return \Twig\Markup
* @throws \yii\web\NotFoundHttpException
*/
public function includeCssModule(string $moduleName, bool $async = false, $config = null): \Twig_Markup
public function includeCssModule(string $moduleName, bool $async = false, $config = null): \Twig\Markup
{
return Template::raw(
ManifestHelper::getCssModuleTags(self::$config, $moduleName, $async)
Expand All @@ -75,9 +75,9 @@ public function includeCssModule(string $moduleName, bool $async = false, $confi
*
* @param string $path
*
* @return \Twig_Markup
* @return \Twig\Markup
*/
public function includeInlineCssTags(string $path): \Twig_Markup
public function includeInlineCssTags(string $path): \Twig\Markup
{
return Template::raw(
ManifestHelper::getCssInlineTags($path)
Expand All @@ -88,9 +88,9 @@ public function includeInlineCssTags(string $path): \Twig_Markup
* Returns the uglified loadCSS rel=preload Polyfill as per:
* https://github.com/filamentgroup/loadCSS#how-to-use-loadcss-recommended-example
*
* @return \Twig_Markup
* @return \Twig\Markup
*/
public static function includeCssRelPreloadPolyfill(): \Twig_Markup
public static function includeCssRelPreloadPolyfill(): \Twig\Markup
{
return Template::raw(
ManifestHelper::getCssRelPreloadPolyfill()
Expand All @@ -102,7 +102,7 @@ public static function includeCssRelPreloadPolyfill(): \Twig_Markup
* @param bool $async
* @param null|array $config
*
* @return null|\Twig_Markup
* @return null|\Twig\Markup
* @throws \yii\web\NotFoundHttpException
*/
public function includeJsModule(string $moduleName, bool $async = false, $config = null)
Expand All @@ -119,7 +119,7 @@ public function includeJsModule(string $moduleName, bool $async = false, $config
* @param string $type
* @param null $config
*
* @return null|\Twig_Markup
* @return null|\Twig\Markup
* @throws \yii\web\NotFoundHttpException
*/
public function getModuleUri(string $moduleName, string $type = 'modern', $config = null)
Expand All @@ -132,9 +132,9 @@ public function getModuleUri(string $moduleName, string $type = 'modern', $confi
/**
* Include the Safari 10.1 nomodule fix JavaScript
*
* @return \Twig_Markup
* @return \Twig\Markup
*/
public function includeSafariNomoduleFix(): \Twig_Markup
public function includeSafariNomoduleFix(): \Twig\Markup
{
return Template::raw(
ManifestHelper::getSafariNomoduleFix()
Expand All @@ -146,9 +146,9 @@ public function includeSafariNomoduleFix(): \Twig_Markup
*
* @param string $path
*
* @return \Twig_Markup
* @return \Twig\Markup
*/
public function includeFile(string $path): \Twig_Markup
public function includeFile(string $path): \Twig\Markup
{
return Template::raw(
ManifestHelper::getFile($path)
Expand All @@ -162,9 +162,9 @@ public function includeFile(string $path): \Twig_Markup
* @param string $type
* @param null $config
*
* @return \Twig_Markup
* @return \Twig\Markup
*/
public function includeFileFromManifest(string $fileName, string $type = 'legacy', $config = null): \Twig_Markup
public function includeFileFromManifest(string $fileName, string $type = 'legacy', $config = null): \Twig\Markup
{
return Template::raw(
ManifestHelper::getFileFromManifest($config, $fileName, $type)
Expand Down

0 comments on commit 83a102d

Please sign in to comment.