Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT * FROM TABLE WHERE `column1` = 'x' and (`column2` = INET_ATON('1.1.1.1') OR `column3` like '%bla%'...)
- $where->add($qb->expr()->eq('column2', $qb->expr()->literal('inet_aton('1.1.1.1'))));
- <?php
- namespace ApplicationDQL;
- use DoctrineORMQueryLexer;
- class InetAtonFunction extends DoctrineORMQueryASTFunctionsFunctionNode
- {
- public $valueExpression = null;
- /**
- * parse
- *
- * @param DoctrineORMQueryParser $parser
- * @access public
- * @return void
- */
- public function parse(DoctrineORMQueryParser $parser)
- {
- $parser->match(Lexer::T_IDENTIFIER);
- $parser->match(Lexer::T_OPEN_PARENTHESIS);
- $this->valueExpression = $parser->StringPrimary();
- $parser->match(Lexer::T_CLOSE_PARENTHESIS);
- }
- /**
- * getSql
- *
- * @param DoctrineORMQuerySqlWalker $sqlWalker
- * @access public
- * @return string
- */
- public function getSql(DoctrineORMQuerySqlWalker $sqlWalker)
- {
- return 'INET_ATON('. $this->valueExpression->dispatch($sqlWalker) . ')';
- }
- }
- <?php
- namespace Observer;
- //...
- class Module implements
- AutoloaderProviderInterface,
- ConfigProviderInterface,
- ServiceProviderInterface
- {
- //...
- public function onBootstrap($e)
- {
- $application = $e->getParam('application');
- $sm = $application->getServiceManager();
- $em = $application->getEventManager();
- $entityManager = $sm->get('doctrine.entitymanager.orm_default');
- $entityManager->getConfiguration()->addCustomStringFunction('inet_aton', 'ApplicationDQLInetAtonFunction');
- }
- ...
- SELECT whatever FROM someting where cloumn = inet_aton(:?)
- <?php
- namespace MyAppDQL;
- use DoctrineORMQueryASTFunctionsFunctionNode;
- use DoctrineORMQueryLexer;
- use DoctrineORMQuerySqlWalker;
- class InetAnon extends FunctionNode
- {
- private $arithmeticExpression;
- public function getSql(SqlWalker $sqlWalker)
- {
- return 'INET_ANON(' . $sqlWalker->walkSimpleArithmeticExpression(
- $this->arithmeticExpression
- ) . ')';
- }
- public function parse(DoctrineORMQueryParser $parser)
- {
- $lexer = $parser->getLexer();
- $parser->match(Lexer::T_IDENTIFIER);
- $parser->match(Lexer::T_OPEN_PARENTHESIS);
- $this->arithmeticExpression = $parser->SimpleArithmeticExpression();
- $parser->match(Lexer::T_CLOSE_PARENTHESIS);
- }
- }
- $config = new DoctrineORMConfiguration();
- $config->addCustomNumericFunction('INET_ANON', 'MyAppDQLInetAnon');
- doctrine:
- dbal:
- driver: "%database_driver%"
- host: "%database_host%"
- port: "%database_port%"
- dbname: "%database_name%"
- user: "%database_user%"
- password: "%database_password%"
- orm:
- auto_generate_proxy_classes: "%kernel.debug%"
- auto_mapping: true
- dql:
- string_functions:
- inet_aton: homemyBundlemyFolderContaintClassInetAton
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement