Version 1
[yaffs-website] / web / modules / contrib / devel / webprofiler / src / Routing / TokenConverter.php
1 <?php
2
3 namespace Drupal\webprofiler\Routing;
4
5 use Drupal\Core\ParamConverter\ParamConverterInterface;
6 use Symfony\Component\Routing\Route;
7
8 /**
9  * Class TokenConverter
10  */
11 class TokenConverter implements ParamConverterInterface {
12
13   /**
14    * {@inheritdoc}
15    */
16   public function convert($value, $definition, $name, array $defaults) {
17     // "profiler" service isn't injected to prevent circular reference when
18     // more than one language is active and "Account administration pages" is
19     // enabled on admin/config/regional/language/detection. See #2710787 for
20     // more information.
21     /** @var \Drupal\webprofiler\Profiler\Profiler $profiler */
22     $profiler = \Drupal::service('profiler');
23
24     if (NULL === $profiler) {
25       return NULL;
26     }
27
28     $profile = $profiler->loadProfile($value);
29
30     if (NULL === $profile) {
31       return NULL;
32     }
33
34     return $profile;
35   }
36
37   /**
38    * {@inheritdoc}
39    */
40   public function applies($definition, $name, Route $route) {
41     if (!empty($definition['type']) && $definition['type'] === 'webprofiler:token') {
42       return TRUE;
43     }
44     return FALSE;
45   }
46 }