Skip to content
Permalink
Browse files

Adding a ResultSetInterface to standarize the result of a query

  • Loading branch information...
lorenzo committed Sep 23, 2014
1 parent edefed1 commit 0e4cc2396d476fccf44cd237edcb30dbfb2a3705

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -37,7 +37,7 @@ trait QueryTrait {
*
* When set, query execution will be bypassed.
*
* @var \Cake\Datasource\ResultSetDecorator
* @var \Cake\Datasource\ResultSetInterface
* @see setResult()
*/
protected $_results;
@@ -107,7 +107,7 @@ public function repository(RepositoryInterface $table = null) {
*
* This method is most useful when combined with results stored in a persistent cache.
*
* @param \Cake\ORM\ResultSet $results The results this query should return.
* @param \Cake\Datasource\ResultSetInterface $results The results this query should return.
* @return \Cake\ORM\Query The query instance.
*/
public function setResult($results) {
@@ -196,7 +196,7 @@ public function eagerLoaded($value = null) {
* ResultSetDecorator is a travesable object that implements the methods found
* on Cake\Collection\Collection.
*
* @return \Cake\DataSource\ResultSetDecorator
* @return \Cake\Datasource\ResultSetInterface
*/
public function all() {
if (isset($this->_results)) {
@@ -393,7 +393,7 @@ public function __call($method, $arguments) {
* Decorates the results iterator with MapReduce routines and formatters
*
* @param \Traversable $result Original results
* @return \Cake\Datasource\ResultSetDecorator
* @return \Cake\Datasource\ResultSetInterface
*/
protected function _decorateResults($result) {
$decorator = $this->_decoratorClass();
@@ -14,18 +14,16 @@
*/
namespace Cake\Datasource;
use Cake\Datasource\ResultSetInterface;
use Cake\Collection\Collection;
use Countable;
use JsonSerializable;
use Serializable;
/**
* Generic ResultSet decorator. This will make any traversable object appear to
* be a database result
*
* @return void
*/
class ResultSetDecorator extends Collection implements Countable, Serializable, JsonSerializable {
class ResultSetDecorator extends Collection implements ResultSetInterface {
/**
* Make this object countable.
@@ -0,0 +1,26 @@
<?php
/**
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* For full copyright and license information, please see the LICENSE.txt
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @since 3.0.0
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Cake\Datasource;
use Cake\Collection\CollectionInterface;
use Countable;
use Serializable;
/**
* Describes how a collection of datasource results should look like
*
*/
interface ResultSetInterface extends CollectionInterface, Countable, Serializable {
}
@@ -278,7 +278,7 @@ public function findTranslations(Query $query, array $options) {
* Modifies the results from a table find in order to merge the translated fields
* into each entity for a given locale.
*
* @param \Cake\DataSource\ResultSetDecorator $results Results to map.
* @param \Cake\Datasource\ResultSetInterface $results Results to map.
* @param string $locale Locale string
* @return \Cake\Collection\Collection
*/
@@ -318,7 +318,7 @@ protected function _rowMapper($results, $locale) {
* Modifies the results from a table find in order to merge full translation records
* into each entity under the `_translations` key
*
* @param \Cake\Datasource\ResultSetDecorator $results Results to modify.
* @param \Cake\Datasource\ResultSetInterface $results Results to modify.
* @return \Cake\Collection\Collection
*/
public function groupTranslations($results) {
@@ -782,7 +782,7 @@ public function __debugInfo() {
*
* Part of JsonSerializable interface.
*
* @return \Cake\ORM\ResultSet The data to convert to JSON.
* @return \Cake\Datasource\ResultSetInterface The data to convert to JSON.
*/
public function jsonSerialize() {
return $this->all();
@@ -809,7 +809,7 @@ public function autoFields($value = null) {
* Decorates the results iterator with MapReduce routines and formatters
*
* @param \Traversable $result Original results
* @return \Cake\Datasource\ResultSetDecorator
* @return \Cake\Datasource\ResultSetInterface
*/
protected function _decorateResults($result) {
$result = $this->_applyDecorators($result);
@@ -17,10 +17,8 @@
use Cake\Collection\CollectionTrait;
use Cake\Database\Exception;
use Cake\Database\Type;
use Countable;
use Iterator;
use Cake\Datasource\ResultSetInterface;
use JsonSerializable;
use Serializable;
use SplFixedArray;
/**
@@ -30,7 +28,7 @@
* queries required for eager loading external associations.
*
*/
class ResultSet implements Countable, Iterator, Serializable, JsonSerializable {
class ResultSet implements ResultSetInterface {
use CollectionTrait;
@@ -660,10 +660,10 @@ public function testPaginate() {
$this->assertArrayNotHasKey('Paginator', $Controller->helpers);
$results = $Controller->paginate('Posts');
$this->assertInstanceOf('Cake\Datasource\ResultSetDecorator', $results);
$this->assertInstanceOf('Cake\Datasource\ResultSetInterface', $results);
$results = $Controller->paginate(TableRegistry::get('Posts'));
$this->assertInstanceOf('Cake\Datasource\ResultSetDecorator', $results);
$this->assertInstanceOf('Cake\Datasource\ResultSetInterface', $results);
$this->assertSame($Controller->request->params['paging']['Posts']['page'], 1);
$this->assertSame($Controller->request->params['paging']['Posts']['pageCount'], 1);
@@ -686,7 +686,7 @@ public function testPaginateUsesModelClass() {
$Controller->modelClass = 'Posts';
$results = $Controller->paginate();
$this->assertInstanceOf('Cake\Datasource\ResultSetDecorator', $results);
$this->assertInstanceOf('Cake\Datasource\ResultSetInterface', $results);
}
/**
@@ -1541,7 +1541,7 @@ public function testCacheWriteIntegration() {
->method('write')
->with(
'my_key',
$this->isInstanceOf('Cake\Datasource\ResultSetDecorator')
$this->isInstanceOf('Cake\Datasource\ResultSetInterface')
);
$query->cache('my_key', $cacher)

0 comments on commit 0e4cc23

Please sign in to comment.
You can’t perform that action at this time.