1 | <?php |
||
16 | trait Executable |
||
17 | { |
||
18 | /** |
||
19 | * @var PDO |
||
20 | */ |
||
21 | protected $pdo; |
||
22 | |||
23 | /** |
||
24 | * @var int |
||
25 | */ |
||
26 | protected $rowCount; |
||
27 | |||
28 | /** |
||
29 | * Sets the PDO instance used by this query. |
||
30 | * |
||
31 | * @param PDO $pdo |
||
32 | * |
||
33 | * @return self |
||
34 | */ |
||
35 | public function setPDO(PDO $pdo) |
||
41 | |||
42 | /** |
||
43 | * Gets the PDO instance used by this query. |
||
44 | * |
||
45 | * @return PDO |
||
46 | */ |
||
47 | public function getPDO() |
||
51 | |||
52 | /** |
||
53 | * Executes a query. |
||
54 | * |
||
55 | * @return \PDOStatement|bool result |
||
56 | */ |
||
57 | public function execute() |
||
69 | |||
70 | /** |
||
71 | * Returns the number of rows affected by the last executed statement. |
||
72 | * |
||
73 | * @return int |
||
74 | */ |
||
75 | public function rowCount() |
||
79 | |||
80 | /** |
||
81 | * Starts a transaction. |
||
82 | * |
||
83 | * @return bool |
||
84 | */ |
||
85 | public function beginTransaction() |
||
89 | |||
90 | /** |
||
91 | * Commits the transaction. |
||
92 | * |
||
93 | * @return bool |
||
94 | */ |
||
95 | public function commit() |
||
99 | |||
100 | /** |
||
101 | * Rolls back the transaction. |
||
102 | * |
||
103 | * @return bool |
||
104 | */ |
||
105 | public function rollBack() |
||
109 | |||
110 | /** |
||
111 | * Checks if the query is in a transaction. |
||
112 | * |
||
113 | * @return bool |
||
114 | */ |
||
115 | public function inTransaction() |
||
119 | } |
||
120 |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.