1 | <?php |
||
27 | class DBQuery{ |
||
28 | |||
29 | const DIALECTS = [ |
||
30 | 'mysql' => 'MySQL', |
||
31 | 'pgsql' => 'Postgres', |
||
32 | 'sqlite' => 'SQLite', |
||
33 | 'firebird' => 'Firebird', |
||
34 | ]; |
||
35 | |||
36 | /** |
||
37 | * @var \chillerlan\Database\Drivers\DBDriverInterface |
||
38 | */ |
||
39 | protected $DBDriver; |
||
40 | |||
41 | /** |
||
42 | * @var string |
||
43 | */ |
||
44 | protected $dialect; |
||
45 | |||
46 | /** |
||
47 | * DBQuery constructor. |
||
48 | * |
||
49 | * @param \chillerlan\Database\Drivers\DBDriverInterface $DBDriver |
||
50 | */ |
||
51 | public function __construct(DBDriverInterface $DBDriver){ |
||
52 | $this->DBDriver = $DBDriver; |
||
53 | |||
54 | $this->dialect = __NAMESPACE__.'\\Query\\Dialects\\'.self::DIALECTS[$this->DBDriver->dialect]; |
||
|
|||
55 | } |
||
56 | |||
57 | /** |
||
58 | * @param string $name |
||
59 | * |
||
60 | * @return \chillerlan\Database\Query\StatementInterface|null |
||
61 | */ |
||
62 | public function __get(string $name){ |
||
63 | $name = strtolower($name); |
||
64 | |||
65 | if(in_array($name, ['select', 'insert', 'update', 'delete'])){ |
||
66 | $class = $this->dialect.'\\'.ucfirst($name); |
||
67 | return new $class($this->DBDriver, $this->dialect); |
||
68 | } |
||
69 | elseif($name === 'create'){ |
||
70 | |||
71 | return new class($this->DBDriver, $this->dialect) extends StatementAbstract implements CreateInterface{ |
||
72 | |||
73 | public function database(string $dbname = null):CreateDatabaseInterface{ |
||
76 | |||
77 | public function table(string $tablename = null):CreateTableInterface{ |
||
80 | |||
81 | public function index():CreateInterface{ |
||
84 | |||
85 | public function view():CreateInterface{ |
||
88 | |||
89 | public function trigger():CreateInterface{ |
||
92 | }; |
||
93 | |||
98 | |||
99 | } |
||
100 |
If you access a property on an interface, you most likely code against a concrete implementation of the interface.
Available Fixes
Adding an additional type check:
Changing the type hint: