-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add orm3 compatibility and simplifying with abstract classes
- Loading branch information
Showing
191 changed files
with
1,399 additions
and
1,955 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,15 +9,16 @@ | |
{"name": "Steve Lacey", "email": "[email protected]"} | ||
], | ||
"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": "^3.47.0", | ||
"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" | ||
}, | ||
|
@@ -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" | ||
} |
This file contains 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
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); | ||
} | ||
} |
This file contains 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
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); | ||
} | ||
} |
This file contains 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
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); | ||
} | ||
} |
This file contains 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
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); | ||
} | ||
} |
This file contains 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
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); | ||
} | ||
} |
This file contains 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
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); | ||
} | ||
} |
This file contains 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
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); | ||
} | ||
} |
This file contains 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
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); | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 <[email protected]> | ||
*/ | ||
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) . ')'; | ||
} | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.