|
1
|
|
|
<?php |
|
2
|
|
|
namespace src\pdoDataBase\select; |
|
3
|
|
|
|
|
4
|
|
|
use src\FactoryClassInterface; |
|
5
|
|
|
|
|
6
|
|
|
use src\pdoDatabase\select\{ |
|
7
|
|
|
Select, |
|
|
|
|
|
|
8
|
|
|
Tabla, |
|
|
|
|
|
|
9
|
|
|
Campos, |
|
|
|
|
|
|
10
|
|
|
Donde, |
|
|
|
|
|
|
11
|
|
|
Entre, |
|
|
|
|
|
|
12
|
|
|
Limite, |
|
|
|
|
|
|
13
|
|
|
Orden |
|
|
|
|
|
|
14
|
|
|
}; |
|
15
|
|
|
|
|
16
|
|
|
use src\pdoDataBase\consulta\{Consulta, Query, CrearConsulta}; |
|
17
|
|
|
|
|
18
|
|
|
use src\pdoDataBase\conexion\CrearConexionBaseDeDatos; |
|
19
|
|
|
|
|
20
|
|
|
class ConsultaConSelect implements FactoryClassInterface |
|
21
|
|
|
{ |
|
22
|
|
|
public function crear(array $array): Consulta |
|
23
|
|
|
{ |
|
24
|
|
|
$donde = new Donde( |
|
25
|
|
|
new MasDonde($this->masDonde($array)), |
|
26
|
|
|
$this->donde($array) |
|
27
|
|
|
); |
|
28
|
|
|
|
|
29
|
|
|
$select = new Select( |
|
30
|
|
|
new Tabla($array['tabla']), |
|
31
|
|
|
new Campos($this->campos($array)), |
|
32
|
|
|
$donde, |
|
33
|
|
|
new Entre($this->entre($array)), |
|
34
|
|
|
new Limite($this->limite($array)), |
|
35
|
|
|
new Orden($this->orden($array)) |
|
36
|
|
|
); |
|
37
|
|
|
|
|
38
|
|
|
$consulta = new CrearConsulta; |
|
39
|
|
|
$conexion = new CrearConexionBaseDeDatos; |
|
40
|
|
|
|
|
41
|
|
|
return $consulta->crear(array( |
|
42
|
|
|
$conexion->crear(array()), |
|
43
|
|
|
'sql' => $select->select(), |
|
44
|
|
|
'valores' => $donde->datos() |
|
45
|
|
|
)); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
private function campos(array $array): array |
|
49
|
|
|
{ |
|
50
|
|
|
if(isset($array['campos'])) |
|
51
|
|
|
{ |
|
52
|
|
|
return $array['campos']; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
return []; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
private function donde($array): array |
|
59
|
|
|
{ |
|
60
|
|
|
if(isset($array['donde'])) |
|
61
|
|
|
{ |
|
62
|
|
|
return $array['donde']; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
return []; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
private function masDonde($array): array |
|
69
|
|
|
{ |
|
70
|
|
|
if( is_array($this->donde($array)) && isset($array['masDonde']) ) |
|
71
|
|
|
{ |
|
72
|
|
|
return $array['masDonde']; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return []; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
private function entre(array $array): array |
|
79
|
|
|
{ |
|
80
|
|
|
if(isset($array['entre'])) |
|
81
|
|
|
{ |
|
82
|
|
|
return $array['entre']; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
return []; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
private function limite(array $array) |
|
89
|
|
|
{ |
|
90
|
|
|
if(isset($array['limite'])) |
|
91
|
|
|
{ |
|
92
|
|
|
return $array['limite']; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
private function orden(array $array) |
|
97
|
|
|
{ |
|
98
|
|
|
if(isset($array['orden'])) |
|
99
|
|
|
{ |
|
100
|
|
|
return $array['orden']; |
|
101
|
|
|
} |
|
102
|
|
|
} |
|
103
|
|
|
} |
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: