|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Classes\AdapterMakerFile; |
|
4
|
|
|
|
|
5
|
|
|
/** |
|
6
|
|
|
* @author Pedro Alarcao <[email protected]> |
|
7
|
|
|
* @link https://github.com/pedro151/orm-generator |
|
8
|
|
|
*/ |
|
9
|
|
|
abstract class AbstractAdapter |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* @type AbstractAdapter[] |
|
13
|
|
|
*/ |
|
14
|
|
|
private static $_instance = array (); |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @type FilesFixeds[] |
|
18
|
|
|
*/ |
|
19
|
|
|
private $instanceFixedFile = array (); |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @param \Classes\MakerFile $makerFile |
|
23
|
|
|
* @param \Classes\Db\DbTable $dbTable |
|
24
|
|
|
* |
|
25
|
|
|
* @return array |
|
26
|
|
|
*/ |
|
27
|
|
|
abstract public function parseRelation ( \Classes\MakerFile $makerFile , \Classes\Db\DbTable $dbTable ); |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @type string nome do arquivo template |
|
31
|
|
|
*/ |
|
32
|
|
|
protected $fileTpl; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @type string |
|
36
|
|
|
*/ |
|
37
|
|
|
protected $pastName; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* nome do arquivo template e nome das classes fixas |
|
41
|
|
|
* |
|
42
|
|
|
* @type string[][] |
|
43
|
|
|
*/ |
|
44
|
|
|
protected $fileFixedData = array (); |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @var bool |
|
48
|
|
|
*/ |
|
49
|
|
|
protected $overwrite = false; |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* |
|
53
|
|
|
*/ |
|
54
|
|
|
final private function __construct () |
|
55
|
|
|
{ |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return \Classes\AdapterMakerFile\AbstractAdapter |
|
60
|
|
|
*/ |
|
61
|
|
|
public static function getInstance () |
|
62
|
|
|
{ |
|
63
|
|
|
$class = get_called_class (); |
|
64
|
|
|
if ( ! isset( self::$_instance[ $class ] ) ) |
|
65
|
|
|
{ |
|
66
|
|
|
self::$_instance[ $class ] = new $class(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
return self::$_instance[ $class ]; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* verifica se existe diretorio nesta makeFile |
|
74
|
|
|
* |
|
75
|
|
|
* @return bool |
|
76
|
|
|
*/ |
|
77
|
|
|
public function hasDiretory () |
|
78
|
|
|
{ |
|
79
|
|
|
return ! empty( $this->pastName ); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* @return \Classes\AdapterMakerFile\FilesFixeds |
|
84
|
|
|
*/ |
|
85
|
|
|
public function getFilesFixeds ( $key ) |
|
86
|
|
|
{ |
|
87
|
|
|
$key = strtolower($key); |
|
88
|
|
|
if ( ! isset( $this->fileFixedData[ $key ] ) ) |
|
89
|
|
|
{ |
|
90
|
|
|
throw new \Exception( 'Não existe dados para popular o FilesFixeds ' . $key ); |
|
91
|
|
|
} |
|
92
|
|
|
|
|
93
|
|
|
if ( !isset($this->instanceFixedFile[ $key ]) or ! $this->instanceFixedFile[ $key ] instanceof FilesFixeds ) |
|
|
|
|
|
|
94
|
|
|
{ |
|
95
|
|
|
$this->instanceFixedFile[ $key ] = FilesFixeds::getInstance ( $this->fileFixedData[ $key ] ); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
return $this->instanceFixedFile[ $key ]; |
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* verifica se existe arquivo de exeção |
|
103
|
|
|
* |
|
104
|
|
|
* @return bool |
|
105
|
|
|
*/ |
|
106
|
|
|
public function hasFilesFixeds ( $key ) |
|
107
|
|
|
{ |
|
108
|
|
|
return $this->getFilesFixeds ( strtolower($key) )->hasData (); |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* retorna a lista de possiveis objetos |
|
113
|
|
|
* |
|
114
|
|
|
* @return array |
|
115
|
|
|
*/ |
|
116
|
|
|
public function getListFilesFixed () |
|
117
|
|
|
{ |
|
118
|
|
|
return \array_keys ( $this->fileFixedData ); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @return string |
|
123
|
|
|
*/ |
|
124
|
|
|
public function getFileTpl () |
|
125
|
|
|
{ |
|
126
|
|
|
return $this->fileTpl; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
/** |
|
130
|
|
|
* @return string |
|
131
|
|
|
*/ |
|
132
|
|
|
public function getPastName () |
|
133
|
|
|
{ |
|
134
|
|
|
return $this->pastName; |
|
135
|
|
|
} |
|
136
|
|
|
|
|
137
|
|
|
/** |
|
138
|
|
|
* @return bool |
|
139
|
|
|
*/ |
|
140
|
|
|
public function isOverwrite () |
|
141
|
|
|
{ |
|
142
|
|
|
return $this->overwrite; |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
} |
|
146
|
|
|
|
PHP has two types of connecting operators (logical operators, and boolean operators):
and&&or||The difference between these is the order in which they are executed. In most cases, you would want to use a boolean operator like
&&, or||.Let’s take a look at a few examples:
Logical Operators are used for Control-Flow
One case where you explicitly want to use logical operators is for control-flow such as this:
Since
dieintroduces problems of its own, f.e. it makes our code hardly testable, and prevents any kind of more sophisticated error handling; you probably do not want to use this in real-world code. Unfortunately, logical operators cannot be combined withthrowat this point:These limitations lead to logical operators rarely being of use in current PHP code.