@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | Craft::t( |
| 86 | 86 | 'retour', |
| 87 | 87 | '404 URL: {url}', |
| 88 | - ['url' => $url] |
|
| 88 | + [ 'url' => $url ] |
|
| 89 | 89 | ), |
| 90 | 90 | __METHOD__ |
| 91 | 91 | ); |
@@ -114,13 +114,13 @@ discard block |
||
| 114 | 114 | { |
| 115 | 115 | $response = Craft::$app->getResponse(); |
| 116 | 116 | if ($redirect !== null) { |
| 117 | - $dest = $redirect['redirectDestUrl']; |
|
| 118 | - $status = $redirect['redirectHttpCode']; |
|
| 117 | + $dest = $redirect[ 'redirectDestUrl' ]; |
|
| 118 | + $status = $redirect[ 'redirectHttpCode' ]; |
|
| 119 | 119 | Craft::info( |
| 120 | 120 | Craft::t( |
| 121 | 121 | 'retour', |
| 122 | 122 | 'Redirecting {url} to {dest} with status {status}', |
| 123 | - ['url' => $url, 'dest' => $dest, 'status' => $status] |
|
| 123 | + [ 'url' => $url, 'dest' => $dest, 'status' => $status ] |
|
| 124 | 124 | ), |
| 125 | 125 | __METHOD__ |
| 126 | 126 | ); |
@@ -172,13 +172,13 @@ discard block |
||
| 172 | 172 | public function getRedirectFromCache($url) |
| 173 | 173 | { |
| 174 | 174 | $cache = Craft::$app->getCache(); |
| 175 | - $cacheKey = $this::CACHE_KEY.md5($url); |
|
| 175 | + $cacheKey = $this::CACHE_KEY . md5($url); |
|
| 176 | 176 | $redirect = $cache->get($cacheKey); |
| 177 | 177 | Craft::info( |
| 178 | 178 | Craft::t( |
| 179 | 179 | 'retour', |
| 180 | 180 | 'Cached redirect hit for {url}', |
| 181 | - ['url' => $url] |
|
| 181 | + [ 'url' => $url ] |
|
| 182 | 182 | ), |
| 183 | 183 | __METHOD__ |
| 184 | 184 | ); |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | */ |
| 193 | 193 | public function saveRedirectToCache($url, $redirect) |
| 194 | 194 | { |
| 195 | - $cacheKey = $this::CACHE_KEY.md5($url); |
|
| 195 | + $cacheKey = $this::CACHE_KEY . md5($url); |
|
| 196 | 196 | $cache = Craft::$app->getCache(); |
| 197 | 197 | // Get the current site id |
| 198 | 198 | $sites = Craft::$app->getSites(); |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | $dependency = new TagDependency([ |
| 206 | 206 | 'tags' => [ |
| 207 | 207 | $this::GLOBAL_REDIRECTS_CACHE_TAG, |
| 208 | - $this::GLOBAL_REDIRECTS_CACHE_TAG.$siteId, |
|
| 208 | + $this::GLOBAL_REDIRECTS_CACHE_TAG . $siteId, |
|
| 209 | 209 | ], |
| 210 | 210 | ]); |
| 211 | 211 | $cache->set($cacheKey, $redirect, Retour::$cacheDuration, $dependency); |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | Craft::t( |
| 214 | 214 | 'retour', |
| 215 | 215 | 'Cached redirect saved for {url}', |
| 216 | - ['url' => $url] |
|
| 216 | + [ 'url' => $url ] |
|
| 217 | 217 | ), |
| 218 | 218 | __METHOD__ |
| 219 | 219 | ); |
@@ -229,11 +229,11 @@ discard block |
||
| 229 | 229 | { |
| 230 | 230 | $result = null; |
| 231 | 231 | foreach ($redirects as $redirect) { |
| 232 | - $redirectMatchType = $redirect['redirectMatchType'] ?? null; |
|
| 232 | + $redirectMatchType = $redirect[ 'redirectMatchType' ] ?? null; |
|
| 233 | 233 | switch ($redirectMatchType) { |
| 234 | 234 | // Do a straight up match |
| 235 | 235 | case 'exactmatch': |
| 236 | - if (strcasecmp($redirect['redirectSrcUrlParsed'], $url) === 0) { |
|
| 236 | + if (strcasecmp($redirect[ 'redirectSrcUrlParsed' ], $url) === 0) { |
|
| 237 | 237 | $this->incrementRedirectHitCount($redirect); |
| 238 | 238 | $this->saveRedirectToCache($url, $redirect); |
| 239 | 239 | |
@@ -243,14 +243,14 @@ discard block |
||
| 243 | 243 | |
| 244 | 244 | // Do a regex match |
| 245 | 245 | case 'regexmatch': |
| 246 | - $matchRegEx = '`'.$redirect['redirectSrcUrlParsed'].'`i'; |
|
| 246 | + $matchRegEx = '`' . $redirect[ 'redirectSrcUrlParsed' ] . '`i'; |
|
| 247 | 247 | if (preg_match($matchRegEx, $url) === 1) { |
| 248 | 248 | $this->incrementRedirectHitCount($redirect); |
| 249 | 249 | // If we're not associated with an EntryID, handle capture group replacement |
| 250 | - if ((int)$redirect['associatedElementId'] === 0) { |
|
| 251 | - $redirect['redirectDestUrl'] = preg_replace( |
|
| 250 | + if ((int) $redirect[ 'associatedElementId' ] === 0) { |
|
| 251 | + $redirect[ 'redirectDestUrl' ] = preg_replace( |
|
| 252 | 252 | $matchRegEx, |
| 253 | - $redirect['redirectDestUrl'], |
|
| 253 | + $redirect[ 'redirectDestUrl' ], |
|
| 254 | 254 | $url |
| 255 | 255 | ); |
| 256 | 256 | } |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | 'redirect' => &$redirect, |
| 270 | 270 | ], |
| 271 | 271 | ]; |
| 272 | - $result = \call_user_func_array([$plugin, 'retourMatch'], $args); |
|
| 272 | + $result = \call_user_func_array([ $plugin, 'retourMatch' ], $args); |
|
| 273 | 273 | if ($result) { |
| 274 | 274 | $this->incrementRedirectHitCount($redirect); |
| 275 | 275 | $this->saveRedirectToCache($url, $redirect); |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | Craft::t( |
| 285 | 285 | 'retour', |
| 286 | 286 | 'Not handled: {url}', |
| 287 | - ['url' => $url] |
|
| 287 | + [ 'url' => $url ] |
|
| 288 | 288 | ), |
| 289 | 289 | __METHOD__ |
| 290 | 290 | ); |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | foreach (Craft::$app->getPlugins()->getAllPlugins() as $plugin) { |
| 309 | 309 | /** @var Plugin $plugin */ |
| 310 | 310 | if (method_exists($plugin, 'retourMatch')) { |
| 311 | - $result[$plugin->getHandle()] = $plugin->name.Craft::t('retour', ' Match'); |
|
| 311 | + $result[ $plugin->getHandle() ] = $plugin->name . Craft::t('retour', ' Match'); |
|
| 312 | 312 | } |
| 313 | 313 | } |
| 314 | 314 | |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | } |
| 329 | 329 | // Query the db table |
| 330 | 330 | $query = (new Query()) |
| 331 | - ->from(['{{%retour_static_redirects}}']) |
|
| 331 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
| 332 | 332 | ->orderBy('redirectMatchType ASC, hitCount DESC'); |
| 333 | 333 | if ($limit) { |
| 334 | 334 | $query->limit($limit); |
@@ -351,8 +351,8 @@ discard block |
||
| 351 | 351 | { |
| 352 | 352 | // Query the db table |
| 353 | 353 | $redirect = (new Query()) |
| 354 | - ->from(['{{%retour_static_redirects}}']) |
|
| 355 | - ->where(['id' => $id]) |
|
| 354 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
| 355 | + ->where([ 'id' => $id ]) |
|
| 356 | 356 | ->one(); |
| 357 | 357 | |
| 358 | 358 | return $redirect; |
@@ -369,8 +369,8 @@ discard block |
||
| 369 | 369 | { |
| 370 | 370 | // Query the db table |
| 371 | 371 | $redirect = (new Query()) |
| 372 | - ->from(['{{%retour_static_redirects}}']) |
|
| 373 | - ->where(['redirectSrcUrl' => $redirectSrcUrl]) |
|
| 372 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
| 373 | + ->where([ 'redirectSrcUrl' => $redirectSrcUrl ]) |
|
| 374 | 374 | ->one(); |
| 375 | 375 | |
| 376 | 376 | return $redirect; |
@@ -411,13 +411,13 @@ discard block |
||
| 411 | 411 | { |
| 412 | 412 | if ($redirectConfig !== null) { |
| 413 | 413 | $db = Craft::$app->getDb(); |
| 414 | - $redirectConfig['hitCount']++; |
|
| 415 | - $redirectConfig['hitLastTime'] = Db::prepareDateForDb(new \DateTime()); |
|
| 414 | + $redirectConfig[ 'hitCount' ]++; |
|
| 415 | + $redirectConfig[ 'hitLastTime' ] = Db::prepareDateForDb(new \DateTime()); |
|
| 416 | 416 | Craft::debug( |
| 417 | 417 | Craft::t( |
| 418 | 418 | 'retour', |
| 419 | 419 | 'Incrementing statistics for: {redirect}', |
| 420 | - ['redirect' => print_r($redirectConfig, true)] |
|
| 420 | + [ 'redirect' => print_r($redirectConfig, true) ] |
|
| 421 | 421 | ), |
| 422 | 422 | __METHOD__ |
| 423 | 423 | ); |
@@ -426,14 +426,14 @@ discard block |
||
| 426 | 426 | $rowsAffected = $db->createCommand()->update( |
| 427 | 427 | '{{%retour_static_redirects}}', |
| 428 | 428 | [ |
| 429 | - 'hitCount' => $redirectConfig['hitCount'], |
|
| 430 | - 'hitLastTime' => $redirectConfig['hitLastTime'], |
|
| 429 | + 'hitCount' => $redirectConfig[ 'hitCount' ], |
|
| 430 | + 'hitLastTime' => $redirectConfig[ 'hitLastTime' ], |
|
| 431 | 431 | ], |
| 432 | 432 | [ |
| 433 | - 'id' => $redirectConfig['id'], |
|
| 433 | + 'id' => $redirectConfig[ 'id' ], |
|
| 434 | 434 | ] |
| 435 | 435 | )->execute(); |
| 436 | - Craft::debug('Rows affected: '.$rowsAffected, __METHOD__); |
|
| 436 | + Craft::debug('Rows affected: ' . $rowsAffected, __METHOD__); |
|
| 437 | 437 | } catch (Exception $e) { |
| 438 | 438 | Craft::error($e->getMessage(), __METHOD__); |
| 439 | 439 | } |
@@ -452,7 +452,7 @@ discard block |
||
| 452 | 452 | Craft::t( |
| 453 | 453 | 'retour', |
| 454 | 454 | 'Error validating redirect {id}: {errors}', |
| 455 | - ['id' => $redirect->id, 'errors' => print_r($redirect->getErrors(), true)] |
|
| 455 | + [ 'id' => $redirect->id, 'errors' => print_r($redirect->getErrors(), true) ] |
|
| 456 | 456 | ), |
| 457 | 457 | __METHOD__ |
| 458 | 458 | ); |
@@ -463,23 +463,23 @@ discard block |
||
| 463 | 463 | $redirectConfig = $redirect->getAttributes(); |
| 464 | 464 | $db = Craft::$app->getDb(); |
| 465 | 465 | // See if a redirect exists with this source URL already |
| 466 | - if ((int)$redirectConfig['id'] === 0) { |
|
| 466 | + if ((int) $redirectConfig[ 'id' ] === 0) { |
|
| 467 | 467 | // Query the db table |
| 468 | 468 | $redirect = (new Query()) |
| 469 | - ->from(['{{%retour_static_redirects}}']) |
|
| 470 | - ->where(['redirectSrcUrlParsed' => $redirectConfig['redirectSrcUrlParsed']]) |
|
| 469 | + ->from([ '{{%retour_static_redirects}}' ]) |
|
| 470 | + ->where([ 'redirectSrcUrlParsed' => $redirectConfig[ 'redirectSrcUrlParsed' ] ]) |
|
| 471 | 471 | ->one(); |
| 472 | 472 | // If it exists, update it rather than having duplicates |
| 473 | 473 | if (!empty($redirect)) { |
| 474 | - $redirectConfig['id'] = $redirect['id']; |
|
| 474 | + $redirectConfig[ 'id' ] = $redirect[ 'id' ]; |
|
| 475 | 475 | } |
| 476 | 476 | } |
| 477 | - if ((int)$redirectConfig['id'] !== 0) { |
|
| 477 | + if ((int) $redirectConfig[ 'id' ] !== 0) { |
|
| 478 | 478 | Craft::debug( |
| 479 | 479 | Craft::t( |
| 480 | 480 | 'retour', |
| 481 | 481 | 'Updating existing redirect: {redirect}', |
| 482 | - ['redirect' => print_r($redirectConfig, true)] |
|
| 482 | + [ 'redirect' => print_r($redirectConfig, true) ] |
|
| 483 | 483 | ), |
| 484 | 484 | __METHOD__ |
| 485 | 485 | ); |
@@ -489,7 +489,7 @@ discard block |
||
| 489 | 489 | '{{%retour_static_redirects}}', |
| 490 | 490 | $redirectConfig, |
| 491 | 491 | [ |
| 492 | - 'id' => $redirectConfig['id'], |
|
| 492 | + 'id' => $redirectConfig[ 'id' ], |
|
| 493 | 493 | ] |
| 494 | 494 | )->execute(); |
| 495 | 495 | } catch (Exception $e) { |
@@ -500,7 +500,7 @@ discard block |
||
| 500 | 500 | Craft::t( |
| 501 | 501 | 'retour', |
| 502 | 502 | 'Creating new redirect: {redirect}', |
| 503 | - ['redirect' => print_r($redirectConfig, true)] |
|
| 503 | + [ 'redirect' => print_r($redirectConfig, true) ] |
|
| 504 | 504 | ), |
| 505 | 505 | __METHOD__ |
| 506 | 506 | ); |
@@ -515,13 +515,13 @@ discard block |
||
| 515 | 515 | } |
| 516 | 516 | } |
| 517 | 517 | // To prevent redirect loops, see if any static redirects have our redirectDestUrl as their redirectSrcUrl |
| 518 | - $testRedirectConfig = $this->getRedirectByRedirectSrcUrl($redirectConfig['redirectDestUrl']); |
|
| 518 | + $testRedirectConfig = $this->getRedirectByRedirectSrcUrl($redirectConfig[ 'redirectDestUrl' ]); |
|
| 519 | 519 | if ($testRedirectConfig !== null) { |
| 520 | 520 | Craft::debug( |
| 521 | 521 | Craft::t( |
| 522 | 522 | 'retour', |
| 523 | 523 | 'Deleting redirect to prevent a loop: {redirect}', |
| 524 | - ['redirect' => print_r($testRedirectConfig, true)] |
|
| 524 | + [ 'redirect' => print_r($testRedirectConfig, true) ] |
|
| 525 | 525 | ), |
| 526 | 526 | __METHOD__ |
| 527 | 527 | ); |
@@ -529,7 +529,7 @@ discard block |
||
| 529 | 529 | try { |
| 530 | 530 | $db->createCommand()->delete( |
| 531 | 531 | '{{%retour_static_redirects}}', |
| 532 | - ['id' => $testRedirectConfig['id']] |
|
| 532 | + [ 'id' => $testRedirectConfig[ 'id' ] ] |
|
| 533 | 533 | )->execute(); |
| 534 | 534 | } catch (Exception $e) { |
| 535 | 535 | Craft::error($e->getMessage(), __METHOD__); |