1 | <?php |
||
2 | |||
3 | use Ffcms\Core\Helper\Type\Any; |
||
4 | use Ffcms\Templex\Url\Url; |
||
0 ignored issues
–
show
|
|||
5 | |||
6 | /** @var $routes array */ |
||
7 | /** @var \Ffcms\Templex\Template\Template $this */ |
||
8 | |||
9 | $this->layout('_layouts/default', [ |
||
10 | 'title' => __('Routing'), |
||
11 | 'breadcrumbs' => [ |
||
12 | Url::to('main/index') => __('Main'), |
||
13 | __('Routing') |
||
14 | ] |
||
15 | ]); |
||
16 | $aliasExist = false; |
||
17 | $callbackExist = false; |
||
18 | ?> |
||
19 | |||
20 | <?php $this->start('body') ?> |
||
21 | <h1><?= __('Routing scheme') ?></h1> |
||
22 | <div class="row"> |
||
23 | <div class="col-md-6"> |
||
24 | <h2><?= __('Static(alias) routes') ?></h2> |
||
25 | <?php |
||
26 | if ($routes['Alias'] && Any::isArray($routes['Alias']) && count($routes['Alias']) > 0) { |
||
27 | $aliasExist = true; |
||
28 | echo '<div class="table-responsive">'; |
||
29 | $alias = $this->table(['class' => 'table']) |
||
30 | ->head([ |
||
31 | ['text' => "Source → Target"], |
||
32 | ['text' => __('Environment')], |
||
33 | ['text' => ''] |
||
34 | ]); |
||
35 | foreach ($routes['Alias'] as $env => $route) { |
||
36 | if (Any::isArray($route)) { |
||
37 | foreach ($route as $source => $target) { |
||
38 | $alias->row([ |
||
39 | ['text' => '<span class="badge badge-primary">' . $source . '</span> ' . |
||
40 | '→ ' . |
||
41 | '<span class="badge badge-secondary">' . $target . '</span>', 'html' => true], |
||
42 | ['text' => $env], |
||
43 | ['text' => Url::a( |
||
44 | ['main/deleteroute', null, ['type' => 'Alias', 'loader' => $env, 'path' => $source]], |
||
45 | '<i class="fa fa-remove"></i>', |
||
46 | ['html' => true] |
||
47 | ), 'properties' => ['class' => 'text-center'], 'html' => true] |
||
48 | ]); |
||
49 | } |
||
50 | } |
||
51 | } |
||
52 | echo $alias->display(); |
||
53 | echo '</div>'; |
||
54 | } |
||
55 | ?> |
||
56 | </div> |
||
57 | <div class="col-md-6"> |
||
58 | <h2><?= __('Dynamic(callback) routes') ?></h2> |
||
59 | <?php |
||
60 | if ($routes['Callback'] && Any::isArray($routes['Callback']) && count($routes['Callback']) > 0) { |
||
61 | $callbackExist = true; |
||
62 | echo '<div class="table-responsive">'; |
||
63 | $dynamic = $this->table(['class' => 'table']) |
||
64 | ->head([ |
||
65 | ['text' => "Source → Target"], |
||
66 | ['text' => __('Environment')], |
||
67 | ['text' => ''] |
||
68 | ]); |
||
69 | foreach ($routes['Callback'] as $env => $route) { |
||
70 | if (Any::isArray($route)) { |
||
71 | foreach ($route as $source => $target) { |
||
72 | $dynamic->row([ |
||
73 | ['text' => '<span class="badge badge-primary">' . $source . '</span> ' . |
||
74 | '→ ' . |
||
75 | '<span class="badge badge-secondary">' . $target . '</span>', 'html' => true], |
||
76 | ['text' => $env], |
||
77 | ['text' => Url::a( |
||
78 | ['main/deleteroute', null, ['type' => 'Callback', 'loader' => $env, 'path' => $source]], |
||
79 | '<i class="fa fa-remove"></i>', |
||
80 | ['html' => true] |
||
81 | ), 'properties' => ['class' => 'text-center'], 'html' => true] |
||
82 | ]); |
||
83 | } |
||
84 | } |
||
85 | } |
||
86 | echo $dynamic->display(); |
||
87 | echo '</div>'; |
||
88 | } |
||
89 | ?> |
||
90 | </div> |
||
91 | </div> |
||
92 | <?php if (!$aliasExist && !$callbackExist): ?> |
||
93 | <p class="alert alert-warning"><?= __('Custom routes is not yet found') ?></p> |
||
94 | <?php endif ;?> |
||
95 | <?= Url::a(['main/addroute'], '<i class="fa fa-plus"></i> ' . __('New route'), ['class' => 'btn btn-primary', 'html' => true]) ?> |
||
96 | <?php $this->stop() ?> |
||
97 |
Let?s assume that you have a directory layout like this:
and let?s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: