Beispiel #1
0
 public function testInstance()
 {
     $rule = new RedirectRule([1, Redirect::TYPE_EXACT, Redirect::TARGET_TYPE_PATH_URL, '/from/url', '/to/url', null, null, 301, null, Carbon::today(), Carbon::tomorrow()]);
     self::assertEquals(1, $rule->getId());
     self::assertEquals(Redirect::TYPE_EXACT, $rule->getMatchType());
     self::assertEquals(Redirect::TARGET_TYPE_PATH_URL, $rule->getTargetType());
     self::assertEquals('/from/url', $rule->getFromUrl());
     self::assertEquals('/to/url', $rule->getToUrl());
     self::assertEquals(301, $rule->getStatusCode());
     self::assertEquals(Carbon::today(), $rule->getFromDate());
     self::assertEquals(Carbon::tomorrow(), $rule->getToDate());
 }
Beispiel #2
0
 /**
  * Get Location URL to redirect to
  *
  * @param RedirectRule $rule
  * @return bool|string
  */
 public function getLocation(RedirectRule $rule)
 {
     $toUrl = false;
     // Determine the URL to redirect to
     switch ($rule->getTargetType()) {
         case Redirect::TARGET_TYPE_PATH_URL:
             $toUrl = $this->redirectToPathOrUrl($rule);
             // Check if $toUrl is a relative path, if so, we need to add the base path to it.
             // Refs: https://github.com/adrenth/redirect/issues/21
             if (is_string($toUrl) && $toUrl[0] !== '/' && substr($toUrl, 0, 7) !== 'http://' && substr($toUrl, 0, 8) !== 'https://') {
                 $toUrl = $this->basePath . '/' . $toUrl;
             }
             break;
         case Redirect::TARGET_TYPE_CMS_PAGE:
             $toUrl = $this->redirectToCmsPage($rule);
             break;
         case Redirect::TARGET_TYPE_STATIC_PAGE:
             $toUrl = $this->redirectToStaticPage($rule);
             break;
     }
     return $toUrl;
 }