1 | <?php |
||
11 | class Scheme |
||
12 | { |
||
13 | /** Global/Default scheme marker */ |
||
14 | const BASE = 'global'; |
||
15 | |||
16 | /** Entity configuration file pattern */ |
||
17 | const ENTITY_PATTERN = '*Config.php'; |
||
18 | |||
19 | /** @var array Collection of file path -> class loaded */ |
||
20 | protected static $classes = array(); |
||
21 | |||
22 | /** @var string Current configuration environment */ |
||
23 | protected $environment; |
||
24 | |||
25 | /** @var array Configuration folder path array */ |
||
26 | protected $path = array(); |
||
27 | |||
28 | /** @var array Collection of module identifier => configurator class */ |
||
29 | public $entities = array(); |
||
30 | |||
31 | /** |
||
32 | * Create configuration instance. |
||
33 | * |
||
34 | * All module configurators must be stored within configuration base path, |
||
35 | * by default this is stored in __SAMSON_CONFIG_PATH constant. |
||
36 | * |
||
37 | * Every environment configuration must be stored in sub-folder with the name of this |
||
38 | * environment within base configuration folder. |
||
39 | * |
||
40 | * Configurators located at base root configuration folder considered as generic |
||
41 | * module configurators. |
||
42 | * |
||
43 | * @param string $path Base path to configuration root folder |
||
44 | * @param string $environment Configuration environment name |
||
45 | */ |
||
46 | public function __construct($path, $environment) |
||
57 | |||
58 | /** |
||
59 | * Load entity configuration classes for this scheme. |
||
60 | * Function scans all required classes and matches them by |
||
61 | * specified scheme path. |
||
62 | */ |
||
63 | public function load($path = null) |
||
83 | |||
84 | /** |
||
85 | * Convert entity configuration or object class name to identifier |
||
86 | * @param string $class Entity configuration class name |
||
87 | * @return string Entity real class name |
||
88 | */ |
||
89 | public function identifier($class) |
||
99 | |||
100 | /** |
||
101 | * Retrieve entity configuration by identifier. |
||
102 | * If entity configuration not found null will be |
||
103 | * returned. |
||
104 | * |
||
105 | * @param string $identifier Entity identifier |
||
106 | * @param mixed $entity Return found entity configuration pointer |
||
107 | * @return Entity|boolean Entity configuration pointer or bool |
||
108 | */ |
||
109 | public function & entity($identifier, & $entity = null) |
||
123 | |||
124 | /** |
||
125 | * Perform object configuration with specific entity |
||
126 | * @param mixed $object Object instance pointer |
||
127 | * @param Entity $entity Entity configuration pointer |
||
128 | * @param mixed $params Collection of parameters |
||
129 | * @return bool True if everything went fine, otherwise false |
||
130 | */ |
||
131 | protected function handleConfigure(& $object, Entity & $entity, $params = null) |
||
141 | |||
142 | /** |
||
143 | * Configure object with configuration entity parameters. |
||
144 | * |
||
145 | * If now $identifier is passed - automatic identifier generation |
||
146 | * will take place from object class name. |
||
147 | * |
||
148 | * If additional parameters key=>value collection is passed, they |
||
149 | * will be used to configure object instead of entity configuration |
||
150 | * class. |
||
151 | * |
||
152 | * @param mixed $object Object for configuration with entity |
||
153 | * @param string $identifier Configuration entity name |
||
154 | * @param array|null $params Collection of configuration parameters |
||
155 | * |
||
156 | * @return boolean True if we have successfully configured object |
||
157 | */ |
||
158 | public function configure(& $object, $identifier = null, $params = null) |
||
179 | } |
||
180 |