1 | <?php |
||
2 | |||
3 | use Jidaikobo\Kontiki\Bootstrap; |
||
4 | use Jidaikobo\Kontiki\Core\Auth; |
||
0 ignored issues
–
show
|
|||
5 | use Jidaikobo\Kontiki\Models\PostModel; |
||
6 | |||
7 | if (!function_exists('getIndex')) { |
||
8 | /** |
||
9 | * @param array $args Configuration for the request. |
||
10 | * @param string $env environment. |
||
11 | * @return array |
||
12 | */ |
||
13 | function getIndex(array $args, string $env = 'production'): array |
||
14 | { |
||
15 | $app = Bootstrap::init($env); |
||
16 | $model = $app->getContainer()->get(PostModel::class); |
||
17 | $retval = []; |
||
18 | $retval['body'] = $model->getIndexData('published', $args); |
||
19 | $retval['pagination'] = $model->getPagination(); |
||
20 | return $retval; |
||
21 | } |
||
22 | } |
||
23 | |||
24 | if (!function_exists('getData')) { |
||
25 | /** |
||
26 | * @param array $args Configuration for the request. |
||
27 | * @param string $env environment. |
||
28 | * @return array |
||
29 | */ |
||
30 | function getData(array $args, string $env = 'production'): array |
||
0 ignored issues
–
show
|
|||
31 | { |
||
32 | $app = Bootstrap::init($env); |
||
33 | $model = $app->getContainer()->get(PostModel::class); |
||
34 | $slug = $args['slug'] ?? ''; |
||
35 | $retval = []; |
||
36 | $retval['body'] = $model->getByFieldWithCondtioned('slug', $slug, 'published'); |
||
37 | return $retval; |
||
38 | } |
||
39 | } |
||
40 | |||
41 | if (!function_exists('printEditDataLink')) { |
||
42 | /** |
||
43 | * @param array $args Configuration for the request. |
||
44 | * @param string $env environment. |
||
45 | * @return void |
||
46 | */ |
||
47 | function printEditDataLink(array $args, string $env = 'production'): void |
||
0 ignored issues
–
show
|
|||
48 | { |
||
49 | $app = Bootstrap::init($env); |
||
50 | $auth = $app->getContainer()->get(Auth::class); |
||
51 | if (!$auth->isLoggedIn()) { |
||
52 | return; |
||
53 | } |
||
54 | |||
55 | $app = Bootstrap::init($env); |
||
56 | $model = $app->getContainer()->get(PostModel::class); |
||
57 | $slug = $args['slug'] ?? ''; |
||
58 | $data = $model->getByFieldWithCondtioned('slug', $slug, 'published'); |
||
59 | $url = $app->getBasePath() . '/' . e($data['post_type']) . '/edit/' . e($data['id']); |
||
60 | |||
61 | $html = ''; |
||
62 | $html .= '<p class="edit-this-page"><a href="' . $url . '">'; |
||
63 | $html .= __('edit_this_content'); |
||
64 | $html .= '</a></p>'; |
||
65 | echo $html; |
||
66 | } |
||
67 | } |
||
68 |
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: