-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an internal trait to allow cross-version compatibility for ORM SQ…
…L walkers
- Loading branch information
Showing
5 changed files
with
455 additions
and
82 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
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,20 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Doctrine Behavioral Extensions package. | ||
* (c) Gediminas Morkevicius <gediminas.morkevicius@gmail.com> http://www.gediminasm.org | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Gedmo\Tool\ORM\Walker; | ||
|
||
use Doctrine\ORM\Query\SqlWalker; | ||
|
||
if ((new \ReflectionClass(SqlWalker::class))->getMethod('getExecutor')->hasReturnType()) { | ||
// ORM 3.x | ||
require_once __DIR__.'/orm-3.php'; | ||
} else { | ||
// ORM 2.x | ||
require_once __DIR__.'/orm-2.php'; | ||
} |
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,218 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Doctrine Behavioral Extensions package. | ||
* (c) Gediminas Morkevicius <gediminas.morkevicius@gmail.com> http://www.gediminasm.org | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Gedmo\Tool\ORM\Walker; | ||
|
||
use Doctrine\ORM\Query\AST; | ||
use Doctrine\ORM\Query\Exec; | ||
use Doctrine\ORM\Query\SqlWalker; | ||
|
||
/** | ||
* Helper trait to address compatibility issues between ORM 2.x and 3.x. | ||
* | ||
* @mixin SqlWalker | ||
* | ||
* @internal | ||
*/ | ||
trait SqlWalkerCompat | ||
{ | ||
/** | ||
* Gets an executor that can be used to execute the result of this walker. | ||
* | ||
* @param AST\SelectStatement|AST\UpdateStatement|AST\DeleteStatement $statement | ||
* | ||
* @return Exec\AbstractSqlExecutor | ||
*/ | ||
public function getExecutor($statement) | ||
{ | ||
return $this->doGetExecutorWithCompat($statement); | ||
} | ||
|
||
/** | ||
* Walks down a SelectStatement AST node, thereby generating the appropriate SQL. | ||
* | ||
* @param AST\SelectStatement $selectStatement | ||
* | ||
* @return string | ||
*/ | ||
public function walkSelectStatement($selectStatement) | ||
{ | ||
return $this->doWalkSelectStatementWithCompat($selectStatement); | ||
} | ||
|
||
/** | ||
* Walks down a SelectClause AST node, thereby generating the appropriate SQL. | ||
* | ||
* @param AST\SelectClause $selectClause | ||
* | ||
* @return string | ||
*/ | ||
public function walkSelectClause($selectClause) | ||
{ | ||
return $this->doWalkSelectClauseWithCompat($selectClause); | ||
} | ||
|
||
/** | ||
* Walks down a FromClause AST node, thereby generating the appropriate SQL. | ||
* | ||
* @param AST\FromClause $fromClause | ||
* | ||
* @return string | ||
*/ | ||
public function walkFromClause($fromClause) | ||
{ | ||
return $this->doWalkFromClauseWithCompat($fromClause); | ||
} | ||
|
||
/** | ||
* Walks down a OrderByClause AST node, thereby generating the appropriate SQL. | ||
* | ||
* @param AST\OrderByClause $orderByClause | ||
* | ||
* @return string | ||
*/ | ||
public function walkOrderByClause($orderByClause) | ||
{ | ||
return $this->doWalkOrderByClauseWithCompat($orderByClause); | ||
} | ||
|
||
/** | ||
* Walks down a HavingClause AST node, thereby generating the appropriate SQL. | ||
* | ||
* @param AST\HavingClause $havingClause | ||
* | ||
* @return string | ||
*/ | ||
public function walkHavingClause($havingClause) | ||
{ | ||
return $this->doWalkHavingClauseWithCompat($havingClause); | ||
} | ||
|
||
/** | ||
* Walks down a SubselectFromClause AST node, thereby generating the appropriate SQL. | ||
* | ||
* @param AST\SubselectFromClause $subselectFromClause | ||
* | ||
* @return string | ||
*/ | ||
public function walkSubselectFromClause($subselectFromClause) | ||
{ | ||
return $this->doWalkSubselectFromClauseWithCompat($subselectFromClause); | ||
} | ||
|
||
/** | ||
* Walks down a SimpleSelectClause AST node, thereby generating the appropriate SQL. | ||
* | ||
* @param AST\SimpleSelectClause $simpleSelectClause | ||
* | ||
* @return string | ||
*/ | ||
public function walkSimpleSelectClause($simpleSelectClause) | ||
{ | ||
return $this->doWalkSimpleSelectClauseWithCompat($simpleSelectClause); | ||
} | ||
|
||
/** | ||
* Walks down a GroupByClause AST node, thereby generating the appropriate SQL. | ||
* | ||
* @param AST\GroupByClause $groupByClause | ||
* | ||
* @return string | ||
*/ | ||
public function walkGroupByClause($groupByClause) | ||
{ | ||
return $this->doWalkGroupByClauseWithCompat($groupByClause); | ||
} | ||
|
||
/** | ||
* Walks down a DeleteClause AST node, thereby generating the appropriate SQL. | ||
* | ||
* @param AST\DeleteClause $deleteClause | ||
* | ||
* @return string | ||
*/ | ||
public function walkDeleteClause($deleteClause) | ||
{ | ||
return $this->doWalkDeleteClauseWithCompat($deleteClause); | ||
} | ||
|
||
/** | ||
* Walks down a WhereClause AST node, thereby generating the appropriate SQL. | ||
* | ||
* WhereClause or not, the appropriate discriminator sql is added. | ||
* | ||
* @param AST\WhereClause|null $whereClause | ||
* | ||
* @return string | ||
*/ | ||
public function walkWhereClause($whereClause) | ||
{ | ||
return $this->doWalkWhereClauseWithCompat($whereClause); | ||
} | ||
|
||
/** | ||
* Gets an executor that can be used to execute the result of this walker. | ||
* | ||
* @param AST\SelectStatement|AST\UpdateStatement|AST\DeleteStatement $statement | ||
*/ | ||
protected function doGetExecutorWithCompat($statement): Exec\AbstractSqlExecutor | ||
{ | ||
return parent::getExecutor($statement); | ||
} | ||
|
||
protected function doWalkSelectStatementWithCompat(AST\SelectStatement $selectStatement): string | ||
{ | ||
return parent::walkSelectStatement($selectStatement); | ||
} | ||
|
||
protected function doWalkSelectClauseWithCompat(AST\SelectClause $selectClause): string | ||
{ | ||
return parent::walkSelectClause($selectClause); | ||
} | ||
|
||
protected function doWalkFromClauseWithCompat(AST\FromClause $fromClause): string | ||
{ | ||
return parent::walkFromClause($fromClause); | ||
} | ||
|
||
protected function doWalkOrderByClauseWithCompat(AST\OrderByClause $orderByClause): string | ||
{ | ||
return parent::walkOrderByClause($orderByClause); | ||
} | ||
|
||
protected function doWalkHavingClauseWithCompat(AST\HavingClause $havingClause): string | ||
{ | ||
return parent::walkHavingClause($havingClause); | ||
} | ||
|
||
protected function doWalkSubselectFromClauseWithCompat(AST\SubselectFromClause $subselectFromClause): string | ||
{ | ||
return parent::walkSubselectFromClause($subselectFromClause); | ||
} | ||
|
||
protected function doWalkSimpleSelectClauseWithCompat(AST\SimpleSelectClause $simpleSelectClause): string | ||
{ | ||
return parent::walkSimpleSelectClause($simpleSelectClause); | ||
} | ||
|
||
protected function doWalkGroupByClauseWithCompat(AST\GroupByClause $groupByClause): string | ||
{ | ||
return parent::walkGroupByClause($groupByClause); | ||
} | ||
|
||
protected function doWalkDeleteClauseWithCompat(AST\DeleteClause $deleteClause): string | ||
{ | ||
return parent::walkDeleteClause($deleteClause); | ||
} | ||
|
||
protected function doWalkWhereClauseWithCompat(?AST\WhereClause $whereClause): string | ||
{ | ||
return parent::walkWhereClause($whereClause); | ||
} | ||
} |
Oops, something went wrong.