-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #280 from peter-gribanov/BaseSpecification_location
Сorrect location of BaseSpecification class
- Loading branch information
Showing
4 changed files
with
100 additions
and
74 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
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,91 @@ | ||
<?php | ||
|
||
/** | ||
* This file is part of the Happyr Doctrine Specification package. | ||
* | ||
* (c) Tobias Nyholm <tobias@happyr.com> | ||
* Kacper Gunia <kacper@gunia.me> | ||
* Peter Gribanov <info@peter-gribanov.ru> | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Happyr\DoctrineSpecification\Specification; | ||
|
||
use Doctrine\ORM\QueryBuilder; | ||
use Happyr\DoctrineSpecification\Filter\Filter; | ||
use Happyr\DoctrineSpecification\Query\QueryModifier; | ||
|
||
/** | ||
* Extend this abstract class if you want to build a new spec with your domain logic. | ||
*/ | ||
abstract class BaseSpecification implements Specification | ||
{ | ||
/** | ||
* @var string|null | ||
*/ | ||
private $dqlAlias; | ||
|
||
/** | ||
* @param string|null $dqlAlias | ||
*/ | ||
public function __construct($dqlAlias = null) | ||
{ | ||
$this->dqlAlias = $dqlAlias; | ||
} | ||
|
||
/** | ||
* @param QueryBuilder $qb | ||
* @param string $dqlAlias | ||
* | ||
* @return string | ||
*/ | ||
public function getFilter(QueryBuilder $qb, $dqlAlias) | ||
{ | ||
$spec = $this->getSpec(); | ||
if ($spec instanceof Filter) { | ||
return $spec->getFilter($qb, $this->getAlias($dqlAlias)); | ||
} | ||
|
||
return ''; | ||
} | ||
|
||
/** | ||
* @param QueryBuilder $qb | ||
* @param string $dqlAlias | ||
*/ | ||
public function modify(QueryBuilder $qb, $dqlAlias) | ||
{ | ||
$spec = $this->getSpec(); | ||
if ($spec instanceof QueryModifier) { | ||
$spec->modify($qb, $this->getAlias($dqlAlias)); | ||
} | ||
} | ||
|
||
/** | ||
* Return all the specifications. | ||
* | ||
* @return Filter|QueryModifier|null | ||
*/ | ||
protected function getSpec() | ||
{ | ||
@trigger_error('Using the default implementation of '.__METHOD__.' method is deprecated since version 1.1 and this method will be marked as abstract in 2.0. You must overwrite this implementation.', E_USER_DEPRECATED); | ||
|
||
return null; | ||
} | ||
|
||
/** | ||
* @param string $dqlAlias | ||
* | ||
* @return string | ||
*/ | ||
private function getAlias($dqlAlias) | ||
{ | ||
if (null !== $this->dqlAlias) { | ||
return $this->dqlAlias; | ||
} | ||
|
||
return $dqlAlias; | ||
} | ||
} |