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