This repository has been archived by the owner on Nov 11, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 189
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving query builder core out of odm.
- Loading branch information
Showing
16 changed files
with
2,645 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,180 @@ | ||
<?php | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the LGPL. For more information, see | ||
* <http://www.doctrine-project.org>. | ||
*/ | ||
|
||
namespace Doctrine\MongoDB\Query; | ||
|
||
use Doctrine\MongoDB\Iterator; | ||
use Doctrine\MongoDB\Database; | ||
use Doctrine\MongoDB\Collection; | ||
|
||
/** | ||
* Abstract executable query class for the different types of queries to implement. | ||
* | ||
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL | ||
* @since 1.0 | ||
* @author Jonathan H. Wage <jonwage@gmail.com> | ||
*/ | ||
abstract class AbstractQuery implements QueryInterface, Iterator | ||
{ | ||
/** | ||
* The Database instance. | ||
* | ||
* @var Database | ||
*/ | ||
protected $database; | ||
|
||
/** | ||
* The Collection instance. | ||
* | ||
* @var Collection | ||
*/ | ||
protected $collection; | ||
|
||
/** | ||
* Mongo command prefix | ||
* | ||
* @var string | ||
*/ | ||
protected $cmd; | ||
|
||
/** | ||
* @var Iterator | ||
*/ | ||
protected $iterator; | ||
|
||
public function __construct(Database $database, Collection $collection, $cmd) | ||
{ | ||
$this->database = $database; | ||
$this->collection = $collection; | ||
$this->cmd = $cmd; | ||
} | ||
|
||
/** | ||
* Gets an array of information about this query for debugging. | ||
* | ||
* @param string $name | ||
* @return array $debug | ||
*/ | ||
public function debug($name = null) | ||
{ | ||
$debug = get_object_vars($this); | ||
|
||
unset($debug['database'], $debug['collection'], $debug['cmd']); | ||
if ($name !== null) { | ||
return $debug[$name]; | ||
} | ||
foreach ($debug as $key => $value) { | ||
if ( ! $value) { | ||
unset($debug[$key]); | ||
} | ||
} | ||
return $debug; | ||
} | ||
|
||
public function getIterator(array $options = array()) | ||
{ | ||
if ($this->iterator === null) { | ||
$iterator = $this->execute($options); | ||
if ($iterator !== null && !$iterator instanceof Iterator) { | ||
throw new \BadMethodCallException('Query execution did not return an iterator. This query may not support returning iterators. '); | ||
} | ||
$this->iterator = $iterator; | ||
} | ||
return $this->iterator; | ||
} | ||
|
||
/** | ||
* Count the number of results for this query. | ||
* | ||
* @param bool $all | ||
* @return integer $count | ||
*/ | ||
public function count($all = false) | ||
{ | ||
return $this->getIterator()->count($all); | ||
} | ||
|
||
/** | ||
* Execute the query and get a single result | ||
* | ||
* @return object $document The single document. | ||
*/ | ||
public function getSingleResult(array $options = array()) | ||
{ | ||
return $this->getIterator($options)->getSingleResult(); | ||
} | ||
|
||
/** | ||
* Iterator over the query using the Cursor. | ||
* | ||
* @return Cursor $cursor | ||
*/ | ||
public function iterate() | ||
{ | ||
return $this->getIterator(); | ||
} | ||
|
||
/** @inheritDoc */ | ||
public function first() | ||
{ | ||
return $this->getIterator()->first(); | ||
} | ||
|
||
/** @inheritDoc */ | ||
public function last() | ||
{ | ||
return $this->getIterator()->last(); | ||
} | ||
|
||
/** @inheritDoc */ | ||
public function key() | ||
{ | ||
return $this->getIterator()->key(); | ||
} | ||
|
||
/** @inheritDoc */ | ||
public function next() | ||
{ | ||
return $this->getIterator()->next(); | ||
} | ||
|
||
/** @inheritDoc */ | ||
public function current() | ||
{ | ||
return $this->getIterator()->current(); | ||
} | ||
|
||
/** @inheritDoc */ | ||
public function rewind() | ||
{ | ||
return $this->getIterator()->rewind(); | ||
} | ||
|
||
/** @inheritDoc */ | ||
public function valid() | ||
{ | ||
return $this->getIterator()->valid(); | ||
} | ||
|
||
/** @inheritDoc */ | ||
public function toArray() | ||
{ | ||
return $this->getIterator()->toArray(); | ||
} | ||
} |
Oops, something went wrong.