diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f1b5640 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +nbproject +Morph.phar +doc/* diff --git a/src/Morph/IQuery.php b/src/Morph/IQuery.php new file mode 100644 index 0000000..80b677b --- /dev/null +++ b/src/Morph/IQuery.php @@ -0,0 +1,36 @@ + + * @copyright 2011 Jonathan Moss + */ + +/** + * An interface for query objects + * + * @author Jonathan Moss + */ +interface Morph_IQuery +{ + + /** + * @return array + */ + function getRawQuery(); + + /** + * @return array + */ + function getRawSort(); + + /** + * @return int + */ + function getLimit(); + + /** + * @return int + */ + function getSkip(); + +} diff --git a/src/Morph/Object.php b/src/Morph/Object.php index b5e3bab..7e8048b 100644 --- a/src/Morph/Object.php +++ b/src/Morph/Object.php @@ -230,10 +230,10 @@ public function findByIds(array $ids) /** * Find objects by query * - * @param Morph_Query $query + * @param Morph_IQuery $query * @return Morph_Iterator */ - public function findByQuery(Morph_Query $query) + public function findByQuery(Morph_IQuery $query) { return Morph_Storage::instance()->findByQuery($this, $query); } @@ -244,7 +244,7 @@ public function findByQuery(Morph_Query $query) * @param Morph_Query $query * @return Morph_Object */ - public function findOneByQuery(Morph_Query $query) + public function findOneByQuery(Morph_IQuery $query) { return Morph_Storage::instance()->findOneByQuery($this, $query); } diff --git a/src/Morph/Query.php b/src/Morph/Query.php index db561da..f422a09 100644 --- a/src/Morph/Query.php +++ b/src/Morph/Query.php @@ -3,7 +3,6 @@ * @package Morph * @author Jonathan Moss * @copyright 2009 Jonathan Moss - * @version SVN: $Id$ */ /** @@ -41,7 +40,7 @@ * * @package Morph */ -class Morph_Query +class Morph_Query implements Morph_IQuery { /** diff --git a/src/Morph/Query/Property.php b/src/Morph/Query/Property.php index 3058206..40a559f 100644 --- a/src/Morph/Query/Property.php +++ b/src/Morph/Query/Property.php @@ -14,7 +14,7 @@ * @package Morph * @subpackage Query */ -class Morph_Query_Property +class Morph_Query_Property implements Morph_IQuery { /** @@ -98,6 +98,32 @@ public function skip($numberToSkip) return $this->query->skip($numberToSkip); } + public function getRawQuery() + { + return $this->query->getRawQuery(); + } + + public function getRawSort() + { + return $this->query->getRawSort(); + } + + /** + * @return int + */ + public function getSkip() + { + return $this->query->getSkip(); + } + + /** + * @return int + */ + public function getLimit() + { + return $this->getLimit(); + } + ////////////////////////// // CONSTRAINT FUNCTIONS // ////////////////////////// diff --git a/src/Morph/Storage.php b/src/Morph/Storage.php index e2f3e12..e03b079 100644 --- a/src/Morph/Storage.php +++ b/src/Morph/Storage.php @@ -191,10 +191,10 @@ public function delete(Morph_Object $object) * The results come packages up in a Morph_Iterator object * * @param Morph_Object $object Required to determine the correct collection query against - * @param Morph_Query $query + * @param Morph_IQuery $query * @return Morph_Iterator */ - public function findByQuery(Morph_Object $object, Morph_Query $query = null) + public function findByQuery(Morph_Object $object, Morph_IQuery $query = null) { $class = get_class($object); @@ -225,10 +225,10 @@ public function findByQuery(Morph_Object $object, Morph_Query $query = null) * Finds one object matching the passed in query * * @param Morph_Object $object - * @param Morph_Query $query + * @param Morph_IQuery $query * @return Morph_Object */ - public function findOneByQuery(Morph_Object $object, Morph_Query $query = null) + public function findOneByQuery(Morph_Object $object, Morph_IQuery $query = null) { $result = null; $class = get_class($object); diff --git a/src/bootstrap.php b/src/bootstrap.php index 8486a82..199fb0e 100644 --- a/src/bootstrap.php +++ b/src/bootstrap.php @@ -25,6 +25,7 @@ class MorphAutoloader 'Morph_Compare_Property' => 'phar://Morph/Compare/Property.php', 'Morph_PropertySet' => 'phar://Morph/PropertySet.php', 'Morph_Query' => 'phar://Morph/Query.php', + 'Morph_IQuery' => 'phar://Morph/IQuery.php', 'Morph_Object' => 'phar://Morph/Object.php', 'Morph_ICompare' => 'phar://Morph/ICompare.php', 'Morph_Property_HasMany' => 'phar://Morph/Property/HasMany.php', diff --git a/unit-tests/Query/TestProperty.php b/unit-tests/Query/TestProperty.php index 658ac34..0d4ce85 100644 --- a/unit-tests/Query/TestProperty.php +++ b/unit-tests/Query/TestProperty.php @@ -1,6 +1,8 @@