SHARE
TWEET

Untitled

a guest Jun 15th, 2019 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace App\Adapters\Doctrine;
  4.  
  5. use Doctrine\ORM\Query\AST\Functions\FunctionNode;
  6. use Doctrine\ORM\Query\AST\Subselect;
  7. use Doctrine\ORM\Query\Lexer;
  8. use Doctrine\ORM\Query\Parser;
  9. use Doctrine\ORM\Query\SqlWalker;
  10.  
  11. class RegexSubstrFunction extends FunctionNode
  12. {
  13.     /**
  14.      * @var Subselect
  15.      */
  16.     private $string;
  17.  
  18.     /**
  19.      * @var Subselect
  20.      */
  21.     private $pattern;
  22.  
  23.     /**
  24.      * @param Parser $parser
  25.      * @throws \Doctrine\ORM\Query\QueryException
  26.      */
  27.     public function parse(Parser $parser)
  28.     {
  29.         $parser->match(Lexer::T_IDENTIFIER);
  30.         $parser->match(Lexer::T_OPEN_PARENTHESIS);
  31.         $this->string = $parser->ArithmeticPrimary();
  32.         $parser->match(Lexer::T_COMMA);
  33.         $this->pattern = $parser->Literal();
  34.         $parser->match(Lexer::T_CLOSE_PARENTHESIS);
  35.     }
  36.  
  37.     /**
  38.      * @param SqlWalker $sqlWalker
  39.      * @return string
  40.      * @throws \Doctrine\ORM\Query\AST\ASTException
  41.      */
  42.     public function getSql(SqlWalker $sqlWalker)
  43.     {
  44.         return sprintf('REGEX_SUBSTR(%s, %s)',
  45.             $this->string->dispatch($sqlWalker),
  46.             $this->pattern->dispatch($sqlWalker)
  47.         );
  48.     }
  49. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top