forked from doctrine/DoctrineMongoDBBundle
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request doctrine#67 from stof/forms
Refactored the form integration to use the bridge
- Loading branch information
Showing
8 changed files
with
88 additions
and
1,030 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,71 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Doctrine MongoDBBundle | ||
* | ||
* The code was originally distributed inside the Symfony framework. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* (c) Doctrine Project | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Doctrine\Bundle\MongoDBBundle\Form\ChoiceList; | ||
|
||
use Doctrine\Common\Persistence\ObjectManager; | ||
use Doctrine\ODM\MongoDB\Query\Builder; | ||
use Symfony\Bridge\Doctrine\Form\ChoiceList\EntityLoaderInterface; | ||
use Symfony\Component\Form\Exception\FormException; | ||
use Symfony\Component\Form\Exception\UnexpectedTypeException; | ||
|
||
/** | ||
* Getting Entities through the MongoDB QueryBuilder | ||
*/ | ||
class MongoDBQueryBuilderLoader implements EntityLoaderInterface | ||
{ | ||
/** | ||
* Contains the query builder that builds the query for fetching the | ||
* entities | ||
* | ||
* This property should only be accessed through queryBuilder. | ||
* | ||
* @var Builder | ||
*/ | ||
private $queryBuilder; | ||
|
||
/** | ||
* Construct an ORM Query Builder Loader | ||
* | ||
* @param Builder|\Closure $queryBuilder | ||
* @param ObjectManager $manager | ||
* @param string $class | ||
*/ | ||
public function __construct($queryBuilder, ObjectManager $manager = null, $class = null) | ||
{ | ||
// If a query builder was passed, it must be a closure or QueryBuilder | ||
// instance | ||
if (!($queryBuilder instanceof Builder || $queryBuilder instanceof \Closure)) { | ||
throw new UnexpectedTypeException($queryBuilder, 'Doctrine\ODM\MongoDB\Query\Builder or \Closure'); | ||
} | ||
|
||
if ($queryBuilder instanceof \Closure) { | ||
$queryBuilder = $queryBuilder($manager->getRepository($class)); | ||
|
||
if (!$queryBuilder instanceof Builder) { | ||
throw new UnexpectedTypeException($queryBuilder, 'Doctrine\ODM\MongoDB\Query\Builder'); | ||
} | ||
} | ||
|
||
$this->queryBuilder = $queryBuilder; | ||
} | ||
|
||
/** | ||
* {@inheritDoc} | ||
*/ | ||
public function getEntities() | ||
{ | ||
return $this->queryBuilder->getQuery()->execute(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.