This repository has been archived by the owner on Sep 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert changes to PersistenceModel->select and move to ->query
- Loading branch information
Showing
6 changed files
with
238 additions
and
55 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 |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace CsrDelft\Orm\Common; | ||
|
||
/** | ||
* @author G.J.W. Oolbekkink <g.j.w.oolbekkink@gmail.com> | ||
* @date 29/10/2017 | ||
*/ | ||
abstract class Enum { | ||
/** | ||
* Error constants. | ||
*/ | ||
const ERROR_CHOICE_NOT_SUPPORTED = 'Choice "%s" not supported.'; | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
protected static $supportedChoices = []; | ||
|
||
/** | ||
* @var string Current choice | ||
*/ | ||
protected $choice; | ||
|
||
/** | ||
* Enum constructor. | ||
* @param string $choice | ||
* @throws OrmException | ||
*/ | ||
public function __construct($choice) { | ||
|
||
if (isset(static::$supportedChoices[$choice])) { | ||
$this->choice = $choice; | ||
} else { | ||
throw new OrmException(sprintf(self::ERROR_CHOICE_NOT_SUPPORTED, $choice)); | ||
} | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getChoice() { | ||
return $this->choice; | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
|
||
namespace CsrDelft\Orm\Query; | ||
use CsrDelft\Orm\Common\Enum; | ||
|
||
/** | ||
* @author G.J.W. Oolbekkink <g.j.w.oolbekkink@gmail.com> | ||
* @date 02/11/2017 | ||
*/ | ||
class OrderDirection extends Enum { | ||
/** | ||
* Possible choices. | ||
*/ | ||
const CHOICE_ASC = 'ASC'; | ||
const CHOICE_DESC = 'DESC'; | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
protected static $supportedChoices = [ | ||
self::CHOICE_ASC => self::CHOICE_ASC, | ||
self::CHOICE_DESC => self::CHOICE_DESC, | ||
]; | ||
|
||
/** | ||
* @return OrderDirection | ||
*/ | ||
public static function ASC() { | ||
return new static(self::CHOICE_ASC); | ||
} | ||
|
||
/** | ||
* @return OrderDirection | ||
*/ | ||
public static function DESC() { | ||
return new static(self::CHOICE_DESC); | ||
} | ||
} |
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,84 @@ | ||
<?php | ||
|
||
namespace CsrDelft\Orm\Query; | ||
|
||
use CsrDelft\Orm\Common\Enum; | ||
|
||
/** | ||
* @author G.J.W. Oolbekkink <g.j.w.oolbekkink@gmail.com> | ||
* @date 29/10/2017 | ||
*/ | ||
class SelectMode extends Enum { | ||
/** | ||
* Select type constants. | ||
*/ | ||
const TYPE_EXACT = 'exact'; | ||
const TYPE_IEXACT = 'iexact'; | ||
const TYPE_CONTAINS = 'contains'; | ||
const TYPE_ICONTAINS = 'icontains'; | ||
const TYPE_STARTSWITH = 'startswith'; | ||
const TYPE_ISTARTSWITH = 'istartswith'; | ||
const TYPE_ENDSWITH = 'endswith'; | ||
const TYPE_IENDSWITH = 'iendswith'; | ||
const TYPE_LT = 'lt'; | ||
const TYPE_LTE = 'lte'; | ||
const TYPE_GT = 'gt'; | ||
const TYPE_GTE = 'gte'; | ||
|
||
/** | ||
* Sql operator constants. | ||
*/ | ||
const COLLATE_CASE_SENSITIVE = 'COLLATE \'utf8_bin\' '; | ||
const OPERATOR_ENDSWITH = 'LIKE \'%\''; | ||
const OPERATOR_STARTSWITH = 'LIKE ? || \'%\''; | ||
const OPERATOR_CONTAINS = 'LIKE \'%\' || ? || \'%\''; | ||
const OPERATOR_EXACT = '= ?'; | ||
const OPERATOR_LT = '< ?'; | ||
const OPERATOR_LTE = '<= ?'; | ||
const OPERATOR_GT = '> ?'; | ||
const OPETAROR_GTE = '>= ?'; | ||
const SQL_AND = ' AND '; | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
protected static $supportedChoices = [ | ||
self::TYPE_EXACT => self::TYPE_EXACT, | ||
self::TYPE_IEXACT => self::TYPE_IEXACT, | ||
self::TYPE_CONTAINS => self::TYPE_CONTAINS, | ||
self::TYPE_ICONTAINS => self::TYPE_ICONTAINS, | ||
self::TYPE_STARTSWITH => self::TYPE_STARTSWITH, | ||
self::TYPE_ISTARTSWITH => self::TYPE_ISTARTSWITH, | ||
self::TYPE_ENDSWITH => self::TYPE_ENDSWITH, | ||
self::TYPE_IENDSWITH => self::TYPE_IENDSWITH, | ||
self::TYPE_LT => self::TYPE_LT, | ||
self::TYPE_LTE => self::TYPE_LTE, | ||
self::TYPE_GT => self::TYPE_GT, | ||
self::TYPE_GTE => self::TYPE_GTE, | ||
]; | ||
|
||
/** | ||
* @var string[] | ||
*/ | ||
protected static $typeToOperator = [ | ||
self::TYPE_EXACT => self::COLLATE_CASE_SENSITIVE . self::OPERATOR_EXACT, | ||
self::TYPE_IEXACT => self::OPERATOR_EXACT, | ||
self::TYPE_CONTAINS => self::COLLATE_CASE_SENSITIVE . self::OPERATOR_CONTAINS, | ||
self::TYPE_ICONTAINS => self::OPERATOR_CONTAINS, | ||
self::TYPE_STARTSWITH => self::COLLATE_CASE_SENSITIVE . self::OPERATOR_STARTSWITH, | ||
self::TYPE_ISTARTSWITH => self::OPERATOR_STARTSWITH, | ||
self::TYPE_ENDSWITH => self::COLLATE_CASE_SENSITIVE . self::OPERATOR_ENDSWITH, | ||
self::TYPE_IENDSWITH => self::OPERATOR_ENDSWITH, | ||
self::TYPE_LT => self::OPERATOR_LT, | ||
self::TYPE_LTE => self::OPERATOR_LTE, | ||
self::TYPE_GT => self::OPERATOR_GT, | ||
self::TYPE_GTE => self::OPETAROR_GTE, | ||
]; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getOperator() { | ||
return static::$typeToOperator[$this->choice]; | ||
} | ||
} |
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