From 50816e2af9b752a2d2941906606800b8580f5943 Mon Sep 17 00:00:00 2001 From: mark_story Date: Wed, 17 Jun 2015 13:36:33 -0400 Subject: [PATCH] Typehint against the interface. Typehinting against an implementation is generally not a good idea. --- src/ORM/ResultSet.php | 3 ++- src/View/Form/EntityContext.php | 16 ++++++++-------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/ORM/ResultSet.php b/src/ORM/ResultSet.php index dff7ca9aae1..31cada50e16 100644 --- a/src/ORM/ResultSet.php +++ b/src/ORM/ResultSet.php @@ -19,6 +19,7 @@ use Cake\Database\Exception; use Cake\Database\Type; use Cake\Datasource\ResultSetInterface; +use Cake\Datasource\EntityInterface; use SplFixedArray; /** @@ -589,7 +590,7 @@ protected function _groupResult($row) if (isset($results[$defaultAlias])) { $results = $results[$defaultAlias]; } - if ($this->_hydrate && !($results instanceof Entity)) { + if ($this->_hydrate && !($results instanceof EntityInterface)) { $results = new $this->_entityClass($results, $options); } diff --git a/src/View/Form/EntityContext.php b/src/View/Form/EntityContext.php index e95d94408a8..69a18e29662 100644 --- a/src/View/Form/EntityContext.php +++ b/src/View/Form/EntityContext.php @@ -15,8 +15,8 @@ namespace Cake\View\Form; use Cake\Collection\Collection; +use Cake\Datasource\EntityInterface; use Cake\Network\Request; -use Cake\ORM\Entity; use Cake\ORM\TableRegistry; use Cake\Utility\Inflector; use Cake\View\Form\ContextInterface; @@ -123,7 +123,7 @@ protected function _prepare() if (is_array($entity) || $entity instanceof Traversable) { $entity = (new Collection($entity))->first(); } - $isEntity = $entity instanceof Entity; + $isEntity = $entity instanceof EntityInterface; if ($isEntity) { $table = $entity->source(); @@ -190,7 +190,7 @@ public function isCreate() if (is_array($entity) || $entity instanceof Traversable) { $entity = (new Collection($entity))->first(); } - if ($entity instanceof Entity) { + if ($entity instanceof EntityInterface) { return $entity->isNew() !== false; } return true; @@ -220,7 +220,7 @@ public function val($field) return $this->_extractMultiple($entity, $parts); } - if ($entity instanceof Entity) { + if ($entity instanceof EntityInterface) { return $entity->get(array_pop($parts)); } return null; @@ -290,7 +290,7 @@ public function entity($path = null) $isTraversable = ( is_array($next) || $next instanceof Traversable || - $next instanceof Entity + $next instanceof EntityInterface ); if ($isLast || !$isTraversable) { return $entity; @@ -315,7 +315,7 @@ protected function _getProp($target, $field) if (is_array($target) && isset($target[$field])) { return $target[$field]; } - if ($target instanceof Entity) { + if ($target instanceof EntityInterface) { return $target->get($field); } if ($target instanceof Traversable) { @@ -340,7 +340,7 @@ public function isRequired($field) $entity = $this->entity($parts); $isNew = true; - if ($entity instanceof Entity) { + if ($entity instanceof EntityInterface) { $isNew = $entity->isNew(); } @@ -496,7 +496,7 @@ public function error($field) $parts = explode('.', $field); $entity = $this->entity($parts); - if ($entity instanceof Entity) { + if ($entity instanceof EntityInterface) { return $entity->errors(array_pop($parts)); } return [];