1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace HexMakina\LeMarchand; |
4
|
|
|
|
5
|
|
|
use Psr\Container\ContainerInterface; |
6
|
|
|
use Psr\Container\ContainerExceptionInterface; |
7
|
|
|
use Psr\Container\NotFoundExceptionInterface; |
8
|
|
|
|
9
|
|
|
class Configuration |
10
|
|
|
{ |
11
|
|
|
public const RX_SETTINGS = '/^settings\./'; |
12
|
|
|
|
13
|
|
|
public const RX_INTERFACE = '/([a-zA-Z]+)Interface$/'; |
14
|
|
|
|
15
|
|
|
public const RX_MVC = '/(Models|Controllers)\\\([a-zA-Z\\\]+)(::class|::new)?$/'; |
16
|
|
|
|
17
|
|
|
|
18
|
|
|
private $lament; |
19
|
|
|
private ContainerInterface $box; |
20
|
|
|
|
21
|
|
|
public function __construct($id, ContainerInterface $c) |
22
|
|
|
{ |
23
|
|
|
$this->lament = $id; |
24
|
|
|
$this->box = $c; |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function __toString() |
28
|
|
|
{ |
29
|
|
|
return $this->lament; |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function id(): string |
33
|
|
|
{ |
34
|
|
|
return $this->lament; |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
public function container(): ContainerInterface |
38
|
|
|
{ |
39
|
|
|
return $this->box; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function isSettings(): bool |
43
|
|
|
{ |
44
|
|
|
return preg_match(self::RX_SETTINGS, $this->lament) === 1; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function isExistingClass(): bool |
48
|
|
|
{ |
49
|
|
|
return class_exists($this->lament); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function isInterface(): bool |
53
|
|
|
{ |
54
|
|
|
return preg_match(self::RX_INTERFACE, $this->lament) === 1; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function rxModelOrController(): ?string |
58
|
|
|
{ |
59
|
|
|
$ret = null; |
60
|
|
|
|
61
|
|
|
$m = []; |
62
|
|
|
if (preg_match(self::RX_MVC, $this->lament, $m) === 1) { |
63
|
|
|
$ret = $m[1] . '\\' . $m[2]; |
64
|
|
|
} else { |
65
|
|
|
} |
66
|
|
|
return $ret; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
public function hasClassNameModifier() |
70
|
|
|
{ |
71
|
|
|
return strpos($this->lament, '::class') !== false; |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
public function hasNewInstanceModifier() |
75
|
|
|
{ |
76
|
|
|
return strpos($this->lament, '::new') !== false; |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|