@param Expression[] $expressions
@param string       $class

@return \Doctrine\ORM\QueryBuilder

@throws \Exception
17675
public function toQueryBuilder(array $expressions, $class)
    {
        $expr = $this->buildExpression($expressions);

        $qb = $this->em->getRepository($class)->createQueryBuilder('a');

        $traverser = new ExpressionTraverser();
        $traverser->addVisitor(new QueryBuilderVisitor($qb));
        $traverser->traverse($expr);

        return $qb;
    }
352378
protected function instantiateClass($class)
    {
        try {
            $instance = app($class);

        } catch (BindingResolutionException $e) {

            throw new InvalidArgumentException(
                "Failed to instantiate Module or ModuleGenerator instance for '{$class}'",
                $e->getCode(),
                $e
            );

        } catch (ReflectionException $e) {

            throw new InvalidArgumentException(
                "Failed to instantiate Module or ModuleGenerator instance for '{$class}'",
                $e->getCode(),
                $e
            );
        }

        if (    ! ($instance instanceof ModuleInterface)
            &&  ! ($instance instanceof ModuleGeneratorInterface)
        ) {
            throw new InvalidArgumentException(
                "Expected ModuleInterface or ModuleGeneratorInterface, got '{$class}'"
            );
        }

        return $instance;
    }
273310
protected function findExpressions(array $attributes, $expressions=null)
    {

        $search = [
            'string'   => isset($attributes['string'])   ? $attributes['string']   : '*',
            'name'     => isset($attributes['name'])     ? $attributes['name']     : '*',
            'operator' => isset($attributes['operator']) ? $attributes['operator'] : '*',
            'operand'  => isset($attributes['operand'])  ? $attributes['operand']  : '*',
            'class'    => isset($attributes['class'])    ? $attributes['class']    : '*',
        ];

        $expressions = $expressions ?: $this->allExpressions();

        $matches = [];

        foreach ($expressions as $expression) {

            if ($this->matchesAttributes($expression, $search)) {
                $matches[] = $expression;
            }
        }

        return $matches;
    }
1357575
public static function hydrate($class, $results, $type = self::TYPE_COLLECTION , $exists = false)
    {

        if (!class_exists($class)) {
            throw new \Exception("class {$class} not exists!");
        } elseif ($type == self::TYPE_COLLECTION) {
            $models = array();
            foreach ($results as $result) {
                $model = self::pack($class, $result , $exists);
                $models[] = $model;
            }

            return Collection::make($models);
        } else {
            $model = self::pack($class, $results , $exists);
            return $model;
        }

    }
1294352
public static function from($queryClassAndAlias)
    {
        list($class, $alias) = ModelCriteria::getClassAndAlias($queryClassAndAlias);
        $queryClass = $class . 'Query';
        if (!class_exists($queryClass)) {
            throw new PropelException('Cannot find a query class for ' . $class);
        }
        $query = new $queryClass();
        if ($alias !== null) {
            $query->setModelAlias($alias);
        }

        return $query;
    }
270719
protected function buildExpression($collection, $type = AndX::class)
    {
        $expressions = [];

        /** @var Expression $expression */
        foreach ($collection as $expression) {
            if (!$expression instanceof Expression) {
                throw new \Exception(sprintf('Expressions must be of type %s', Expression::class));
            }

            if (count($expression->getChildren())) {
                $expressions[] = $this->buildExpression($expression->getChildren(), $expression->getConstraint());
            } else {
                $expressions[] = $this->transform($expression);
            }
        }

        return new $type($expressions);
    }
456168
public function all(string $class=""): \ArrayIterator
    {
        return new \ArrayIterator(
            array_merge(
                $this->in($class)->getArrayCopy(), 
                $this->out($class)->getArrayCopy()
            )
        );
    }
189892
protected function buildCustomDatabaseIndexes($class)
    {
        $indexes = [];
        $classIndexes = Config::inst()->get($class, 'indexes', Config::UNINHERITED) ?: [];
        foreach ($classIndexes as $indexName => $indexSpec) {
            if (array_key_exists($indexName, $indexes)) {
                throw new InvalidArgumentException(sprintf(
                    'Index named "%s" already exists on class %s',
                    $indexName,
                    $class
                ));
            }
            if (is_array($indexSpec)) {
                if (!ArrayLib::is_associative($indexSpec)) {
                    $indexSpec = [
                        'columns' => $indexSpec,
                    ];
                }
                if (!isset($indexSpec['type'])) {
                    $indexSpec['type'] = 'index';
                }
                if (!isset($indexSpec['columns'])) {
                    $indexSpec['columns'] = [$indexName];
                } elseif (!is_array($indexSpec['columns'])) {
                    throw new InvalidArgumentException(sprintf(
                        'Index %s on %s is not valid. columns should be an array %s given',
                        var_export($indexName, true),
                        var_export($class, true),
                        var_export($indexSpec['columns'], true)
                    ));
                }
            } else {
                $indexSpec = [
                    'type' => 'index',
                    'columns' => [$indexName],
                ];
            }
            $indexes[$indexName] = $indexSpec;
        }
        return $indexes;
    }
134412
public function getSpecificSubclassMapping(string $class): self
    {
        if ($this->class->getClassName() === $class) {
            return $this;
        }

        if (!is_subclass_of($class, $this->class->getClassName(), true)) {
            throw InvalidArgumentException::format(
                'Invalid class supplied to %s: must be a subclass of %s, %s given',
                __METHOD__, $this->class->getClassName(), $class
            );
        }

        foreach ($this->subClassMappings as $mapping) {
            if (is_subclass_of($class, $mapping->getDefinition()->getClassName(), true)) {
                return $mapping->getDefinition()->getSpecificSubclassMapping($class);
            }
        }

        throw InvalidArgumentException::format(
            'Invalid class supplied to %s: cannot find mapping for %s',
            __METHOD__, $class
        );
    }
490622
public function executeClass($class)
    {
        $classReflection = new \ReflectionClass($class);
        $bag = new ExecutedBag();

        $classExecuted = $this->parse($classReflection->getDocComment())
            ->execute();


        $bag->set(
            'properties',
            $this->executeProperties($classReflection->getProperties())
        );

        $methods = $classReflection->getMethods();


        $bag->set('methods',
            $this->executeMethods($methods)
        );


        foreach ($classExecuted as $item => $value) {
            $bag->set($item, $value);
        }

        return $bag;
    }
982402
public function bindMany(string $class, array $methods)
  {
    /**
     * Map through the functions
     *
     * @param Closure $closure
     */
    array_map(function ($closure) use ($class) {

      $info = new ReflectionFunction($closure);

      $doc  = explode(PHP_EOL, $info->getDocComment());

      /**
       * Filter out the stuff that's not needed
       */
      array_filter($doc, function($comment) use ($class, $closure) {

        /**
         * Register a new function if its not commented out
         */
        if (str_contains($comment, '@method') && !str_contains($comment, '//')) {

          /**
           * Filter out "*" and "@method"
           */
          $filtered = array_diff(
            array_filter(explode(' ', $comment)
          ), ['*', '@method']);

          /**
           * Return the name of the method
           */
          $method = array_first($filtered, function($value) {
            if (ends_with($value, '()')) return $value;
          });

          /**
           * Bind new method to $class
           */
          if ($method) {
            $this->bind($class, substr($method, 0, strlen($method) - 2), $closure);
          }

        }

      });
    }, $methods);
  }
120215
public function findQueryBuilderForClass($class, array $method = [], $queryResult = null) {
        $em = $this->getDoctrine()->getManager();
        $alias = "c";
        $qb = $em->createQueryBuilder()
                ->select($alias)
                ->from($class, $alias);
        foreach ($method as $key => $value) {
            $qb
                    ->andWhere(sprintf("%s.%s = :%s", $alias, $key, $key))
                    ->setParameter($key, $value)
            ;
        }
        if ($queryResult == "OneOrNull") {
            return $qb->getQuery()->getOneOrNullResult();
        } else {
            return $qb->getQuery()->getResult();
        }
    }
798852
public function from(string $tables) : QueryBuilder
    {
        $this->_query[] = "FROM";
        $this->_query[] = '`'. $this->sanitize($tables) .'`';

        return $this;
    }
1239418
protected function createConjunctionExpression(array $expressions, $conjunction)
    {
        // create the appropriate expression
        if (ListBuilderInterface::CONJUNCTION_AND === strtoupper($conjunction)) {
            return $this->listBuilder->createAndExpression($expressions);
        }

        return $this->listBuilder->createOrExpression($expressions);
    }
1190133
public function scopeWhereSubjectModel(Builder $query, string $class)
    {
        $notificationTypes = array_filter(self::getSubjectModels(), function ($modelClass) use ($class) {
            return $modelClass === $class or is_subclass_of($class, $modelClass);
        });

        $query->whereIn('type', array_keys($notificationTypes));
    }
639195
protected function transform(Expression $expression)
    {
        $constraint = $expression->getConstraint();
        $getter = 'get'.ucfirst($expression->getSelector());

        return Expr::method($getter, new $constraint($expression->getValue()));
    }
767754
public function getStatementBuilder($builderClass = Select::class)
    {
        // @SOMEDAY check for instance of StatementBuilder

        /** @var StatementBuilder $statementBuilder */
        $statementBuilder = new $builderClass();
        $table = $this->getResultModel()->getTableName();

        $statementBuilder->setFrom($table);

        return $statementBuilder;
    }