Mercurial > hg > cmmr2012-drupal-site
comparison vendor/symfony-cmf/routing/Enhancer/RouteContentEnhancer.php @ 0:c75dbcec494b
Initial commit from drush-created site
author | Chris Cannam |
---|---|
date | Thu, 05 Jul 2018 14:24:15 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c75dbcec494b |
---|---|
1 <?php | |
2 | |
3 /* | |
4 * This file is part of the Symfony CMF package. | |
5 * | |
6 * (c) 2011-2015 Symfony CMF | |
7 * | |
8 * For the full copyright and license information, please view the LICENSE | |
9 * file that was distributed with this source code. | |
10 */ | |
11 | |
12 namespace Symfony\Cmf\Component\Routing\Enhancer; | |
13 | |
14 use Symfony\Component\HttpFoundation\Request; | |
15 use Symfony\Cmf\Component\Routing\RouteObjectInterface; | |
16 | |
17 /** | |
18 * This enhancer sets the content to target field if the route provides content. | |
19 * | |
20 * Only works with RouteObjectInterface routes that can return a referenced | |
21 * content. | |
22 * | |
23 * @author David Buchmann | |
24 */ | |
25 class RouteContentEnhancer implements RouteEnhancerInterface | |
26 { | |
27 /** | |
28 * @var string field for the route class | |
29 */ | |
30 protected $routefield; | |
31 /** | |
32 * @var string field to write hashmap lookup result into | |
33 */ | |
34 protected $target; | |
35 | |
36 /** | |
37 * @param string $routefield the field name of the route class | |
38 * @param string $target the field name to set from the map | |
39 * @param array $hashmap the map of class names to field values | |
40 */ | |
41 public function __construct($routefield, $target) | |
42 { | |
43 $this->routefield = $routefield; | |
44 $this->target = $target; | |
45 } | |
46 | |
47 /** | |
48 * If the route has a non-null content and if that content class is in the | |
49 * injected map, returns that controller. | |
50 * | |
51 * {@inheritdoc} | |
52 */ | |
53 public function enhance(array $defaults, Request $request) | |
54 { | |
55 if (isset($defaults[$this->target])) { | |
56 // no need to do anything | |
57 return $defaults; | |
58 } | |
59 | |
60 if (!isset($defaults[$this->routefield]) | |
61 || !$defaults[$this->routefield] instanceof RouteObjectInterface | |
62 ) { | |
63 // we can't determine the content | |
64 return $defaults; | |
65 } | |
66 /** @var $route RouteObjectInterface */ | |
67 $route = $defaults[$this->routefield]; | |
68 | |
69 $content = $route->getContent(); | |
70 if (!$content) { | |
71 // we have no content | |
72 return $defaults; | |
73 } | |
74 $defaults[$this->target] = $content; | |
75 | |
76 return $defaults; | |
77 } | |
78 } |