src/main/php/DataDo/Data/Repository.php
private function addSelectionMethod(QueryBuilderResult $query, $methodName)
    {
        $findMethod = function () use ($query, $methodName) {

            $sth = $this->pdo->prepare($query->getSql());
            /** @noinspection PhpMethodParametersCountMismatchInspection */
            $sth->setFetchMode(\PDO::FETCH_CLASS, $this->entityClass->getName());
            try {
                $sth->execute(func_get_args());
            } catch (PDOException $e) {
                throw new DslSyntaxException('Failed to run query [' . $methodName . '] with parameters ' . print_r(func_get_args(), true));
            }

            switch ($query->getResultMode()) {
                case QueryBuilderResult::RESULT_SELECT_SINGLE:
                    return $sth->fetch();
                case QueryBuilderResult::RESULT_SELECT_MULTIPLE:
                    return $sth->fetchAll();
            }

            throw new DslSyntaxException('Result Mode ' . $query->getResultMode() . ' is not implemented', DATADO_ILLEGAL_RESULT_MODE);

        };

        $this->methods[$methodName] = \Closure::bind($findMethod, $this, get_class());
    }
private function addSelectionMethod(QueryBuilderResult $query, $methodName)
    {
        $findMethod = function () use ($query, $methodName) {

            $sth = $this->pdo->prepare($query->getSql());
            /** @noinspection PhpMethodParametersCountMismatchInspection */
            $sth->setFetchMode(\PDO::FETCH_CLASS, $this->entityClass->getName());
            try {
                $sth->execute(func_get_args());
            } catch (PDOException $e) {
                throw new DslSyntaxException('Failed to run query [' . $methodName . '] with parameters ' . print_r(func_get_args(), true));
            }

            switch ($query->getResultMode()) {
                case QueryBuilderResult::RESULT_SELECT_SINGLE:
                    return $sth->fetch();
                case QueryBuilderResult::RESULT_SELECT_MULTIPLE:
                    return $sth->fetchAll();
            }

            throw new DslSyntaxException('Result Mode ' . $query->getResultMode() . ' is not implemented', DATADO_ILLEGAL_RESULT_MODE);

        };

        $this->methods[$methodName] = \Closure::bind($findMethod, $this, get_class());
    }
private function addSelectionMethod ( QueryBuilderResult $ query , $ methodName ) { $ findMethod = function ( ) use ( $ query , $ methodName ) { $ sth = $ this -> pdo -> prepare ( $ query -> getSql ( ) ) ; /** @noinspection PhpMethodParametersCountMismatchInspection */ $ sth -> setFetchMode ( \ PDO :: FETCH_CLASS , $ this -> entityClass -> getName ( ) ) ; try { $ sth -> execute ( func_get_args ( ) ) ; } catch ( PDOException $ e ) { throw new DslSyntaxException ( 'Failed to run query [' . $ methodName . '] with parameters ' . print_r ( func_get_args ( ) , true ) ) ; } switch ( $ query -> getResultMode ( ) ) { case QueryBuilderResult :: RESULT_SELECT_SINGLE : return $ sth -> fetch ( ) ; case QueryBuilderResult :: RESULT_SELECT_MULTIPLE : return $ sth -> fetchAll ( ) ; } throw new DslSyntaxException ( 'Result Mode ' . $ query -> getResultMode ( ) . ' is not implemented' , DATADO_ILLEGAL_RESULT_MODE ) ; } ; $ this -> methods [ $ methodName ] = \ Closure :: bind ( $ findMethod , $ this , get_class ( ) ) ; }
Add a method that can either result in an entity or an array of entities.
@param $query QueryBuilderResult a parsed query
@param $methodName string the name of the dsl method
@throws DslSyntaxException if an unsupported result mode was requested
Add a method that can either result in an entity or an array of entities .