Skip to content

Commit f2cd735

Browse files
committed
Removing ORM specific code out of QueryTrait
1 parent 06d6343 commit f2cd735

File tree

3 files changed

+38
-17
lines changed

3 files changed

+38
-17
lines changed

src/Datasource/QueryCacher.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@
2222
/**
2323
* Handles caching queries and loading results from the cache.
2424
*
25-
* Used by Cake\ORM\Query internally.
25+
* Used by Cake\Datasource\QueryTrait internally.
2626
*
27-
* @see Cake\ORM\Query::cache() for the public interface.
27+
* @see Cake\Datasource\QueryTrait::cache() for the public interface.
2828
*/
2929
class QueryCacher {
3030

src/Datasource/QueryTrait.php

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ trait QueryTrait {
4040
*
4141
* When set, query execution will be bypassed.
4242
*
43-
* @var Cake\ORM\ResultSet
43+
* @var \Cake\Datasource\ResultSetDecorator
4444
* @see setResult()
4545
*/
4646
protected $_results;
@@ -186,13 +186,9 @@ public function getResults() {
186186
* When using a function, this query instance will be supplied as an argument.
187187
* @param string|CacheEngine $config Either the name of the cache config to use, or
188188
* a cache config instance.
189-
* @return Query The query instance.
190-
* @throws \RuntimeException When you attempt to cache a non-select query.
189+
* @return QueryTrait This same object
191190
*/
192191
public function cache($key, $config = 'default') {
193-
if ($this->_type !== 'select' && $this->_type !== null) {
194-
throw new \RuntimeException('You cannot cache the results of non-select queries.');
195-
}
196192
if ($key === false) {
197193
$this->_cache = null;
198194
return $this;
@@ -205,20 +201,15 @@ public function cache($key, $config = 'default') {
205201
* Fetch the results for this query.
206202
*
207203
* Compiles the SQL representation of this query and executes it using the
208-
* provided connection object. Returns a ResultSet iterator object.
204+
* provided connection object. Returns a ResultSetDecorator iterator object.
209205
*
210-
* ResultSet is a travesable object that implements the methods found
206+
* ResultSetDecorator is a travesable object that implements the methods found
211207
* on Cake\Collection\Collection.
212208
*
213-
* @return Cake\ORM\ResultCollectionTrait
209+
* @return Cake\ORM\ResultSetDecorator
214210
* @throws RuntimeException if this method is called on a non-select Query.
215211
*/
216212
public function all() {
217-
if ($this->_type !== 'select' && $this->_type !== null) {
218-
throw new \RuntimeException(
219-
'You cannot call all() on a non-select query. Use execute() instead.'
220-
);
221-
}
222213
return $this->getResults();
223214
}
224215

src/ORM/Query.php

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@
2828
*/
2929
class Query extends DatabaseQuery {
3030

31-
use QueryTrait;
31+
use QueryTrait {
32+
cache as private _cache;
33+
all as private _all;
34+
}
3235

3336
/**
3437
* Indicates that the operation should append to the list
@@ -553,6 +556,33 @@ public function hydrate($enable = null) {
553556
return $this;
554557
}
555558

559+
/**
560+
* {@inheritdoc}
561+
*
562+
* @return Query The query instance.
563+
* @throws \RuntimeException When you attempt to cache a non-select query.
564+
*/
565+
public function cache($key, $config = 'default') {
566+
if ($this->_type !== 'select' && $this->_type !== null) {
567+
throw new \RuntimeException('You cannot cache the results of non-select queries.');
568+
}
569+
return $this->_cache($key, $config);
570+
}
571+
572+
/**
573+
* {@inheritdoc}
574+
*
575+
* @throws RuntimeException if this method is called on a non-select Query.
576+
*/
577+
public function all() {
578+
if ($this->_type !== 'select' && $this->_type !== null) {
579+
throw new \RuntimeException(
580+
'You cannot call all() on a non-select query. Use execute() instead.'
581+
);
582+
}
583+
return $this->_all();
584+
}
585+
556586
/**
557587
* Auxiliary function used to wrap the original statement from the driver with
558588
* any registered callbacks. This will also setup the correct statement class

0 commit comments

Comments
 (0)