1
|
|
|
<?php |
|
|
|
|
2
|
|
|
|
3
|
|
|
namespace Classes\AdapterConfig; |
4
|
|
|
|
5
|
|
|
use Classes\AdapterMakerFile\ZendFrameworkOne\DbTable; |
6
|
|
|
use Classes\AdapterMakerFile\ZendFrameworkOne\Entity; |
7
|
|
|
use Classes\AdapterMakerFile\ZendFrameworkOne\Model; |
8
|
|
|
use Classes\AdapterMakerFile\ZendFrameworkOne\Peer; |
9
|
|
|
|
10
|
|
|
require_once "Classes/AdapterConfig/AbstractAdapter.php"; |
11
|
|
|
require_once "Classes/AdapterMakerFile/ZendFrameworkOne/DbTable.php"; |
12
|
|
|
require_once "Classes/AdapterMakerFile/ZendFrameworkOne/Entity.php"; |
13
|
|
|
require_once "Classes/AdapterMakerFile/ZendFrameworkOne/Model.php"; |
14
|
|
|
require_once "Classes/AdapterMakerFile/ZendFrameworkOne/Peer.php"; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @author Pedro Alarcao <[email protected]> |
18
|
|
|
* @link https://github.com/pedro151/orm-generator |
19
|
|
|
*/ |
20
|
|
|
class ZendFrameworkOne extends AbstractAdapter |
21
|
|
|
{ |
22
|
|
|
|
23
|
|
|
private $config; |
24
|
|
|
|
25
|
|
|
const SEPARETOR = "_"; |
26
|
|
|
|
27
|
|
|
protected function init () |
28
|
|
|
{ |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* retorna os parametros da configuração do framework |
33
|
|
|
* |
34
|
|
|
* @return array |
35
|
|
|
*/ |
36
|
|
|
protected function getParams () |
37
|
|
|
{ |
38
|
|
|
if ( ! $this->config or ! $this->isValidFrameworkFiles () ) |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
return array (); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
return array ( |
44
|
|
|
//Driver do banco de dados |
45
|
|
|
'driver' => $this->config[ 'adapter' ] , |
46
|
|
|
//Nome do banco de dados |
47
|
|
|
'database' => $this->config[ 'params' ][ 'dbname' ] , |
48
|
|
|
//Host do banco |
49
|
|
|
'host' => $this->config[ 'params' ][ 'host' ] , |
50
|
|
|
//Port do banco |
51
|
|
|
'port' => isset( $this->config[ 'params' ][ 'port' ] ) |
52
|
|
|
? $this->config[ 'params' ][ 'port' ] : '' , |
53
|
|
|
//usuario do banco |
54
|
|
|
'username' => $this->config[ 'params' ][ 'username' ] , |
55
|
|
|
//senha do banco |
56
|
|
|
'password' => $this->config[ 'params' ][ 'password' ] , |
57
|
|
|
); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
protected function parseFrameworkConfig () |
61
|
|
|
{ |
62
|
|
|
if ( ! $this->isValidFrameworkFiles () ) |
63
|
|
|
{ |
64
|
|
|
return; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
$frameworkIni = $this->getFrameworkIni (); |
68
|
|
|
|
69
|
|
|
require_once 'Zend/Config/Ini.php'; |
70
|
|
|
|
71
|
|
|
$objConfig = new \Zend_Config_Ini( |
72
|
|
|
realpath ( $frameworkIni ) , $this->getEnvironment () |
73
|
|
|
); |
74
|
|
|
|
75
|
|
|
$arrConfig = $objConfig->toArray (); |
76
|
|
|
|
77
|
|
|
if ( isset( $arrConfig[ 'resources' ][ 'db' ] ) ) |
78
|
|
|
{ |
79
|
|
|
$this->config = $arrConfig[ 'resources' ][ 'db' ]; |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Cria Instancias dos arquivos que devem ser gerados |
85
|
|
|
* |
86
|
|
|
* @return \Classes\AdapterMakerFile\AbstractAdapter[] |
87
|
|
|
*/ |
88
|
|
|
public function getMakeFileInstances () |
89
|
|
|
{ |
90
|
|
|
|
91
|
|
|
$instances = array (); |
92
|
|
|
if ( $this->hasOptionalClasses () ) |
93
|
|
|
{ |
94
|
|
|
foreach ( $this->getOptionalClasses () as $optionalClass ) |
95
|
|
|
{ |
96
|
|
|
$Name = ucfirst ( $optionalClass ); |
97
|
|
|
$className = "Classes\\AdapterMakerFile\\ZendFrameworkOne\\{$Name}"; |
98
|
|
|
if(method_exists($className,'getInstance')){ |
99
|
|
|
$instances[] = $className::getInstance (); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
return array_merge ( array ( |
105
|
|
|
DbTable::getInstance () , |
106
|
|
|
Entity::getInstance () , |
107
|
|
|
Model::getInstance () |
108
|
|
|
) , $instances ); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
} |
112
|
|
|
|
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.