Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList::__construct PHP Method

__construct() public method

public __construct ( EntityManager $em, $class, $property = null, $queryBuilder = null, $choices = [] )
$em Doctrine\ORM\EntityManager
    public function __construct(EntityManager $em, $class, $property = null, $queryBuilder = null, $choices = array())
    {
        // If a query builder was passed, it must be a closure or QueryBuilder
        // instance
        if (!(null === $queryBuilder || $queryBuilder instanceof QueryBuilder || $queryBuilder instanceof \Closure)) {
            throw new UnexpectedTypeException($queryBuilder, 'Doctrine\ORM\QueryBuilder or \Closure');
        }

        if ($queryBuilder instanceof \Closure) {
            $queryBuilder = $queryBuilder($em->getRepository($class));

            if (!$queryBuilder instanceof QueryBuilder) {
                throw new UnexpectedTypeException($queryBuilder, 'Doctrine\ORM\QueryBuilder');
            }
        }

        $this->em = $em;
        $this->class = $class;
        $this->queryBuilder = $queryBuilder;
        $this->unitOfWork = $em->getUnitOfWork();
        $this->identifier = $em->getClassMetadata($class)->getIdentifierFieldNames();

        // The property option defines, which property (path) is used for
        // displaying entities as strings
        if ($property) {
            $this->propertyPath = new PropertyPath($property);
        }

        parent::__construct($choices);
    }

Usage Example

 /**
  * Constructs
  *
  * @param EntityManager  $em
  * @param string         $class
  * @param string         $property
  * @param QueryBuilder   $qb
  * @param array|\Closure $choices
  * @param string         $groupBy
  * @param boolean        $ajax
  */
 public function __construct(EntityManager $em, $class, $property = null, $qb = null, $choices = null, $groupBy = null, $ajax = false)
 {
     $this->ajax = $ajax;
     if ($property) {
         $this->propertyPath = new PropertyPath($property);
     }
     parent::__construct($em, $class, $property, $qb, $choices, $groupBy);
 }
All Usage Examples Of Symfony\Bridge\Doctrine\Form\ChoiceList\EntityChoiceList::__construct