1 | <?php |
||
32 | class DBQuery{ |
||
33 | |||
34 | const DIALECTS = [ |
||
35 | 'mysql' => 'MySQL', |
||
36 | 'pgsql' => 'Postgres', |
||
37 | 'sqlite' => 'SQLite', |
||
38 | 'firebird' => 'Firebird', |
||
39 | ]; |
||
40 | |||
41 | /** |
||
42 | * @var \chillerlan\Database\Drivers\DBDriverInterface |
||
43 | */ |
||
44 | protected $DBDriver; |
||
45 | |||
46 | /** |
||
47 | * @var string |
||
48 | */ |
||
49 | protected $dialect; |
||
50 | |||
51 | /** |
||
52 | * DBQuery constructor. |
||
53 | * |
||
54 | * @param \chillerlan\Database\Drivers\DBDriverInterface $DBDriver |
||
55 | */ |
||
56 | public function __construct(DBDriverInterface $DBDriver){ |
||
57 | $this->DBDriver = $DBDriver; |
||
58 | |||
59 | $this->dialect = __NAMESPACE__.'\\Query\\Dialects\\'.self::DIALECTS[$this->DBDriver->dialect]; |
||
|
|||
60 | |||
61 | mb_internal_encoding('UTF-8'); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * @param string $name |
||
66 | * |
||
67 | * @return \chillerlan\Database\Query\StatementInterface|null |
||
68 | */ |
||
69 | public function __get(string $name){ |
||
70 | $name = strtolower($name); |
||
71 | |||
72 | if(in_array($name, ['select', 'insert', 'update', 'delete'])){ |
||
73 | $class = $this->dialect.'\\'.ucfirst($name); |
||
74 | return new $class($this->DBDriver, $this->dialect); |
||
75 | } |
||
76 | elseif($name === 'create'){ |
||
77 | |||
78 | return new class($this->DBDriver, $this->dialect) extends StatementAbstract implements CreateInterface{ |
||
79 | |||
80 | public function database(string $dbname = null):CreateDatabaseInterface{ |
||
83 | |||
84 | public function table(string $tablename = null):CreateTableInterface{ |
||
87 | |||
88 | # public function index():CreateInterface{} |
||
112 | |||
113 | } |
||
114 |
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: