|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the EOffice project. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Anthonius Munthi <https://itstoni.com> |
|
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
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
use EOffice\Packages\Resource\Exceptions\ResourceException; |
|
15
|
|
|
use Illuminate\Config\Repository; |
|
16
|
|
|
use Illuminate\Support\Facades\App; |
|
17
|
|
|
|
|
18
|
|
|
if ( ! function_exists('register_model')) { |
|
19
|
|
|
/** |
|
20
|
|
|
* @param string $namespace |
|
21
|
|
|
* @param array<array-key,string> $options |
|
|
|
|
|
|
22
|
|
|
*/ |
|
23
|
|
|
function register_model(string $namespace, array $options): void |
|
24
|
|
|
{ |
|
25
|
|
|
/** @var Repository $config */ |
|
26
|
|
|
$config = App('config'); |
|
27
|
|
|
$managerName = $options['manager_name'] ?? 'default'; |
|
28
|
|
|
$type = $options['type'] ?? 'annotation'; |
|
29
|
|
|
$path = $options['path'] ?? null; |
|
30
|
|
|
|
|
31
|
|
|
if (null === $path) { |
|
32
|
|
|
throw ResourceException::nullModelPath(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
if ( ! is_dir($path)) { |
|
36
|
|
|
throw ResourceException::modelDirNotExists($path); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
$existing = (array) $config->get('doctrine.managers.default.mappings', []); |
|
40
|
|
|
$key = 'doctrine.managers.'.$managerName.'.mappings'; |
|
41
|
|
|
$config->set($key, array_merge($existing, [ |
|
42
|
|
|
$namespace => [ |
|
43
|
|
|
'dir' => realpath($path), |
|
44
|
|
|
'type' => $type, |
|
45
|
|
|
], |
|
46
|
|
|
])); |
|
47
|
|
|
} |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
if ( ! function_exists('load_doctrine_extension')) { |
|
51
|
|
|
/** |
|
52
|
|
|
* @param string|class-string $class |
|
|
|
|
|
|
53
|
|
|
* |
|
54
|
|
|
* @throws ResourceException when class not exists |
|
55
|
|
|
*/ |
|
56
|
|
|
function load_doctrine_extension(string $class) |
|
57
|
|
|
{ |
|
58
|
|
|
/** @var Repository $config */ |
|
59
|
|
|
$config = App('config'); |
|
60
|
|
|
|
|
61
|
|
|
$extensions = (array) $config->get('doctrine.extensions', []); |
|
62
|
|
|
$extensions[] = $class; |
|
63
|
|
|
|
|
64
|
|
|
if ( ! class_exists($class)) { |
|
65
|
|
|
throw ResourceException::doctrineExtensionClassNotExists($class); |
|
66
|
|
|
} |
|
67
|
|
|
$config->set('doctrine.extensions', $extensions); |
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
if ( ! function_exists('public_path')) { |
|
72
|
|
|
/** |
|
73
|
|
|
* Get the path to the public folder. |
|
74
|
|
|
* |
|
75
|
|
|
* @param string $path |
|
76
|
|
|
* |
|
77
|
|
|
* @return string |
|
78
|
|
|
*/ |
|
79
|
|
|
function public_path($path = '') |
|
80
|
|
|
{ |
|
81
|
|
|
return app()->make('path.public').($path ? \DIRECTORY_SEPARATOR.ltrim($path, \DIRECTORY_SEPARATOR) : $path); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
if ( ! function_exists('mix')) { |
|
86
|
|
|
/** |
|
87
|
|
|
* Get the path to a versioned Mix file. |
|
88
|
|
|
* |
|
89
|
|
|
* @param string $path |
|
90
|
|
|
* @param string $manifestDirectory |
|
91
|
|
|
* |
|
92
|
|
|
* @throws \Exception |
|
93
|
|
|
* |
|
94
|
|
|
* @return \Illuminate\Support\HtmlString|string |
|
95
|
|
|
*/ |
|
96
|
|
|
function mix($path, $manifestDirectory = '') |
|
97
|
|
|
{ |
|
98
|
|
|
return app(\EOffice\Packages\UI\Mix::class)(...func_get_args()); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|