Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Commit

Permalink
adding an IQuery interface to make chaining query generation easier
Browse files Browse the repository at this point in the history
  • Loading branch information
a-musing-moose committed Apr 19, 2011
1 parent 6355878 commit 8d5b3b9
Show file tree
Hide file tree
Showing 9 changed files with 79 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
nbproject
Morph.phar
doc/*
36 changes: 36 additions & 0 deletions src/Morph/IQuery.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php
/**
* @package Morph
* @author Jonathan Moss <[email protected]>
* @copyright 2011 Jonathan Moss
*/

/**
* An interface for query objects
*
* @author Jonathan Moss <[email protected]>
*/
interface Morph_IQuery
{

/**
* @return array
*/
function getRawQuery();

/**
* @return array
*/
function getRawSort();

/**
* @return int
*/
function getLimit();

/**
* @return int
*/
function getSkip();

}
6 changes: 3 additions & 3 deletions src/Morph/Object.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down
3 changes: 1 addition & 2 deletions src/Morph/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
* @package Morph
* @author Jonathan Moss <[email protected]>
* @copyright 2009 Jonathan Moss
* @version SVN: $Id$
*/

/**
Expand Down Expand Up @@ -41,7 +40,7 @@
*
* @package Morph
*/
class Morph_Query
class Morph_Query implements Morph_IQuery
{

/**
Expand Down
28 changes: 27 additions & 1 deletion src/Morph/Query/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @package Morph
* @subpackage Query
*/
class Morph_Query_Property
class Morph_Query_Property implements Morph_IQuery
{

/**
Expand Down Expand Up @@ -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 //
//////////////////////////
Expand Down
8 changes: 4 additions & 4 deletions src/Morph/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions unit-tests/Query/TestProperty.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php
require_once 'PHPUnit/Framework/TestCase.php';

require_once dirname(__FILE__).'/../../src/Morph/Enum.php';
require_once dirname(__FILE__).'/../../src/Morph/IQuery.php';
require_once dirname(__FILE__).'/../../src/Morph/Query/Property.php';

/**
Expand Down
2 changes: 2 additions & 0 deletions unit-tests/TestQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
*/
require_once 'PHPUnit/Framework/TestCase.php';

require_once dirname(__FILE__).'/../src/Morph/Enum.php';
require_once dirname(__FILE__).'/../src/Morph/IQuery.php';
require_once dirname(__FILE__).'/../src/Morph/Query/Property.php';
require_once dirname(__FILE__).'/../src/Morph/Query.php';

Expand Down

0 comments on commit 8d5b3b9

Please sign in to comment.