1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace samsonphp\core\loader\module; |
4
|
|
|
|
5
|
|
|
use samsonframework\container\ContainerConfigurableInterface; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Module |
9
|
|
|
* |
10
|
|
|
* @package samsonphp\core\loader\module |
11
|
|
|
*/ |
12
|
|
|
class Module |
13
|
|
|
{ |
14
|
|
|
/** @var string Interface which mark as class configure the module */ |
15
|
|
|
public static $containerConfigurableInterface = ContainerConfigurableInterface::class; |
16
|
|
|
|
17
|
|
|
/** @var string Module name */ |
18
|
|
|
public $name; |
19
|
|
|
/** @var string Module class name */ |
20
|
|
|
public $className; |
21
|
|
|
/** @var string Module path name */ |
22
|
|
|
public $pathName; |
23
|
|
|
/** @var string Module path */ |
24
|
|
|
public $path; |
25
|
|
|
/** @var array List of classes */ |
26
|
|
|
public $classes = []; |
27
|
|
|
/** @var bool Is module has custom dependency injection configurator */ |
28
|
|
|
public $isContainerConfigurable = false; |
29
|
|
|
/** @var string Configure dependency injection class */ |
30
|
|
|
public $containerConfigurableClassName; |
31
|
|
|
public $composerParameters; |
32
|
|
|
|
33
|
|
|
public function __construct($name, $path, $classes) |
34
|
|
|
{ |
35
|
|
|
$this->name = $name; |
36
|
|
|
$this->path = $path; |
37
|
|
|
$this->classes = $classes; |
38
|
|
|
|
39
|
|
|
// $this->requireClasses(); |
40
|
|
|
// $this->checkIsContainerConfigurable(); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Require module classes |
45
|
|
|
*/ |
46
|
|
|
protected function requireClasses() |
47
|
|
|
{ |
48
|
|
|
foreach ($this->classes as $classPath => $className) { |
|
|
|
|
49
|
|
|
|
50
|
|
|
$className = '\\' . ltrim($className, '\\'); |
51
|
|
|
// if (preg_match('/dbQuery/', $className)) { |
52
|
|
|
// trace('sdf'); |
53
|
|
|
// } |
54
|
|
|
if (file_exists($classPath) |
55
|
|
|
&& !preg_match('/\/api\/generated\//', $className) |
56
|
|
|
&& !preg_match('/activerecord\/dbQuery/', $className) |
57
|
|
|
&& !preg_match('/samson\/activerecord\//', $className) |
58
|
|
|
&& !preg_match('/Field.php$/', $classPath) |
59
|
|
|
&& !preg_match('/Navigation.php$/', $classPath) |
60
|
|
|
&& !preg_match('/TableVirtualCollection.php$/', $classPath) |
61
|
|
|
&& !preg_match('/TableVirtualEntity.php$/', $classPath) |
62
|
|
|
&& !preg_match('/TableVirtualQuery.php$/', $classPath) |
63
|
|
|
&& !class_exists($className) |
64
|
|
|
) { |
65
|
|
|
require_once($classPath); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Check if class configures the container |
72
|
|
|
*/ |
73
|
|
|
public function checkIsContainerConfigurable() |
74
|
|
|
{ |
75
|
|
|
// Find class with correct interface |
76
|
|
|
foreach ($this->classes as $classPath => $className) { |
77
|
|
|
$reflectionClass = new \ReflectionClass($className); |
78
|
|
|
// If class implements correct interface then it is container configurable |
79
|
|
|
if (in_array($this::$containerConfigurableInterface, $reflectionClass->getInterfaceNames(), true)) { |
80
|
|
|
$this->isContainerConfigurable = true; |
81
|
|
|
$this->containerConfigurableClassName = $className; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|