Exemplo n.º 1
0
 /**
  * Boot stuff for Frontend
  *
  * @return void
  */
 public function bootFrontend()
 {
     // Check for running in console or backend before route matching
     $rulesPath = storage_path('app/redirects.csv');
     if (!file_exists($rulesPath) || !is_readable($rulesPath)) {
         return;
     }
     $requestUri = str_replace(Request::getBasePath(), '', Request::getRequestUri());
     $manager = RedirectManager::createWithRulesPath($rulesPath);
     $rule = $manager->match($requestUri);
     if ($rule) {
         $manager->redirectWithRule($rule);
     }
 }
Exemplo n.º 2
0
 /**
  * Test Input Path
  *
  * @throws \ApplicationException
  */
 public function onTest()
 {
     $inputPath = Request::get('inputPath');
     $redirect = new Redirect(Request::get('Redirect'));
     try {
         $rule = RedirectRule::createWithModel($redirect);
         $manager = RedirectManager::createWithRule($rule);
         $testDate = new Carbon(Request::get('test_date', date('Y-m-d')));
         $manager->setMatchDate($testDate);
         $match = $manager->match($inputPath);
     } catch (\Exception $e) {
         throw new \ApplicationException($e->getMessage());
     }
     return ['#testResult' => $this->makePartial('redirect_test_result', ['match' => $match, 'url' => $match ? $manager->getLocation($match) : ''])];
 }
Exemplo n.º 3
0
 public function testAbsoluteRedirect()
 {
     $redirect = new Redirect(['match_type' => Redirect::TYPE_EXACT, 'target_type' => Redirect::TARGET_TYPE_PATH_URL, 'from_url' => '/this-should-be-source', 'to_url' => '/absolute/path/to', 'requirements' => null, 'status_code' => 302, 'is_enabled' => 1, 'from_date' => null, 'to_date' => null]);
     $rule = RedirectRule::createWithModel($redirect);
     $manager = RedirectManager::createWithRule($rule);
     self::assertEquals('/absolute/path/to', $manager->getLocation($rule));
     $manager->setBasePath('/subdirectory');
     self::assertEquals('/absolute/path/to', $manager->getLocation($rule));
     $manager->setBasePath('/subdirectory/sub/sub');
     self::assertEquals('/absolute/path/to', $manager->getLocation($rule));
 }