@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | // Protected Properties |
42 | 42 | // ========================================================================= |
43 | 43 | |
44 | - protected $allowAnonymous = []; |
|
44 | + protected $allowAnonymous = [ ]; |
|
45 | 45 | |
46 | 46 | // Public Methods |
47 | 47 | // ========================================================================= |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function actionRedirects(string $siteHandle = null): Response |
59 | 59 | { |
60 | - $variables = []; |
|
60 | + $variables = [ ]; |
|
61 | 61 | PermissionHelper::controllerPermissionCheck('retour:redirects'); |
62 | 62 | // Get the site to edit |
63 | 63 | $siteId = MultiSiteHelper::getSiteIdFromHandle($siteHandle); |
@@ -70,32 +70,32 @@ discard block |
||
70 | 70 | } catch (InvalidConfigException $e) { |
71 | 71 | Craft::error($e->getMessage(), __METHOD__); |
72 | 72 | } |
73 | - $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl( |
|
73 | + $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl( |
|
74 | 74 | '@nystudio107/retour/assetbundles/retour/dist', |
75 | 75 | true |
76 | 76 | ); |
77 | 77 | // Enabled sites |
78 | 78 | MultiSiteHelper::setMultiSiteVariables($siteHandle, $siteId, $variables); |
79 | - $variables['controllerHandle'] = 'redirects'; |
|
79 | + $variables[ 'controllerHandle' ] = 'redirects'; |
|
80 | 80 | |
81 | 81 | // Basic variables |
82 | - $variables['fullPageForm'] = false; |
|
83 | - $variables['docsUrl'] = self::DOCUMENTATION_URL; |
|
84 | - $variables['pluginName'] = $pluginName; |
|
85 | - $variables['title'] = $templateTitle; |
|
86 | - $siteHandleUri = Craft::$app->isMultiSite ? '/'.$siteHandle : ''; |
|
87 | - $variables['crumbs'] = [ |
|
82 | + $variables[ 'fullPageForm' ] = false; |
|
83 | + $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL; |
|
84 | + $variables[ 'pluginName' ] = $pluginName; |
|
85 | + $variables[ 'title' ] = $templateTitle; |
|
86 | + $siteHandleUri = Craft::$app->isMultiSite ? '/' . $siteHandle : ''; |
|
87 | + $variables[ 'crumbs' ] = [ |
|
88 | 88 | [ |
89 | 89 | 'label' => $pluginName, |
90 | 90 | 'url' => UrlHelper::cpUrl('retour'), |
91 | 91 | ], |
92 | 92 | [ |
93 | 93 | 'label' => $templateTitle, |
94 | - 'url' => UrlHelper::cpUrl('retour/redirects'.$siteHandleUri), |
|
94 | + 'url' => UrlHelper::cpUrl('retour/redirects' . $siteHandleUri), |
|
95 | 95 | ], |
96 | 96 | ]; |
97 | - $variables['docTitle'] = "{$pluginName} - {$templateTitle}"; |
|
98 | - $variables['selectedSubnavItem'] = 'redirects'; |
|
97 | + $variables[ 'docTitle' ] = "{$pluginName} - {$templateTitle}"; |
|
98 | + $variables[ 'selectedSubnavItem' ] = 'redirects'; |
|
99 | 99 | |
100 | 100 | // Render the template |
101 | 101 | return $this->renderTemplate('retour/redirects/index', $variables); |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | int $siteId = 0, |
120 | 120 | StaticRedirectsModel $redirect = null |
121 | 121 | ): Response { |
122 | - $variables = []; |
|
122 | + $variables = [ ]; |
|
123 | 123 | PermissionHelper::controllerPermissionCheck('retour:redirects'); |
124 | 124 | |
125 | 125 | // Load in the redirect |
@@ -133,12 +133,12 @@ discard block |
||
133 | 133 | if ($redirect === null) { |
134 | 134 | $redirectConfig = Retour::$plugin->redirects->getRedirectById($redirectId); |
135 | 135 | if ($redirectConfig === null) { |
136 | - $redirectConfig = []; |
|
136 | + $redirectConfig = [ ]; |
|
137 | 137 | Craft::error( |
138 | 138 | Craft::t( |
139 | 139 | 'retour', |
140 | 140 | "Couldn't load redirect id {id}", |
141 | - ['id' => $redirectId] |
|
141 | + [ 'id' => $redirectId ] |
|
142 | 142 | ), |
143 | 143 | __METHOD__ |
144 | 144 | ); |
@@ -151,13 +151,13 @@ discard block |
||
151 | 151 | if ($redirect->siteId) { |
152 | 152 | $site = $sites->getSiteById($redirect->siteId); |
153 | 153 | if ($site) { |
154 | - MultiSiteHelper::requirePermission('editSite:'.$site->uid); |
|
154 | + MultiSiteHelper::requirePermission('editSite:' . $site->uid); |
|
155 | 155 | } |
156 | 156 | } |
157 | 157 | if ($siteId) { |
158 | 158 | $site = $sites->getSiteById($siteId); |
159 | 159 | if ($site) { |
160 | - MultiSiteHelper::requirePermission('editSite:'.$site->uid); |
|
160 | + MultiSiteHelper::requirePermission('editSite:' . $site->uid); |
|
161 | 161 | } |
162 | 162 | } |
163 | 163 | $pluginName = Retour::$settings->pluginName; |
@@ -169,20 +169,20 @@ discard block |
||
169 | 169 | } catch (InvalidConfigException $e) { |
170 | 170 | Craft::error($e->getMessage(), __METHOD__); |
171 | 171 | } |
172 | - $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl( |
|
172 | + $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl( |
|
173 | 173 | '@nystudio107/retour/assetbundles/retour/dist', |
174 | 174 | true |
175 | 175 | ); |
176 | 176 | // Sites menu |
177 | 177 | MultiSiteHelper::setSitesMenuVariables($variables); |
178 | - $variables['controllerHandle'] = 'redirects'; |
|
178 | + $variables[ 'controllerHandle' ] = 'redirects'; |
|
179 | 179 | |
180 | 180 | // Basic variables |
181 | - $variables['fullPageForm'] = true; |
|
182 | - $variables['docsUrl'] = self::DOCUMENTATION_URL; |
|
183 | - $variables['pluginName'] = $pluginName; |
|
184 | - $variables['title'] = $templateTitle; |
|
185 | - $variables['crumbs'] = [ |
|
181 | + $variables[ 'fullPageForm' ] = true; |
|
182 | + $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL; |
|
183 | + $variables[ 'pluginName' ] = $pluginName; |
|
184 | + $variables[ 'title' ] = $templateTitle; |
|
185 | + $variables[ 'crumbs' ] = [ |
|
186 | 186 | [ |
187 | 187 | 'label' => $pluginName, |
188 | 188 | 'url' => UrlHelper::cpUrl('retour'), |
@@ -193,12 +193,12 @@ discard block |
||
193 | 193 | ], |
194 | 194 | [ |
195 | 195 | 'label' => $templateTitle, |
196 | - 'url' => UrlHelper::cpUrl('retour/edit-redirect/'.$redirectId), |
|
196 | + 'url' => UrlHelper::cpUrl('retour/edit-redirect/' . $redirectId), |
|
197 | 197 | ], |
198 | 198 | ]; |
199 | - $variables['docTitle'] = "{$pluginName} - Redirects - {$templateTitle}"; |
|
200 | - $variables['selectedSubnavItem'] = 'redirects'; |
|
201 | - $variables['redirect'] = $redirect; |
|
199 | + $variables[ 'docTitle' ] = "{$pluginName} - Redirects - {$templateTitle}"; |
|
200 | + $variables[ 'selectedSubnavItem' ] = 'redirects'; |
|
201 | + $variables[ 'redirect' ] = $redirect; |
|
202 | 202 | |
203 | 203 | // Render the template |
204 | 204 | return $this->renderTemplate('retour/redirects/_edit', $variables); |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | if ($redirectConfig === null) { |
245 | 245 | throw new NotFoundHttpException('Redirect not found'); |
246 | 246 | } |
247 | - $redirectConfig['id'] = (int)$redirectConfig['id']; |
|
247 | + $redirectConfig[ 'id' ] = (int) $redirectConfig[ 'id' ]; |
|
248 | 248 | $redirect = new StaticRedirectsModel($redirectConfig); |
249 | 249 | // Make sure the redirect validates |
250 | 250 | if (!$redirect->validate()) { |
@@ -261,8 +261,8 @@ discard block |
||
261 | 261 | Retour::$plugin->redirects->saveRedirect($redirectConfig); |
262 | 262 | // Handle the case where the redirect wasn't saved because it'd create a redirect loop |
263 | 263 | $testRedirectConfig = Retour::$plugin->redirects->getRedirectByRedirectSrcUrl( |
264 | - $redirectConfig['redirectSrcUrl'], |
|
265 | - $redirectConfig['siteId'] |
|
264 | + $redirectConfig[ 'redirectSrcUrl' ], |
|
265 | + $redirectConfig[ 'siteId' ] |
|
266 | 266 | ); |
267 | 267 | if ($testRedirectConfig === null) { |
268 | 268 | Craft::$app->getSession()->setError(Craft::t('app', "Couldn't save redirect settings because it'd create a redirect loop.")); |
@@ -104,8 +104,8 @@ discard block |
||
104 | 104 | public function rules() |
105 | 105 | { |
106 | 106 | return [ |
107 | - ['pluginName', 'string'], |
|
108 | - ['pluginName', 'default', 'value' => 'Retour'], |
|
107 | + [ 'pluginName', 'string' ], |
|
108 | + [ 'pluginName', 'default', 'value' => 'Retour' ], |
|
109 | 109 | [ |
110 | 110 | [ |
111 | 111 | 'createUriChangeRedirects', |
@@ -116,17 +116,17 @@ discard block |
||
116 | 116 | ], |
117 | 117 | 'boolean' |
118 | 118 | ], |
119 | - ['staticRedirectDisplayLimit', 'integer', 'min' => 1], |
|
120 | - ['staticRedirectDisplayLimit', 'default', 'value' => 100], |
|
121 | - ['dynamicRedirectDisplayLimit', 'integer', 'min' => 1], |
|
122 | - ['dynamicRedirectDisplayLimit', 'default', 'value' => 100], |
|
123 | - ['statsStoredLimit', 'integer', 'min' => 1], |
|
124 | - ['statsStoredLimit', 'default', 'value' => 1000], |
|
125 | - ['refreshIntervalSecs', 'integer', 'min' => 0], |
|
126 | - ['refreshIntervalSecs', 'default', 'value' => 3], |
|
127 | - ['statsDisplayLimit', 'integer', 'min' => 1], |
|
128 | - ['statsDisplayLimit', 'default', 'value' => 1000], |
|
129 | - ['excludePatterns', ArrayValidator::class], |
|
119 | + [ 'staticRedirectDisplayLimit', 'integer', 'min' => 1 ], |
|
120 | + [ 'staticRedirectDisplayLimit', 'default', 'value' => 100 ], |
|
121 | + [ 'dynamicRedirectDisplayLimit', 'integer', 'min' => 1 ], |
|
122 | + [ 'dynamicRedirectDisplayLimit', 'default', 'value' => 100 ], |
|
123 | + [ 'statsStoredLimit', 'integer', 'min' => 1 ], |
|
124 | + [ 'statsStoredLimit', 'default', 'value' => 1000 ], |
|
125 | + [ 'refreshIntervalSecs', 'integer', 'min' => 0 ], |
|
126 | + [ 'refreshIntervalSecs', 'default', 'value' => 3 ], |
|
127 | + [ 'statsDisplayLimit', 'integer', 'min' => 1 ], |
|
128 | + [ 'statsDisplayLimit', 'default', 'value' => 1000 ], |
|
129 | + [ 'excludePatterns', ArrayValidator::class ], |
|
130 | 130 | ]; |
131 | 131 | } |
132 | 132 | |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | */ |
136 | 136 | public function behaviors() |
137 | 137 | { |
138 | - $craft31Behaviors = []; |
|
138 | + $craft31Behaviors = [ ]; |
|
139 | 139 | if (Retour::$craft31) { |
140 | 140 | $craft31Behaviors = [ |
141 | 141 | 'parser' => [ |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | // Protected Properties |
41 | 41 | // ========================================================================= |
42 | 42 | |
43 | - protected $allowAnonymous = []; |
|
43 | + protected $allowAnonymous = [ ]; |
|
44 | 44 | |
45 | 45 | // Public Methods |
46 | 46 | // ========================================================================= |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | */ |
57 | 57 | public function actionDashboard(string $siteHandle = null, bool $showWelcome = false): Response |
58 | 58 | { |
59 | - $variables = []; |
|
59 | + $variables = [ ]; |
|
60 | 60 | PermissionHelper::controllerPermissionCheck('retour:dashboard'); |
61 | 61 | // Trim the statistics |
62 | 62 | Retour::$plugin->statistics->trimStatistics(); |
@@ -71,34 +71,34 @@ discard block |
||
71 | 71 | } catch (InvalidConfigException $e) { |
72 | 72 | Craft::error($e->getMessage(), __METHOD__); |
73 | 73 | } |
74 | - $variables['baseAssetsUrl'] = Craft::$app->assetManager->getPublishedUrl( |
|
74 | + $variables[ 'baseAssetsUrl' ] = Craft::$app->assetManager->getPublishedUrl( |
|
75 | 75 | '@nystudio107/retour/assetbundles/retour/dist', |
76 | 76 | true |
77 | 77 | ); |
78 | 78 | // Enabled sites |
79 | 79 | MultiSiteHelper::setMultiSiteVariables($siteHandle, $siteId, $variables); |
80 | - $variables['controllerHandle'] = 'dashboard'; |
|
80 | + $variables[ 'controllerHandle' ] = 'dashboard'; |
|
81 | 81 | |
82 | 82 | // Basic variables |
83 | - $variables['fullPageForm'] = false; |
|
84 | - $variables['docsUrl'] = self::DOCUMENTATION_URL; |
|
85 | - $variables['pluginName'] = $pluginName; |
|
86 | - $variables['title'] = $templateTitle; |
|
87 | - $siteHandleUri = Craft::$app->isMultiSite ? '/'.$siteHandle : ''; |
|
88 | - $variables['crumbs'] = [ |
|
83 | + $variables[ 'fullPageForm' ] = false; |
|
84 | + $variables[ 'docsUrl' ] = self::DOCUMENTATION_URL; |
|
85 | + $variables[ 'pluginName' ] = $pluginName; |
|
86 | + $variables[ 'title' ] = $templateTitle; |
|
87 | + $siteHandleUri = Craft::$app->isMultiSite ? '/' . $siteHandle : ''; |
|
88 | + $variables[ 'crumbs' ] = [ |
|
89 | 89 | [ |
90 | 90 | 'label' => $pluginName, |
91 | 91 | 'url' => UrlHelper::cpUrl('retour'), |
92 | 92 | ], |
93 | 93 | [ |
94 | 94 | 'label' => $templateTitle, |
95 | - 'url' => UrlHelper::cpUrl('retour/dashboard'.$siteHandleUri), |
|
95 | + 'url' => UrlHelper::cpUrl('retour/dashboard' . $siteHandleUri), |
|
96 | 96 | ], |
97 | 97 | ]; |
98 | - $variables['docTitle'] = "{$pluginName} - {$templateTitle}"; |
|
99 | - $variables['selectedSubnavItem'] = 'dashboard'; |
|
100 | - $variables['showWelcome'] = $showWelcome; |
|
101 | - $variables['settings'] = Retour::$settings; |
|
98 | + $variables[ 'docTitle' ] = "{$pluginName} - {$templateTitle}"; |
|
99 | + $variables[ 'selectedSubnavItem' ] = 'dashboard'; |
|
100 | + $variables[ 'showWelcome' ] = $showWelcome; |
|
101 | + $variables[ 'settings' ] = Retour::$settings; |
|
102 | 102 | |
103 | 103 | // Render the template |
104 | 104 | return $this->renderTemplate('retour/dashboard/index', $variables); |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | Craft::t( |
117 | 117 | 'retour', |
118 | 118 | 'Retour statistics cleared: {error}', |
119 | - ['error' => $error] |
|
119 | + [ 'error' => $error ] |
|
120 | 120 | ), |
121 | 121 | __METHOD__ |
122 | 122 | ); |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | Craft::t( |
129 | 129 | 'retour', |
130 | 130 | '404 full URL: {fullUrl}, 404 path only: {pathOnly}', |
131 | - ['fullUrl' => $fullUrl, 'pathOnly' => $pathOnly] |
|
131 | + [ 'fullUrl' => $fullUrl, 'pathOnly' => $pathOnly ] |
|
132 | 132 | ), |
133 | 133 | __METHOD__ |
134 | 134 | ); |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | $response = Craft::$app->getResponse(); |
163 | 163 | if ($redirect !== null) { |
164 | 164 | // Figure out what type of source matching was done |
165 | - $redirectSrcMatch = $redirect['redirectSrcMatch'] ?? 'pathonly'; |
|
165 | + $redirectSrcMatch = $redirect[ 'redirectSrcMatch' ] ?? 'pathonly'; |
|
166 | 166 | switch ($redirectSrcMatch) { |
167 | 167 | case 'pathonly': |
168 | 168 | $url = $pathOnly; |
@@ -174,11 +174,11 @@ discard block |
||
174 | 174 | $url = $pathOnly; |
175 | 175 | break; |
176 | 176 | } |
177 | - $dest = $redirect['redirectDestUrl']; |
|
177 | + $dest = $redirect[ 'redirectDestUrl' ]; |
|
178 | 178 | // If this isn't a full URL, make it one based on the appropriate site |
179 | 179 | if (!UrlHelper::isFullUrl($dest)) { |
180 | 180 | try { |
181 | - $dest = UrlHelper::siteUrl($dest, null, null, $redirect['siteId'] ?? null); |
|
181 | + $dest = UrlHelper::siteUrl($dest, null, null, $redirect[ 'siteId' ] ?? null); |
|
182 | 182 | } catch (\yii\base\Exception $e) { |
183 | 183 | } |
184 | 184 | } |
@@ -188,12 +188,12 @@ discard block |
||
188 | 188 | $dest .= '?' . $request->getQueryStringWithoutPath(); |
189 | 189 | } |
190 | 190 | } |
191 | - $status = $redirect['redirectHttpCode']; |
|
191 | + $status = $redirect[ 'redirectHttpCode' ]; |
|
192 | 192 | Craft::info( |
193 | 193 | Craft::t( |
194 | 194 | 'retour', |
195 | 195 | 'Redirecting {url} to {dest} with status {status}', |
196 | - ['url' => $url, 'dest' => $dest, 'status' => $status] |
|
196 | + [ 'url' => $url, 'dest' => $dest, 'status' => $status ] |
|
197 | 197 | ), |
198 | 198 | __METHOD__ |
199 | 199 | ); |
@@ -273,13 +273,13 @@ discard block |
||
273 | 273 | public function getRedirectFromCache($url, int $siteId = 0) |
274 | 274 | { |
275 | 275 | $cache = Craft::$app->getCache(); |
276 | - $cacheKey = $this::CACHE_KEY.md5($url).$siteId; |
|
276 | + $cacheKey = $this::CACHE_KEY . md5($url) . $siteId; |
|
277 | 277 | $redirect = $cache->get($cacheKey); |
278 | 278 | Craft::info( |
279 | 279 | Craft::t( |
280 | 280 | 'retour', |
281 | 281 | 'Cached redirect hit for {url}', |
282 | - ['url' => $url] |
|
282 | + [ 'url' => $url ] |
|
283 | 283 | ), |
284 | 284 | __METHOD__ |
285 | 285 | ); |
@@ -301,12 +301,12 @@ discard block |
||
301 | 301 | } catch (SiteNotFoundException $e) { |
302 | 302 | $siteId = 1; |
303 | 303 | } |
304 | - $cacheKey = $this::CACHE_KEY.md5($url).$siteId; |
|
304 | + $cacheKey = $this::CACHE_KEY . md5($url) . $siteId; |
|
305 | 305 | // Create the dependency tags |
306 | 306 | $dependency = new TagDependency([ |
307 | 307 | 'tags' => [ |
308 | 308 | $this::GLOBAL_REDIRECTS_CACHE_TAG, |
309 | - $this::GLOBAL_REDIRECTS_CACHE_TAG.$siteId, |
|
309 | + $this::GLOBAL_REDIRECTS_CACHE_TAG . $siteId, |
|
310 | 310 | ], |
311 | 311 | ]); |
312 | 312 | $cache->set($cacheKey, $redirect, Retour::$cacheDuration, $dependency); |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | Craft::t( |
315 | 315 | 'retour', |
316 | 316 | 'Cached redirect saved for {url}', |
317 | - ['url' => $url] |
|
317 | + [ 'url' => $url ] |
|
318 | 318 | ), |
319 | 319 | __METHOD__ |
320 | 320 | ); |
@@ -332,8 +332,8 @@ discard block |
||
332 | 332 | $result = null; |
333 | 333 | foreach ($redirects as $redirect) { |
334 | 334 | // Figure out what type of source matching to do |
335 | - $redirectSrcMatch = $redirect['redirectSrcMatch'] ?? 'pathonly'; |
|
336 | - $redirectEnabled = (bool)$redirect['enabled']; |
|
335 | + $redirectSrcMatch = $redirect[ 'redirectSrcMatch' ] ?? 'pathonly'; |
|
336 | + $redirectEnabled = (bool) $redirect[ 'enabled' ]; |
|
337 | 337 | if ($redirectEnabled === true) { |
338 | 338 | switch ($redirectSrcMatch) { |
339 | 339 | case 'pathonly': |
@@ -346,11 +346,11 @@ discard block |
||
346 | 346 | $url = $pathOnly; |
347 | 347 | break; |
348 | 348 | } |
349 | - $redirectMatchType = $redirect['redirectMatchType'] ?? 'notfound'; |
|
349 | + $redirectMatchType = $redirect[ 'redirectMatchType' ] ?? 'notfound'; |
|
350 | 350 | switch ($redirectMatchType) { |
351 | 351 | // Do a straight up match |
352 | 352 | case 'exactmatch': |
353 | - if (strcasecmp($redirect['redirectSrcUrlParsed'], $url) === 0) { |
|
353 | + if (strcasecmp($redirect[ 'redirectSrcUrlParsed' ], $url) === 0) { |
|
354 | 354 | $this->incrementRedirectHitCount($redirect); |
355 | 355 | $this->saveRedirectToCache($url, $redirect); |
356 | 356 | |
@@ -360,14 +360,14 @@ discard block |
||
360 | 360 | |
361 | 361 | // Do a regex match |
362 | 362 | case 'regexmatch': |
363 | - $matchRegEx = '`'.$redirect['redirectSrcUrlParsed'].'`i'; |
|
363 | + $matchRegEx = '`' . $redirect[ 'redirectSrcUrlParsed' ] . '`i'; |
|
364 | 364 | if (preg_match($matchRegEx, $url) === 1) { |
365 | 365 | $this->incrementRedirectHitCount($redirect); |
366 | 366 | // If we're not associated with an EntryID, handle capture group replacement |
367 | - if ((int)$redirect['associatedElementId'] === 0) { |
|
368 | - $redirect['redirectDestUrl'] = preg_replace( |
|
367 | + if ((int) $redirect[ 'associatedElementId' ] === 0) { |
|
368 | + $redirect[ 'redirectDestUrl' ] = preg_replace( |
|
369 | 369 | $matchRegEx, |
370 | - $redirect['redirectDestUrl'], |
|
370 | + $redirect[ 'redirectDestUrl' ], |
|
371 | 371 | $url |
372 | 372 | ); |
373 | 373 | } |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | 'redirect' => &$redirect, |
387 | 387 | ], |
388 | 388 | ]; |
389 | - $result = \call_user_func_array([$plugin, 'retourMatch'], $args); |
|
389 | + $result = \call_user_func_array([ $plugin, 'retourMatch' ], $args); |
|
390 | 390 | if ($result) { |
391 | 391 | $this->incrementRedirectHitCount($redirect); |
392 | 392 | $this->saveRedirectToCache($url, $redirect); |
@@ -402,7 +402,7 @@ discard block |
||
402 | 402 | Craft::t( |
403 | 403 | 'retour', |
404 | 404 | 'Not handled-> full URL: {fullUrl}, path only: {pathOnly}', |
405 | - ['fullUrl' => $fullUrl, 'pathOnly' => $pathOnly] |
|
405 | + [ 'fullUrl' => $fullUrl, 'pathOnly' => $pathOnly ] |
|
406 | 406 | ), |
407 | 407 | __METHOD__ |
408 | 408 | ); |
@@ -426,7 +426,7 @@ discard block |
||
426 | 426 | foreach (Craft::$app->getPlugins()->getAllPlugins() as $plugin) { |
427 | 427 | /** @var Plugin $plugin */ |
428 | 428 | if (method_exists($plugin, 'retourMatch')) { |
429 | - $result[$plugin->getHandle()] = $plugin->name.Craft::t('retour', ' Match'); |
|
429 | + $result[ $plugin->getHandle() ] = $plugin->name . Craft::t('retour', ' Match'); |
|
430 | 430 | } |
431 | 431 | } |
432 | 432 | |
@@ -447,12 +447,12 @@ discard block |
||
447 | 447 | } |
448 | 448 | // Query the db table |
449 | 449 | $query = (new Query()) |
450 | - ->from(['{{%retour_static_redirects}}']) |
|
450 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
451 | 451 | ->orderBy('redirectMatchType ASC, redirectSrcMatch ASC, hitCount DESC'); |
452 | 452 | if ($siteId) { |
453 | 453 | $query |
454 | - ->where(['siteId' => $siteId]) |
|
455 | - ->orWhere(['siteId' => null]); |
|
454 | + ->where([ 'siteId' => $siteId ]) |
|
455 | + ->orWhere([ 'siteId' => null ]); |
|
456 | 456 | } |
457 | 457 | if ($limit) { |
458 | 458 | $query->limit($limit); |
@@ -475,8 +475,8 @@ discard block |
||
475 | 475 | { |
476 | 476 | // Query the db table |
477 | 477 | $redirect = (new Query()) |
478 | - ->from(['{{%retour_static_redirects}}']) |
|
479 | - ->where(['id' => $id]) |
|
478 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
479 | + ->where([ 'id' => $id ]) |
|
480 | 480 | ->one(); |
481 | 481 | |
482 | 482 | return $redirect; |
@@ -494,16 +494,16 @@ discard block |
||
494 | 494 | { |
495 | 495 | // Query the db table |
496 | 496 | $query = (new Query()) |
497 | - ->from(['{{%retour_static_redirects}}']) |
|
498 | - ->where(['redirectSrcUrl' => $redirectSrcUrl]) |
|
497 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
498 | + ->where([ 'redirectSrcUrl' => $redirectSrcUrl ]) |
|
499 | 499 | ; |
500 | 500 | if ($siteId) { |
501 | 501 | $query |
502 | - ->andWhere(['or', [ |
|
502 | + ->andWhere([ 'or', [ |
|
503 | 503 | 'siteId' => $siteId, |
504 | 504 | ], [ |
505 | 505 | 'siteId' => null, |
506 | - ]]); |
|
506 | + ] ]); |
|
507 | 507 | } |
508 | 508 | $redirect = $query->one(); |
509 | 509 | |
@@ -545,13 +545,13 @@ discard block |
||
545 | 545 | { |
546 | 546 | if ($redirectConfig !== null) { |
547 | 547 | $db = Craft::$app->getDb(); |
548 | - $redirectConfig['hitCount']++; |
|
549 | - $redirectConfig['hitLastTime'] = Db::prepareDateForDb(new \DateTime()); |
|
548 | + $redirectConfig[ 'hitCount' ]++; |
|
549 | + $redirectConfig[ 'hitLastTime' ] = Db::prepareDateForDb(new \DateTime()); |
|
550 | 550 | Craft::debug( |
551 | 551 | Craft::t( |
552 | 552 | 'retour', |
553 | 553 | 'Incrementing statistics for: {redirect}', |
554 | - ['redirect' => print_r($redirectConfig, true)] |
|
554 | + [ 'redirect' => print_r($redirectConfig, true) ] |
|
555 | 555 | ), |
556 | 556 | __METHOD__ |
557 | 557 | ); |
@@ -560,14 +560,14 @@ discard block |
||
560 | 560 | $rowsAffected = $db->createCommand()->update( |
561 | 561 | '{{%retour_static_redirects}}', |
562 | 562 | [ |
563 | - 'hitCount' => $redirectConfig['hitCount'], |
|
564 | - 'hitLastTime' => $redirectConfig['hitLastTime'], |
|
563 | + 'hitCount' => $redirectConfig[ 'hitCount' ], |
|
564 | + 'hitLastTime' => $redirectConfig[ 'hitLastTime' ], |
|
565 | 565 | ], |
566 | 566 | [ |
567 | - 'id' => $redirectConfig['id'], |
|
567 | + 'id' => $redirectConfig[ 'id' ], |
|
568 | 568 | ] |
569 | 569 | )->execute(); |
570 | - Craft::debug('Rows affected: '.$rowsAffected, __METHOD__); |
|
570 | + Craft::debug('Rows affected: ' . $rowsAffected, __METHOD__); |
|
571 | 571 | } catch (Exception $e) { |
572 | 572 | Craft::error($e->getMessage(), __METHOD__); |
573 | 573 | } |
@@ -586,7 +586,7 @@ discard block |
||
586 | 586 | Craft::t( |
587 | 587 | 'retour', |
588 | 588 | 'Error validating redirect {id}: {errors}', |
589 | - ['id' => $redirect->id, 'errors' => print_r($redirect->getErrors(), true)] |
|
589 | + [ 'id' => $redirect->id, 'errors' => print_r($redirect->getErrors(), true) ] |
|
590 | 590 | ), |
591 | 591 | __METHOD__ |
592 | 592 | ); |
@@ -596,32 +596,32 @@ discard block |
||
596 | 596 | // Get the validated model attributes and save them to the db |
597 | 597 | $redirectConfig = $redirect->getAttributes(); |
598 | 598 | // 0 for a siteId needs to be converted to null |
599 | - if (empty($redirectConfig['siteId']) || (int)$redirectConfig['siteId'] === 0) { |
|
600 | - $redirectConfig['siteId'] = null; |
|
599 | + if (empty($redirectConfig[ 'siteId' ]) || (int) $redirectConfig[ 'siteId' ] === 0) { |
|
600 | + $redirectConfig[ 'siteId' ] = null; |
|
601 | 601 | } |
602 | 602 | // Throw an event to before saving the redirect |
603 | 603 | $db = Craft::$app->getDb(); |
604 | 604 | // See if a redirect exists with this source URL already |
605 | - if ((int)$redirectConfig['id'] === 0) { |
|
605 | + if ((int) $redirectConfig[ 'id' ] === 0) { |
|
606 | 606 | // Query the db table |
607 | 607 | $redirect = (new Query()) |
608 | - ->from(['{{%retour_static_redirects}}']) |
|
609 | - ->where(['redirectSrcUrlParsed' => $redirectConfig['redirectSrcUrlParsed']]) |
|
610 | - ->andWhere(['siteId' => $redirectConfig['siteId']]) |
|
608 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
609 | + ->where([ 'redirectSrcUrlParsed' => $redirectConfig[ 'redirectSrcUrlParsed' ] ]) |
|
610 | + ->andWhere([ 'siteId' => $redirectConfig[ 'siteId' ] ]) |
|
611 | 611 | ->one(); |
612 | 612 | // If it exists, update it rather than having duplicates |
613 | 613 | if (!empty($redirect)) { |
614 | - $redirectConfig['id'] = $redirect['id']; |
|
614 | + $redirectConfig[ 'id' ] = $redirect[ 'id' ]; |
|
615 | 615 | } |
616 | 616 | } |
617 | 617 | // Trigger a 'beforeSaveRedirect' event |
618 | - $isNew = (int)$redirectConfig['id'] === 0; |
|
618 | + $isNew = (int) $redirectConfig[ 'id' ] === 0; |
|
619 | 619 | $event = new RedirectEvent([ |
620 | 620 | 'isNew' => $isNew, |
621 | - 'legacyUrl' => $redirectConfig['redirectSrcUrlParsed'], |
|
622 | - 'destinationUrl' => $redirectConfig['redirectDestUrl'], |
|
623 | - 'matchType' => $redirectConfig['redirectSrcMatch'], |
|
624 | - 'redirectType' => $redirectConfig['redirectHttpCode'], |
|
621 | + 'legacyUrl' => $redirectConfig[ 'redirectSrcUrlParsed' ], |
|
622 | + 'destinationUrl' => $redirectConfig[ 'redirectDestUrl' ], |
|
623 | + 'matchType' => $redirectConfig[ 'redirectSrcMatch' ], |
|
624 | + 'redirectType' => $redirectConfig[ 'redirectHttpCode' ], |
|
625 | 625 | ]); |
626 | 626 | $this->trigger(self::EVENT_BEFORE_SAVE_REDIRECT, $event); |
627 | 627 | if (!$event->isValid) { |
@@ -633,7 +633,7 @@ discard block |
||
633 | 633 | Craft::t( |
634 | 634 | 'retour', |
635 | 635 | 'Updating existing redirect: {redirect}', |
636 | - ['redirect' => print_r($redirectConfig, true)] |
|
636 | + [ 'redirect' => print_r($redirectConfig, true) ] |
|
637 | 637 | ), |
638 | 638 | __METHOD__ |
639 | 639 | ); |
@@ -643,7 +643,7 @@ discard block |
||
643 | 643 | '{{%retour_static_redirects}}', |
644 | 644 | $redirectConfig, |
645 | 645 | [ |
646 | - 'id' => $redirectConfig['id'], |
|
646 | + 'id' => $redirectConfig[ 'id' ], |
|
647 | 647 | ] |
648 | 648 | )->execute(); |
649 | 649 | } catch (Exception $e) { |
@@ -654,11 +654,11 @@ discard block |
||
654 | 654 | Craft::t( |
655 | 655 | 'retour', |
656 | 656 | 'Creating new redirect: {redirect}', |
657 | - ['redirect' => print_r($redirectConfig, true)] |
|
657 | + [ 'redirect' => print_r($redirectConfig, true) ] |
|
658 | 658 | ), |
659 | 659 | __METHOD__ |
660 | 660 | ); |
661 | - unset($redirectConfig['id']); |
|
661 | + unset($redirectConfig[ 'id' ]); |
|
662 | 662 | // Create a new record |
663 | 663 | try { |
664 | 664 | $db->createCommand()->insert( |
@@ -671,15 +671,15 @@ discard block |
||
671 | 671 | } |
672 | 672 | // To prevent redirect loops, see if any static redirects have our redirectDestUrl as their redirectSrcUrl |
673 | 673 | $testRedirectConfig = $this->getRedirectByRedirectSrcUrl( |
674 | - $redirectConfig['redirectDestUrl'], |
|
675 | - $redirectConfig['siteId'] |
|
674 | + $redirectConfig[ 'redirectDestUrl' ], |
|
675 | + $redirectConfig[ 'siteId' ] |
|
676 | 676 | ); |
677 | 677 | if ($testRedirectConfig !== null) { |
678 | 678 | Craft::debug( |
679 | 679 | Craft::t( |
680 | 680 | 'retour', |
681 | 681 | 'Deleting redirect to prevent a loop: {redirect}', |
682 | - ['redirect' => print_r($testRedirectConfig, true)] |
|
682 | + [ 'redirect' => print_r($testRedirectConfig, true) ] |
|
683 | 683 | ), |
684 | 684 | __METHOD__ |
685 | 685 | ); |
@@ -687,7 +687,7 @@ discard block |
||
687 | 687 | try { |
688 | 688 | $db->createCommand()->delete( |
689 | 689 | '{{%retour_static_redirects}}', |
690 | - ['id' => $testRedirectConfig['id']] |
|
690 | + [ 'id' => $testRedirectConfig[ 'id' ] ] |
|
691 | 691 | )->execute(); |
692 | 692 | } catch (Exception $e) { |
693 | 693 | Craft::error($e->getMessage(), __METHOD__); |
@@ -720,10 +720,10 @@ discard block |
||
720 | 720 | */ |
721 | 721 | public function excludeUri($uri): bool |
722 | 722 | { |
723 | - $uri = '/'.ltrim($uri, '/'); |
|
723 | + $uri = '/' . ltrim($uri, '/'); |
|
724 | 724 | if (!empty(Retour::$settings->excludePatterns)) { |
725 | 725 | foreach (Retour::$settings->excludePatterns as $excludePattern) { |
726 | - $pattern = '`'.$excludePattern['pattern'].'`i'; |
|
726 | + $pattern = '`' . $excludePattern[ 'pattern' ] . '`i'; |
|
727 | 727 | if (preg_match($pattern, $uri) === 1) { |
728 | 728 | return true; |
729 | 729 | } |