Permalink
Browse files

adding an exception when requested object cannot be found

git-svn-id: http://mongodb-morph.googlecode.com/svn/trunk@143 406649b4-5d4b-11de-8abc-d1c337b90d21
  • Loading branch information...
1 parent affcef1 commit 8171ea1af74b3379dfa3447185a7f1d3fae19b17 Xirisr@gmail.com committed Apr 15, 2011
@@ -0,0 +1,18 @@
+<?php
+/**
+ * @package
+ * @copyright 2011 Tangent Labs
+ * @version SVN: $Id$
+ * @author Jonathan Moss <jonathan.moss@tangentone.com.au>
+ */
+
+/**
+ * thrown when a requested object could not be found
+ *
+ * @package Morph
+ * @subpackage Exception
+ */
+class Morph_Exception_ObjectNotFound extends RuntimeException
+{
+
+}
@@ -90,8 +90,7 @@ public function fetchById(Morph_Object $object, $id)
{
$query = array('_id' => $id);
$data = $this->Db->selectCollection($object->collection())->findOne($query);
- $object->__setData($data, Morph_Enum::STATE_CLEAN);
- return $object;
+ return $this->setData($object, $data);
}
/**
@@ -119,8 +118,7 @@ public function fetchByIds(Morph_Object $object, array $ids)
public function fetchByDbRef(Morph_Object $object, array $dbRef)
{
$data = $this->Db->getDBRef($dbRef);
- $object->__setData($data, Morph_Enum::STATE_CLEAN);
- return $object;
+ return $this->setData($object, $data);
}
/**
@@ -237,11 +235,7 @@ public function findOneByQuery(Morph_Object $object, Morph_Query $query = null)
$query = (is_null($query)) ? new Morph_Query() : $query;
$data = $this->Db->selectCollection($object->collection())->findOne($query->getRawQuery());
- if (!empty($data)) {
- $result = new $class;
- $result->__setData($data, Morph_Enum::STATE_CLEAN);
- }
- return $result;
+ return $this->setData($object, $data);
}
/**
@@ -276,4 +270,18 @@ public function saveFile($filePath, $oldReference = null)
}
return $id;
}
+
+ /**
+ * @param Morph_Object $object
+ * @param array $data
+ * @return Morph_Object
+ */
+ private function setData(Morph_Object $object, $data)
+ {
+ if (empty($data)) {
+ throw new Morph_Exception_ObjectNotFound();
+ }
+ $object->__setData($data, Morph_Enum::STATE_CLEAN);
+ return $object;
+ }
}
@@ -18,30 +18,31 @@ class MorphAutoloader
* @var array
*/
private static $classes = array(
- 'Morph_Collection' => 'phar://Morph/Collection.php',
- 'Morph_Utils' => 'phar://Morph/Utils.php',
- 'Morph_Iterator' => 'phar://Morph/Iterator.php',
- 'Morph_Compare_NumericProperty' => 'phar://Morph/Compare/NumericProperty.php',
- 'Morph_Compare_Property' => 'phar://Morph/Compare/Property.php',
- 'Morph_PropertySet' => 'phar://Morph/PropertySet.php',
- 'Morph_Query' => 'phar://Morph/Query.php',
- 'Morph_Object' => 'phar://Morph/Object.php',
- 'Morph_ICompare' => 'phar://Morph/ICompare.php',
- 'Morph_Property_HasMany' => 'phar://Morph/Property/HasMany.php',
- 'Morph_Property_Date' => 'phar://Morph/Property/Date.php',
- 'Morph_Property_ComposeMany' => 'phar://Morph/Property/ComposeMany.php',
- 'Morph_Property_HasOne' => 'phar://Morph/Property/HasOne.php',
- 'Morph_Property_Enum' => 'phar://Morph/Property/Enum.php',
- 'Morph_Property_Integer' => 'phar://Morph/Property/Integer.php',
- 'Morph_Property_File' => 'phar://Morph/Property/File.php',
- 'Morph_Property_Float' => 'phar://Morph/Property/Float.php',
- 'Morph_Property_ComposeOne' => 'phar://Morph/Property/ComposeOne.php',
- 'Morph_Property_String' => 'phar://Morph/Property/String.php',
- 'Morph_Property_Generic' => 'phar://Morph/Property/Generic.php',
- 'Morph_Query_Property' => 'phar://Morph/Query/Property.php',
- 'Morph_Storage' => 'phar://Morph/Storage.php',
- 'Morph_Format_Collection' => 'phar://Morph/Format/Collection.php',
- 'Morph_Enum' => 'phar://Morph/Enum.php'
+ 'Morph_Collection' => 'phar://Morph/Collection.php',
+ 'Morph_Utils' => 'phar://Morph/Utils.php',
+ 'Morph_Iterator' => 'phar://Morph/Iterator.php',
+ 'Morph_Compare_NumericProperty' => 'phar://Morph/Compare/NumericProperty.php',
+ 'Morph_Compare_Property' => 'phar://Morph/Compare/Property.php',
+ 'Morph_PropertySet' => 'phar://Morph/PropertySet.php',
+ 'Morph_Query' => 'phar://Morph/Query.php',
+ 'Morph_Object' => 'phar://Morph/Object.php',
+ 'Morph_ICompare' => 'phar://Morph/ICompare.php',
+ 'Morph_Property_HasMany' => 'phar://Morph/Property/HasMany.php',
+ 'Morph_Property_Date' => 'phar://Morph/Property/Date.php',
+ 'Morph_Property_ComposeMany' => 'phar://Morph/Property/ComposeMany.php',
+ 'Morph_Property_HasOne' => 'phar://Morph/Property/HasOne.php',
+ 'Morph_Property_Enum' => 'phar://Morph/Property/Enum.php',
+ 'Morph_Property_Integer' => 'phar://Morph/Property/Integer.php',
+ 'Morph_Property_File' => 'phar://Morph/Property/File.php',
+ 'Morph_Property_Float' => 'phar://Morph/Property/Float.php',
+ 'Morph_Property_ComposeOne' => 'phar://Morph/Property/ComposeOne.php',
+ 'Morph_Property_String' => 'phar://Morph/Property/String.php',
+ 'Morph_Property_Generic' => 'phar://Morph/Property/Generic.php',
+ 'Morph_Query_Property' => 'phar://Morph/Query/Property.php',
+ 'Morph_Storage' => 'phar://Morph/Storage.php',
+ 'Morph_Format_Collection' => 'phar://Morph/Format/Collection.php',
+ 'Morph_Enum' => 'phar://Morph/Enum.php',
+ 'Morph_Exception_ObjectNotFound' => 'phar://Morph/Exception/ObjectNotFound.php',
);
/**

0 comments on commit 8171ea1

Please sign in to comment.