These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Victoire\Bundle\CoreBundle\Route; |
||
4 | |||
5 | use Symfony\Component\Config\Loader\Loader; |
||
6 | use Symfony\Component\Routing\Route; |
||
7 | use Symfony\Component\Routing\RouteCollection; |
||
8 | |||
9 | class RouteLoader extends Loader |
||
10 | { |
||
11 | protected $widgets; |
||
12 | |||
13 | public function __construct($widgets) |
||
14 | { |
||
15 | $this->widgets = $widgets; |
||
16 | } |
||
17 | |||
18 | public function load($resource, $type = null) |
||
19 | { |
||
20 | $collection = new RouteCollection(); |
||
21 | |||
22 | $this->addVictoireRouting($collection); |
||
23 | $this->addWidgetsRouting($collection); |
||
24 | $this->addShowPageByIdRoute($collection); |
||
25 | $this->addShowBusinessPageByIdAction($collection); |
||
26 | $this->addShowPageRoute($collection); |
||
27 | $this->addShowHomePageRoute($collection); |
||
28 | |||
29 | return $collection; |
||
30 | } |
||
31 | |||
32 | protected function addVictoireRouting(RouteCollection &$collection) |
||
33 | { |
||
34 | $resources = [ |
||
35 | '@VictoireAnalyticsBundle/Controller/', |
||
36 | '@VictoireTemplateBundle/Controller/', |
||
37 | '@VictoireBlogBundle/Controller/', |
||
38 | '@VictoireBusinessPageBundle/Controller/', |
||
39 | '@VictoireSeoBundle/Controller/', |
||
40 | '@VictoireMediaBundle/Controller/', |
||
41 | '@VictoirePageBundle/Controller/', |
||
42 | '@VictoireCoreBundle/Controller/', |
||
43 | '@VictoireWidgetBundle/Controller/', |
||
44 | '@VictoireSitemapBundle/Controller/', |
||
45 | ]; |
||
46 | foreach ($resources as $resource) { |
||
47 | $importedRoutes = $this->import($resource, 'annotation'); |
||
48 | $collection->addCollection($importedRoutes); |
||
49 | } |
||
50 | } |
||
51 | |||
52 | protected function addWidgetsRouting(RouteCollection &$collection) |
||
53 | { |
||
54 | foreach ($this->widgets as $widgetParams) { |
||
55 | $controllerResource = '@VictoireWidget'.$widgetParams['name'].'Bundle/Controller/'; |
||
56 | if ($this->getResolver()->resolve($controllerResource)) { |
||
57 | $importedRoutes = $this->import($controllerResource, 'annotation'); |
||
58 | $collection->addCollection($importedRoutes); |
||
59 | } |
||
60 | } |
||
61 | } |
||
62 | |||
63 | protected function addShowBusinessPageByIdAction(RouteCollection &$collection) |
||
64 | { |
||
65 | $pattern = '/victoire-dcms-public/show-business-page-by-id/{entityId}/{type}'; |
||
66 | $defaults = [ |
||
67 | '_controller' => 'VictoirePageBundle:Page:showBusinessPageById', |
||
68 | ]; |
||
69 | $requirements = [ |
||
70 | 'viewId' => '\d+', |
||
71 | ]; |
||
72 | $route = new Route($pattern, $defaults, $requirements); |
||
73 | $routeName = 'victoire_core_business_page_show_by_id'; |
||
74 | $collection->add($routeName, $route); |
||
75 | } |
||
76 | |||
77 | protected function addShowPageByIdRoute(RouteCollection &$collection) |
||
78 | { |
||
79 | $pattern = '/victoire-dcms-public/show-page-by-id/{viewId}/{entityId}'; |
||
80 | $defaults = [ |
||
81 | '_controller' => 'VictoirePageBundle:Page:showById', |
||
82 | 'entityId' => null, |
||
83 | ]; |
||
84 | $requirements = [ |
||
85 | 'viewId' => '\d+', |
||
86 | ]; |
||
87 | $options = [ |
||
88 | 'expose' => true, |
||
89 | ]; |
||
90 | $route = new Route($pattern, $defaults, $requirements, $options); |
||
91 | $routeName = 'victoire_core_page_show_by_id'; |
||
92 | $collection->add($routeName, $route); |
||
93 | } |
||
94 | |||
95 | View Code Duplication | protected function addShowPageRoute(RouteCollection &$collection) |
|
0 ignored issues
–
show
|
|||
96 | { |
||
97 | // prepare a new route |
||
98 | $pattern = '/{url}'; |
||
99 | $defaults = [ |
||
100 | '_controller' => 'VictoirePageBundle:Page:show', |
||
101 | ]; |
||
102 | $requirements = [ |
||
103 | 'url' => '^.*$', |
||
104 | ]; |
||
105 | $route = new Route($pattern, $defaults, $requirements); |
||
106 | |||
107 | // add the new route to the route collection: |
||
108 | $collection->add('victoire_core_page_show', $route); |
||
109 | } |
||
110 | |||
111 | View Code Duplication | protected function addShowHomePageRoute(RouteCollection &$collection) |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
112 | { |
||
113 | // prepare a new route |
||
114 | $pattern = '/'; |
||
115 | $defaults = [ |
||
116 | '_controller' => 'VictoirePageBundle:Page:show', |
||
117 | ]; |
||
118 | $options = [ |
||
119 | 'expose' => true, |
||
120 | ]; |
||
121 | $route = new Route($pattern, $defaults, [], $options); |
||
122 | |||
123 | // add the new route to the route collection: |
||
124 | $collection->add('victoire_core_homepage_show', $route); |
||
125 | } |
||
126 | |||
127 | public function supports($resource, $type = null) |
||
128 | { |
||
129 | return $type === 'victoire'; |
||
130 | } |
||
131 | } |
||
132 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.