-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathentry-2.php
More file actions
106 lines (85 loc) · 3.24 KB
/
Copy pathentry-2.php
File metadata and controls
106 lines (85 loc) · 3.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
<?php
use PHPModules\Demo\Config::Loader;
use PHPModules\Demo\Config::ConfigValue;
use PHPModules\Demo\Config::SupportedFormats;
use PHPModules\Demo\Config::FileSource;
require __DIR__ . "/vendor/autoload.php";
$GLOBALS['deepseek/config'] = [
'files' => [
'app.json' => json_encode([
'app_name' => 'My App',
'debug' => true,
]),
'db.json' => json_encode([
'db_host' => 'localhost',
'db_port' => 5432,
]),
],
];
echo "=== Config Module Demo 2 — Advanced Features ===\n\n";
// 1. Error values — missing source is skipped, not fatal
echo "1. SourceError — missing file skips gracefully:\n";
$loader = new Loader();
$loader->addFileSource('nonexistent.json', SupportedFormats::Json);
$loader->addFileSource('app.json', SupportedFormats::Json);
$config = $loader->load();
echo " Loaded (1 of 2 sources succeeded)\n\n";
// 2. Merging from multiple files
echo "2. Merge — config from two JSON sources:\n";
$loader2 = new Loader();
$loader2->addFileSource('app.json', SupportedFormats::Json);
$loader2->addFileSource('db.json', SupportedFormats::Json);
$merged = $loader2->load();
echo " app_name: " . $merged->get('app_name') . "\n";
echo " db_host: " . $merged->get('db_host') . "\n\n";
// 3. ConfigValue boundary — internal constructor
echo "3. ConfigValue — internal constructor:\n";
try {
new ConfigValue('x', 'y');
} catch (\Error $e) {
echo " DENIED: " . $e->getMessage() . "\n\n";
}
// 4. internal const — inaccessible from outside
echo "4. PHPModules\Demo\\Config::DEFAULT_CACHE_TTL — internal const:\n";
try {
$ttl = \PHPModules\Demo\Config::DEFAULT_CACHE_TTL;
} catch (\Error $e) {
echo " DENIED: " . $e->getMessage() . "\n\n";
}
// 5. internal method — inaccessible from outside
echo "5. Loader::resolveParser() — internal method:\n";
$source = new FileSource('app.json', SupportedFormats::Json);
try {
$loader2->resolveParser($source);
} catch (\Error $e) {
echo " DENIED: " . $e->getMessage() . "\n\n";
}
// 6. SupportedFormats enum — public, usable from outside
echo "6. SupportedFormats — public enum:\n";
$format = SupportedFormats::Json;
echo " Case: " . $format->name . "\n";
echo " Match: " . match ($format) {
SupportedFormats::Json => 'JSON',
SupportedFormats::Yaml => 'YAML',
SupportedFormats::Env => 'ENV',
} . "\n\n";
echo "=== Demo Complete ===\n";
/*
project-deepseek $ ../php-src-cli entry-2.php
=== Config Module Demo 2 — Advanced Features ===
1. SourceError — missing file skips gracefully:
Loaded (1 of 2 sources succeeded)
2. Merge — config from two JSON sources:
app_name: My App
db_host: localhost
3. ConfigValue — internal constructor:
DENIED: Cannot instantiate class PHPModules\Demo\Config::ConfigValue via internal constructor from outside its module
4. PHPModules\Demo\Config::DEFAULT_CACHE_TTL — internal const:
DENIED: Cannot access internal module constant PHPModules\Demo\Config::DEFAULT_CACHE_TTL from outside its module
5. Loader::resolveParser() — internal method:
DENIED: Cannot call internal method PHPModules\Demo\Config::Loader::resolveParser() from outside its module
6. SupportedFormats — public enum:
Case: Json
Match: JSON
=== Demo Complete ===
*/