Skip to content

Commit

Permalink
Add orm3 compatibility and simplifying with abstract classes
Browse files Browse the repository at this point in the history
  • Loading branch information
connorhu committed Jan 26, 2024
1 parent 67f32c1 commit daaa858
Show file tree
Hide file tree
Showing 191 changed files with 1,399 additions and 1,955 deletions.
10 changes: 6 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@
{"name": "Steve Lacey", "email": "steve@steve.ly"}
],
"require": {
"php": "^7.2 || ^8.0",
"doctrine/orm": "^2.7"
"php": "^8.0",
"doctrine/orm": "^2.7 || 3.0.0-beta2"
},
"require-dev": {
"doctrine/cache": "^1.11",
"friendsofphp/php-cs-fixer": "^2.14",
"nesbot/carbon": "*",
"phpunit/phpunit": "^7.0 || ^8.0 || ^9.0",
"symfony/yaml": "^4.4 || ^5.3 || ^6.0",
"symfony/cache": "^6.0",
"symfony/yaml": "^6.0",
"zf1/zend-date": "^1.12",
"zf1/zend-registry": "^1.12"
},
Expand All @@ -33,5 +34,6 @@
"scripts": {
"lint": "php-cs-fixer fix --ansi --diff --diff-format udiff --show-progress=none --verbose",
"test": "phpunit --colors=always"
}
},
"minimum-stability": "beta"
}
22 changes: 22 additions & 0 deletions src/Query/AbstractCryptParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace DoctrineExtensions\Query;

use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;

abstract class AbstractCryptParser extends FunctionNode
{
public function parse(\Doctrine\ORM\Query\Parser $parser): void
{
$orm3 = !defined('\Doctrine\ORM\Query\Lexer::T_IDENTIFIER');

$parser->match($orm3 ? TokenType::T_IDENTIFIER : Lexer::T_IDENTIFIER);
$parser->match($orm3 ? TokenType::T_OPEN_PARENTHESIS : Lexer::T_OPEN_PARENTHESIS);
$this->field = $parser->StringExpression();
$parser->match($orm3 ? TokenType::T_COMMA : Lexer::T_COMMA);
$this->key = $parser->StringExpression();
$parser->match($orm3 ? TokenType::T_CLOSE_PARENTHESIS : Lexer::T_CLOSE_PARENTHESIS);
}
}
22 changes: 22 additions & 0 deletions src/Query/AbstractDateFormatParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace DoctrineExtensions\Query;

use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;

abstract class AbstractDateFormatParser extends FunctionNode
{
public function parse(\Doctrine\ORM\Query\Parser $parser): void
{
$orm3 = !defined('\Doctrine\ORM\Query\Lexer::T_IDENTIFIER');

$parser->match($orm3 ? TokenType::T_IDENTIFIER : Lexer::T_IDENTIFIER);
$parser->match($orm3 ? TokenType::T_OPEN_PARENTHESIS : Lexer::T_OPEN_PARENTHESIS);
$this->dateExpression = $parser->ArithmeticExpression();
$parser->match($orm3 ? TokenType::T_COMMA : Lexer::T_COMMA);
$this->patternExpression = $parser->StringPrimary();
$parser->match($orm3 ? TokenType::T_CLOSE_PARENTHESIS : Lexer::T_CLOSE_PARENTHESIS);
}
}
29 changes: 29 additions & 0 deletions src/Query/AbstractDoubleArithmeticExpressionParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace DoctrineExtensions\Query;

use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;

abstract class AbstractDoubleArithmeticExpressionParser extends FunctionNode
{
protected $firstArithmeticExpression;
protected $secondArithmeticExpression;

public function parse(\Doctrine\ORM\Query\Parser $parser): void
{
$orm3 = !defined('\Doctrine\ORM\Query\Lexer::T_IDENTIFIER');

$parser->match($orm3 ? TokenType::T_IDENTIFIER : Lexer::T_IDENTIFIER);
$parser->match($orm3 ? TokenType::T_OPEN_PARENTHESIS : Lexer::T_OPEN_PARENTHESIS);

$this->firstArithmeticExpression = $parser->SimpleArithmeticExpression();

$parser->match($orm3 ? TokenType::T_COMMA : Lexer::T_COMMA);

$this->secondArithmeticExpression = $parser->SimpleArithmeticExpression();

$parser->match($orm3 ? TokenType::T_CLOSE_PARENTHESIS : Lexer::T_CLOSE_PARENTHESIS);
}
}
30 changes: 30 additions & 0 deletions src/Query/AbstractDoubleArithmeticPrimaryParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace DoctrineExtensions\Query;

use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;

abstract class AbstractDoubleArithmeticPrimaryParser extends FunctionNode
{
protected $firstArithmeticPrimary = null;

protected $secondArithmeticPrimary = null;

public function parse(\Doctrine\ORM\Query\Parser $parser): void
{
$orm3 = !defined('\Doctrine\ORM\Query\Lexer::T_IDENTIFIER');

$parser->match($orm3 ? TokenType::T_IDENTIFIER : Lexer::T_IDENTIFIER);
$parser->match($orm3 ? TokenType::T_OPEN_PARENTHESIS : Lexer::T_OPEN_PARENTHESIS);

$this->firstArithmeticPrimary = $parser->ArithmeticPrimary();

$parser->match($orm3 ? TokenType::T_COMMA : Lexer::T_COMMA);

$this->secondArithmeticPrimary = $parser->ArithmeticPrimary();

$parser->match($orm3 ? TokenType::T_CLOSE_PARENTHESIS : Lexer::T_CLOSE_PARENTHESIS);
}
}
24 changes: 24 additions & 0 deletions src/Query/AbstractSingleArithmeticExpressionParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace DoctrineExtensions\Query;

use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;

abstract class AbstractSingleArithmeticExpressionParser extends FunctionNode
{
protected $arithmeticExpression;

public function parse(\Doctrine\ORM\Query\Parser $parser): void
{
$orm3 = !defined('\Doctrine\ORM\Query\Lexer::T_IDENTIFIER');

$parser->match($orm3 ? TokenType::T_IDENTIFIER : Lexer::T_IDENTIFIER);
$parser->match($orm3 ? TokenType::T_OPEN_PARENTHESIS : Lexer::T_OPEN_PARENTHESIS);

$this->arithmeticExpression = $parser->SimpleArithmeticExpression();

$parser->match($orm3 ? TokenType::T_CLOSE_PARENTHESIS : Lexer::T_CLOSE_PARENTHESIS);
}
}
28 changes: 28 additions & 0 deletions src/Query/AbstractSingleArithmeticPrimaryParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace DoctrineExtensions\Query;

use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;

abstract class AbstractSingleArithmeticPrimaryParser extends FunctionNode
{
protected $optional = false;

protected $arithmeticPrimary = null;

public function parse(\Doctrine\ORM\Query\Parser $parser): void
{
$orm3 = !defined('\Doctrine\ORM\Query\Lexer::T_IDENTIFIER');

$parser->match($orm3 ? TokenType::T_IDENTIFIER : Lexer::T_IDENTIFIER);
$parser->match($orm3 ? TokenType::T_OPEN_PARENTHESIS : Lexer::T_OPEN_PARENTHESIS);

if ($this->optional === false || ($this->optional === true && !$parser->getLexer()->isNextToken($orm3 ? TokenType::T_CLOSE_PARENTHESIS : Lexer::T_CLOSE_PARENTHESIS))) {
$this->arithmeticPrimary = $parser->ArithmeticPrimary();
}

$parser->match($orm3 ? TokenType::T_CLOSE_PARENTHESIS : Lexer::T_CLOSE_PARENTHESIS);
}
}
24 changes: 24 additions & 0 deletions src/Query/AbstractSingleStringPrimaryParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace DoctrineExtensions\Query;

use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;

abstract class AbstractSingleStringPrimaryParser extends FunctionNode
{
protected $stringPrimary = null;

public function parse(\Doctrine\ORM\Query\Parser $parser): void
{
$orm3 = !defined('\Doctrine\ORM\Query\Lexer::T_IDENTIFIER');

$parser->match($orm3 ? TokenType::T_IDENTIFIER : Lexer::T_IDENTIFIER);
$parser->match($orm3 ? TokenType::T_OPEN_PARENTHESIS : Lexer::T_OPEN_PARENTHESIS);

$this->stringPrimary = $parser->StringPrimary();

$parser->match($orm3 ? TokenType::T_CLOSE_PARENTHESIS : Lexer::T_CLOSE_PARENTHESIS);
}
}
31 changes: 31 additions & 0 deletions src/Query/AbstractWeekParser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace DoctrineExtensions\Query;

use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;

abstract class AbstractWeekParser extends FunctionNode
{
protected $arithmeticPrimary;

protected $mode;

public function parse(\Doctrine\ORM\Query\Parser $parser): void
{
$orm3 = !defined('\Doctrine\ORM\Query\Lexer::T_IDENTIFIER');

$parser->match($orm3 ? TokenType::T_IDENTIFIER : Lexer::T_IDENTIFIER);
$parser->match($orm3 ? TokenType::T_OPEN_PARENTHESIS : Lexer::T_OPEN_PARENTHESIS);

$this->arithmeticPrimary = $parser->ArithmeticPrimary();

if (($orm3 ? TokenType::T_COMMA : Lexer::T_COMMA) === $parser->getLexer()->lookahead->type) {
$parser->match($orm3 ? TokenType::T_COMMA : Lexer::T_COMMA);
$this->mode = $parser->Literal();
}

$parser->match($orm3 ? TokenType::T_CLOSE_PARENTHESIS : Lexer::T_CLOSE_PARENTHESIS);
}
}
16 changes: 3 additions & 13 deletions src/Query/Mysql/Acos.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,15 @@

use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;
use DoctrineExtensions\Query\AbstractSingleArithmeticExpressionParser;

class Acos extends FunctionNode
class Acos extends AbstractSingleArithmeticExpressionParser
{
public $arithmeticExpression;

public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker): string
{
return 'ACOS(' . $sqlWalker->walkSimpleArithmeticExpression(
$this->arithmeticExpression
) . ')';
}

public function parse(\Doctrine\ORM\Query\Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);

$this->arithmeticExpression = $parser->SimpleArithmeticExpression();

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}
}
24 changes: 4 additions & 20 deletions src/Query/Mysql/AddTime.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,16 @@

use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\TokenType;
use DoctrineExtensions\Query\AbstractDoubleArithmeticPrimaryParser;

/**
* @author Pascal Wacker <hello@pascalwacker.ch>
*/
class AddTime extends FunctionNode
class AddTime extends AbstractDoubleArithmeticPrimaryParser
{
public $date;

public $time;

public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker): string
{
return 'ADDTIME(' . $sqlWalker->walkArithmeticPrimary($this->date) . ', ' . $sqlWalker->walkArithmeticPrimary($this->time) . ')';
}

public function parse(\Doctrine\ORM\Query\Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);

$this->date = $parser->ArithmeticPrimary();

$parser->match(Lexer::T_COMMA);

$this->time = $parser->ArithmeticPrimary();

$parser->match(Lexer::T_CLOSE_PARENTHESIS);
return 'ADDTIME(' . $sqlWalker->walkArithmeticPrimary($this->firstArithmeticPrimary) . ', ' . $sqlWalker->walkArithmeticPrimary($this->secondArithmeticPrimary) . ')';
}
}
15 changes: 2 additions & 13 deletions src/Query/Mysql/AesDecrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,14 @@

namespace DoctrineExtensions\Query\Mysql;

use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Lexer;
use DoctrineExtensions\Query\AbstractCryptParser;

class AesDecrypt extends FunctionNode
class AesDecrypt extends AbstractCryptParser
{
public $field = '';

public $key = '';

public function parse(\Doctrine\ORM\Query\Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$this->field = $parser->StringExpression();
$parser->match(Lexer::T_COMMA);
$this->key = $parser->StringExpression();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}

public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker): string
{
return sprintf(
Expand Down
15 changes: 2 additions & 13 deletions src/Query/Mysql/AesEncrypt.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,14 @@

namespace DoctrineExtensions\Query\Mysql;

use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\Lexer;
use DoctrineExtensions\Query\AbstractCryptParser;

class AesEncrypt extends FunctionNode
class AesEncrypt extends AbstractCryptParser
{
public $field = '';

public $key = '';

public function parse(\Doctrine\ORM\Query\Parser $parser): void
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$this->field = $parser->StringExpression();
$parser->match(Lexer::T_COMMA);
$this->key = $parser->StringExpression();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}

public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker): string
{
return sprintf(
Expand Down
Loading

0 comments on commit daaa858

Please sign in to comment.