Created
September 17, 2020 19:19
-
-
Save felipyamorim/378b95da18184b4c96bee3faddf58b4d to your computer and use it in GitHub Desktop.
Doctrine Custom Top function
This file contains hidden or 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
| <?php | |
| /** | |
| * Created by PhpStorm. | |
| * User: felipy.amorim | |
| * Date: 10/03/2017 | |
| * Time: 13:05 | |
| */ | |
| namespace App\DQL; | |
| use Doctrine\ORM\Query\AST\Functions\FunctionNode; | |
| use Doctrine\ORM\Query\Lexer; | |
| use Doctrine\ORM\Query\Parser; | |
| use Doctrine\ORM\Query\SqlWalker; | |
| class TopFunction extends FunctionNode | |
| { | |
| public $quantityExpression = null; | |
| public $selectExpression = null; | |
| public function parse(Parser $parser) | |
| { | |
| $parser->match(Lexer::T_IDENTIFIER); | |
| $parser->match(Lexer::T_OPEN_PARENTHESIS); | |
| $this->quantityExpression = $parser->ArithmeticExpression(); | |
| $parser->match(Lexer::T_COMMA); | |
| $this->selectExpression = $parser->ArithmeticExpression(); | |
| $parser->match(Lexer::T_CLOSE_PARENTHESIS); | |
| } | |
| public function getSql(SqlWalker $sqlWalker) | |
| { | |
| return sprintf('TOP %s %s', $this->quantityExpression->dispatch($sqlWalker), $this->selectExpression->dispatch($sqlWalker)); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment