Advertisement
Guest User

Untitled

a guest
Jan 12th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.94 KB | None | 0 0
  1. SELECT * FROM TABLE WHERE `column1` = 'x' and (`column2` = INET_ATON('1.1.1.1') OR `column3` like '%bla%'...)
  2.  
  3. $where->add($qb->expr()->eq('column2', $qb->expr()->literal('inet_aton('1.1.1.1'))));
  4.  
  5. <?php
  6.  
  7. namespace ApplicationDQL;
  8.  
  9. use DoctrineORMQueryLexer;
  10.  
  11. class InetAtonFunction extends DoctrineORMQueryASTFunctionsFunctionNode
  12. {
  13. public $valueExpression = null;
  14.  
  15. /**
  16. * parse
  17. *
  18. * @param DoctrineORMQueryParser $parser
  19. * @access public
  20. * @return void
  21. */
  22. public function parse(DoctrineORMQueryParser $parser)
  23. {
  24. $parser->match(Lexer::T_IDENTIFIER);
  25. $parser->match(Lexer::T_OPEN_PARENTHESIS);
  26. $this->valueExpression = $parser->StringPrimary();
  27. $parser->match(Lexer::T_CLOSE_PARENTHESIS);
  28. }
  29.  
  30. /**
  31. * getSql
  32. *
  33. * @param DoctrineORMQuerySqlWalker $sqlWalker
  34. * @access public
  35. * @return string
  36. */
  37. public function getSql(DoctrineORMQuerySqlWalker $sqlWalker)
  38. {
  39. return 'INET_ATON('. $this->valueExpression->dispatch($sqlWalker) . ')';
  40. }
  41. }
  42.  
  43. <?php
  44. namespace Observer;
  45.  
  46. //...
  47.  
  48. class Module implements
  49. AutoloaderProviderInterface,
  50. ConfigProviderInterface,
  51. ServiceProviderInterface
  52. {
  53. //...
  54. public function onBootstrap($e)
  55. {
  56.  
  57. $application = $e->getParam('application');
  58. $sm = $application->getServiceManager();
  59. $em = $application->getEventManager();
  60.  
  61. $entityManager = $sm->get('doctrine.entitymanager.orm_default');
  62. $entityManager->getConfiguration()->addCustomStringFunction('inet_aton', 'ApplicationDQLInetAtonFunction');
  63. }
  64. ...
  65.  
  66. SELECT whatever FROM someting where cloumn = inet_aton(:?)
  67.  
  68. <?php
  69.  
  70. namespace MyAppDQL;
  71.  
  72. use DoctrineORMQueryASTFunctionsFunctionNode;
  73. use DoctrineORMQueryLexer;
  74. use DoctrineORMQuerySqlWalker;
  75.  
  76. class InetAnon extends FunctionNode
  77. {
  78. private $arithmeticExpression;
  79.  
  80. public function getSql(SqlWalker $sqlWalker)
  81. {
  82.  
  83. return 'INET_ANON(' . $sqlWalker->walkSimpleArithmeticExpression(
  84. $this->arithmeticExpression
  85. ) . ')';
  86. }
  87.  
  88. public function parse(DoctrineORMQueryParser $parser)
  89. {
  90.  
  91. $lexer = $parser->getLexer();
  92.  
  93. $parser->match(Lexer::T_IDENTIFIER);
  94. $parser->match(Lexer::T_OPEN_PARENTHESIS);
  95.  
  96. $this->arithmeticExpression = $parser->SimpleArithmeticExpression();
  97.  
  98. $parser->match(Lexer::T_CLOSE_PARENTHESIS);
  99. }
  100. }
  101.  
  102. $config = new DoctrineORMConfiguration();
  103.  
  104. $config->addCustomNumericFunction('INET_ANON', 'MyAppDQLInetAnon');
  105.  
  106. doctrine:
  107. dbal:
  108. driver: "%database_driver%"
  109. host: "%database_host%"
  110. port: "%database_port%"
  111. dbname: "%database_name%"
  112. user: "%database_user%"
  113. password: "%database_password%"
  114.  
  115. orm:
  116. auto_generate_proxy_classes: "%kernel.debug%"
  117. auto_mapping: true
  118. dql:
  119. string_functions:
  120. inet_aton: homemyBundlemyFolderContaintClassInetAton
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement