1 | <?php |
||
15 | class CacheableQuery extends Query |
||
16 | { |
||
17 | use ArrayableTrait; |
||
18 | |||
19 | /** |
||
20 | * @var array|null The cached query result |
||
21 | * @see setCachedResult() |
||
22 | */ |
||
23 | private $result; |
||
24 | |||
25 | /** |
||
26 | * @var array|null The criteria params that were set when the cached query result was set |
||
27 | * @see setCachedResult() |
||
28 | */ |
||
29 | private $resultCriteria; |
||
30 | |||
31 | /** |
||
32 | * @inheritdoc |
||
33 | */ |
||
34 | public function count($q = '*', $db = null) |
||
43 | |||
44 | /** |
||
45 | * @inheritdoc |
||
46 | */ |
||
47 | public function all($db = null) |
||
56 | |||
57 | /** |
||
58 | * @inheritdoc |
||
59 | */ |
||
60 | public function one($db = null) |
||
70 | |||
71 | /** |
||
72 | * Executes the query and returns a single row of result at a given offset. |
||
73 | * |
||
74 | * @param int $n The offset of the row to return. If [[offset]] is set, $offset will be added to it. |
||
75 | * @param Connection|null $db The database connection used to generate the SQL statement. |
||
76 | * If this parameter is not given, the `db` application component will be used. |
||
77 | * |
||
78 | * @return array|bool The object or row of the query result. False is returned if the query |
||
79 | * results in nothing. |
||
80 | */ |
||
81 | public function nth(int $n, Connection $db = null) |
||
90 | |||
91 | /** |
||
92 | * Returns the results set by [[setCachedResult()]], if the criteria params haven’t changed since then. |
||
93 | * |
||
94 | * @return array|null The results, or null if setCachedResult() was never called or the criteria has |
||
95 | * changed |
||
96 | * @see setCachedResult() |
||
97 | */ |
||
98 | public function getCachedResult() |
||
113 | |||
114 | /** |
||
115 | * Sets the results. |
||
116 | * |
||
117 | * If this is called, [[all()]] will return these domains rather than initiating a new SQL query, |
||
118 | * as long as none of the parameters have changed since setCachedResult() was called. |
||
119 | * |
||
120 | * @param array $objects The resulting objects. |
||
121 | * |
||
122 | * @see getCachedResult() |
||
123 | */ |
||
124 | public function setCachedResult(array $objects) |
||
129 | |||
130 | /** |
||
131 | * Clears the results. |
||
132 | * |
||
133 | * @see getCachedResult() |
||
134 | */ |
||
135 | public function clearCachedResult() |
||
140 | |||
141 | /** |
||
142 | * Returns an array of the current criteria attribute values. |
||
143 | * |
||
144 | * @return array |
||
145 | */ |
||
146 | public function getCriteria(): array |
||
150 | |||
151 | /** |
||
152 | * @noinspection PhpDocMissingThrowsInspection |
||
153 | * |
||
154 | * Returns the query's criteria attributes. |
||
155 | * |
||
156 | * @return string[] |
||
157 | */ |
||
158 | public function criteriaAttributes(): array |
||
178 | } |
||
179 |