/** * Test that standard paths works with multiple patterns. * * @dataProvider getMatchPathData */ public function testMatchPath($patterns, $paths) { foreach ($paths as $path => $expected_result) { $actual_result = $this->pathMatcher->matchPath($path, $patterns); $this->assertEquals($actual_result, $expected_result, String::format('Tried matching the path <code>@path</code> to the pattern <pre>@patterns</pre> - expected @expected, got @actual.', array('@path' => $path, '@patterns' => $patterns, '@expected' => var_export($expected_result, TRUE), '@actual' => var_export($actual_result, TRUE)))); } }
/** * Test that standard paths works with multiple patterns. * * @dataProvider getMatchPathData */ public function testMatchPath($patterns, $paths) { foreach ($paths as $path => $expected_result) { $actual_result = $this->pathMatcher->matchPath($path, $patterns); $this->assertEquals($actual_result, $expected_result, "Tried matching the path '{$path}' to the pattern '{$patterns}'."); } }
/** * Perform the anonymous user redirection, if needed. * * This method is called whenever the KernelEvents::REQUEST event is * dispatched. * * @param GetResponseEvent $event */ public function redirect(GetResponseEvent $event) { // Skip if maintenance mode is enabled. if ($this->state->get('system.maintenance_mode')) { return; } // Skip if running from the command-line. if (PHP_SAPI === 'cli') { return; } // Skip if no paths are configured for redirecting. if (!($paths = $this->paths()) || empty($paths['include'])) { return; } // Skip if the user is not anonymous. if (!$this->current_user->isAnonymous()) { return; } // Determine the current path and alias. $current = [ 'path' => $this->path_current->getPath(), 'alias' => \Drupal::request()->getRequestUri(), ]; // Ignore PHP file requests. if (substr($current['path'], -4) == '.php') { return; } // Ignore the user login page. if ($current['path'] == '/user/login') { return; } // Convert the path to the front page token, if needed. $current['path'] = ($current['path'] != '/') ? $current['path'] : '<front>'; // Track if we should redirect. $redirect = FALSE; // Iterate the current path and alias. foreach ($current as &$check) { // Remove the leading slash. $check = substr($check, 1); // Check if there is a trailer slash. if (substr($check, -1) == '/') { // Remove it. $check = substr($check, 0, strlen($check) - 1); } // Redirect if the path is a match for included paths. if ($this->path_matcher->matchPath($check, implode("\n", $paths['include']))) { $redirect = TRUE; } // Do not redirect if the path is a match for excluded paths. if ($this->path_matcher->matchPath($check, implode("\n", $paths['exclude']))) { $redirect = FALSE; // Matching an excluded path is a hard-stop. break; } } // See if we're going to redirect. if ($redirect) { // See if we have a message to display. if ($message = $this->config_factory->get('anonymous_login.settings')->get('message')) { // @todo: translation? // @todo: This does not show after the redirect.. drupal_set_message($message); } // Redirect to the login, keeping the requested alias as the destination. $response = new RedirectResponse('/user/login?destination=' . $current['alias']); $response->send(); exit(); } }
protected function getSv() { return $this->pathMatch->isFrontPage() ? 'ke' : 'in'; }