Skip to content
Permalink
Browse files

Disallowing the use of batching in userland type classes extending Type

This is to avoid breaking backwards compatibility.
  • Loading branch information...
lorenzo committed Mar 4, 2018
1 parent 467d54b commit 6775312b07ccdafce95342e2788865bc4d0f77eb
Showing with 17 additions and 2 deletions.
  1. +17 −1 src/Database/FieldTypeConverter.php
  2. +0 −1 src/Database/Query.php
@@ -14,6 +14,7 @@
*/
namespace Cake\Database;
use Cake\Database\Type;
use Cake\Database\Type\BatchCastingInterface;
use Cake\Database\Type\OptionalConvertInterface;
@@ -40,6 +41,13 @@ class FieldTypeConverter
*/
protected $batchingTypeMap;
/**
* An array containing all the types registered in the Type system
* at the moment this object is created. Used so that the types list
* is not fetched on each single row of the results.
*
* @var array
*/
protected $types;
/**
@@ -69,7 +77,15 @@ public function __construct(TypeMap $typeMap, Driver $driver)
continue;
}
if ($type instanceof BatchCastingInterface) {
// Because of backwards compatibility reasons, we won't allow classes
// inheriting Type in userland code to be batchable, even if they implement
// the interface. Users can implement the TypeInterface instead to have
// access to this feature.
$batchingType = $type instanceof BatchCastingInterface &&
$type instanceof Type &&
strpos(get_class($type), 'Cake\Database\Type') === false;
if ($batchingType) {
$batchingMap[$k] = $type;
continue;
}
@@ -2094,7 +2094,6 @@ protected function _decorateStatement($statement)
$driver = $this->getConnection()->getDriver();
if ($this->typeCastEnabled && $typeMap->toArray()) {
$driver = $this->_connection->getDriver();
$statement = new CallbackStatement($statement, $driver, new FieldTypeConverter($typeMap, $driver));
}

0 comments on commit 6775312

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