1
|
|
|
<?php |
|
|
|
|
2
|
|
|
jRequire("../Query/Query.php"); |
3
|
|
|
jRequire("../File/File.php"); |
4
|
|
|
class Module { |
|
|
|
|
5
|
|
|
use Query { |
6
|
|
|
Query::__construct as private __queryConstruct; |
7
|
|
|
} |
8
|
|
|
use File { |
9
|
|
|
File::__construct as private __fileConstruct; |
10
|
|
|
} |
11
|
|
|
public $name; |
12
|
|
|
public $modules; |
13
|
|
|
public function __construct() { |
14
|
|
|
$this->name = get_class($this); |
15
|
|
|
$this->modules = []; |
16
|
|
|
$this->__queryConstruct(); |
17
|
|
|
$this->__fileConstruct(); |
18
|
|
|
} |
19
|
|
|
public function addModules( $_modules ) { |
20
|
|
|
if(!is_array($_modules)) |
21
|
|
|
throw new JException("Parameter must be an array."); |
22
|
|
|
foreach ($_modules as $value) |
23
|
|
|
$this->addModule($value); |
24
|
|
|
} |
25
|
|
|
public function addModule( $_module ) { |
26
|
|
|
if(!is_object($_module)) |
27
|
|
|
throw new JException("Parameter must be a object."); |
28
|
|
|
if(! is_subclass_of ($_module, "Module")) |
29
|
|
|
throw new JException("Parameter must be a object inherited from Module object."); |
30
|
|
|
$this->modules[$_module->name] = $_module; |
31
|
|
|
if($this->currentConnection) |
32
|
|
|
$this->modules[$_module->name]->addConnectionMan($this->currentConnection); |
33
|
|
|
} |
34
|
|
|
public function addConnectionMan( $_connection, $_name = "default") { |
35
|
|
|
try { |
36
|
|
|
parent::addConnectionMan($_connection, $_name); |
37
|
|
|
foreach ($this->modules as &$module) |
38
|
|
|
if(isset($this->currentConnection)) |
39
|
|
|
$module->addConnectionMan($this->currentConnection, $_name); |
40
|
|
|
} catch (Exception $e) { |
41
|
|
|
throw new JException($e->getMessage(), 1); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
?> |
|
|
|
|
46
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.