diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b930a6e..e5039219 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/composer.json b/composer.json index 0b60ff70..0cad6cee 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/Webperf.php b/src/Webperf.php index 1cd2f905..354ac0bb 100644 --- a/src/Webperf.php +++ b/src/Webperf.php @@ -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(); @@ -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 @@ -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; + } } } diff --git a/src/models/Settings.php b/src/models/Settings.php index 8bf5a205..cb3a9fae 100644 --- a/src/models/Settings.php +++ b/src/models/Settings.php @@ -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; /** @@ -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], @@ -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()` + ], + ]); + } } diff --git a/src/variables/ManifestVariable.php b/src/variables/ManifestVariable.php index 20a5dca2..fb444fbb 100644 --- a/src/variables/ManifestVariable.php +++ b/src/variables/ManifestVariable.php @@ -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) @@ -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) @@ -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() @@ -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) @@ -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) @@ -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() @@ -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) @@ -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)