3709907dcde596cc092560ddb3238762e507f16d
[yaffs-website] / web / core / modules / system / tests / modules / url_alter_test / src / PathProcessor.php
1 <?php
2
3 namespace Drupal\url_alter_test;
4
5 use Drupal\Core\PathProcessor\InboundPathProcessorInterface;
6 use Symfony\Component\HttpFoundation\Request;
7
8 /**
9  * Path processor for url_alter_test.
10  */
11 class PathProcessor implements InboundPathProcessorInterface {
12
13   /**
14    * {@inheritdoc}
15    */
16   public function processInbound($path, Request $request) {
17     if (preg_match('!^/user/([^/]+)(/.*)?!', $path, $matches)) {
18       if ($account = user_load_by_name($matches[1])) {
19         $matches += [2 => ''];
20         $path = '/user/' . $account->id() . $matches[2];
21       }
22     }
23
24     // Rewrite community/ to forum/.
25     $path = preg_replace('@^/community(.*)@', '/forum$1', $path);
26
27     if ($path == '/url-alter-test/bar') {
28       $path = '/url-alter-test/foo';
29     }
30     return $path;
31   }
32
33 }