Browse Source

Move RecordNotFoundException to Datasource.

Also move findOrFail() into QueryTrait so it can be used in other
queryable implementations.
mark_story 11 years ago
parent
commit
a6ac63aad3

+ 1 - 0
config/bootstrap.php

@@ -19,6 +19,7 @@ define('TIME_START', microtime(true));
 class_alias('Cake\Error\Debugger', 'Cake\Utility\Debugger');
 class_alias('Cake\Core\Configure\Engine\PhpConfig', 'Cake\Configure\Engine\PhpConfig');
 class_alias('Cake\Core\Configure\Engine\IniConfig', 'Cake\Configure\Engine\IniConfig');
+class_alias('Cake\Datasource\Exception\RecordNotFoundException', 'Cake\ORM\Exception\RecordNotFoundException');
 class_alias('Cake\ORM\Exception\RecordNotFoundException', 'Cake\ORM\Error\RecordNotFoundException');
 class_alias('Cake\Network\Exception\BadRequestException', 'Cake\Error\BadRequestException');
 class_alias('Cake\Network\Exception\ForbiddenException', 'Cake\Error\ForbiddenException');

+ 1 - 1
src/ORM/Exception/RecordNotFoundException.php

@@ -12,7 +12,7 @@
  * @since         3.0.0
  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
  */
-namespace Cake\ORM\Exception;
+namespace Cake\Datasource\Exception;
 
 use RuntimeException;
 

+ 18 - 0
src/Datasource/QueryTrait.php

@@ -15,6 +15,7 @@
 namespace Cake\Datasource;
 
 use Cake\Collection\Iterator\MapReduce;
+use Cake\Datasource\Exception\RecordNotFoundException;
 use Cake\Datasource\QueryCacher;
 use Cake\Datasource\RepositoryInterface;
 
@@ -329,6 +330,23 @@ trait QueryTrait {
 	}
 
 /**
+ * Get the first result from the executing query or raise an exception.
+ *
+ * @throws \Cake\Datasource\RecordNotFoundException When there is no first record.
+ * @return mixed The first result from the ResultSet.
+ */
+	public function firstOrFail() {
+		$entity = $this->first();
+		if ($entity) {
+			return $entity;
+		}
+		throw new RecordNotFoundException(sprintf(
+			'Record not found in table "%s"',
+			$this->repository()->table()
+		));
+	}
+
+/**
  * Returns an array with the custom options that were applied to this query
  * and that were not already processed by another method in this class.
  *

+ 0 - 17
src/ORM/Query.php

@@ -837,23 +837,6 @@ class Query extends DatabaseQuery implements JsonSerializable {
 	}
 
 /**
- * Get the first result from the executing query or raise an exception.
- *
- * @throws \Cake\ORM\RecordNotFoundException When there is no first record.
- * @return mixed The first result from the ResultSet.
- */
-	public function firstOrFail() {
-		$entity = $this->first();
-		if ($entity) {
-			return $entity;
-		}
-		throw new RecordNotFoundException(sprintf(
-			'Record not found in table "%s"',
-			$this->repository()->table()
-		));
-	}
-
-/**
  * Decorates the results iterator with MapReduce routines and formatters
  *
  * @param \Traversable $result Original results