-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
64f2733
commit b4f91d5
Showing
3 changed files
with
139 additions
and
124 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,33 @@ | ||
<?php | ||
|
||
namespace LaravelFreelancerNL\FluentAQL\Traits; | ||
|
||
trait ValidatesOperators | ||
{ | ||
/** | ||
* @param mixed $operator | ||
* @return bool | ||
*/ | ||
public function isLogicalOperator($operator): bool | ||
{ | ||
return isset($this->logicalOperators[strtoupper($operator)]); | ||
} | ||
|
||
/** | ||
* @param mixed $operator | ||
* @return bool | ||
*/ | ||
public function isComparisonOperator($operator): bool | ||
{ | ||
return isset($this->comparisonOperators[strtoupper($operator)]); | ||
} | ||
|
||
/** | ||
* @param mixed $operator | ||
* @return bool | ||
*/ | ||
public function isArithmeticOperator($operator): bool | ||
{ | ||
return isset($this->arithmeticOperators[$operator]); | ||
} | ||
} |
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,104 @@ | ||
<?php | ||
|
||
namespace LaravelFreelancerNL\FluentAQL\Traits; | ||
|
||
trait ValidatesReferences | ||
{ | ||
/** | ||
* @param mixed $value | ||
* | ||
* @return bool | ||
*/ | ||
public function isBind($value): bool | ||
{ | ||
if (is_string($value)) { | ||
return true; | ||
} | ||
if (is_object($value)) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* @param mixed $value | ||
* | ||
* @return bool | ||
*/ | ||
public function isCollectionBind($value): bool | ||
{ | ||
if (is_string($value)) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* @param mixed $value | ||
* | ||
* @return bool | ||
*/ | ||
public function isVariable($value): bool | ||
{ | ||
if (is_string($value) && preg_match('/^\$?[a-zA-Z_][a-zA-Z0-9_]*+$/', $value)) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* @param mixed $value | ||
* @param array $registeredVariables | ||
* @return bool | ||
*/ | ||
public function isRegisteredVariable($value, $registeredVariables = []): bool | ||
{ | ||
return isset($registeredVariables[$value]); | ||
} | ||
|
||
/** | ||
* @param mixed $value | ||
* | ||
* @return bool | ||
*/ | ||
public function isAttribute($value): bool | ||
{ | ||
$pattern = '/^(@?[\d\w_]+|`@?[\d\w_]+`)(\[\`.+\`\]|\[[\d\w\*]*\])*' | ||
. '(\.(\`.+\`|@?[\d\w]*)(\[\`.+\`\]|\[[\d\w\*]*\])*)*$/'; | ||
if ( | ||
is_string($value) && | ||
preg_match($pattern, $value) | ||
) { | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
/** | ||
* @param mixed $value | ||
* @param array $registeredVariables | ||
* @return bool | ||
*/ | ||
public function isReference($value, $registeredVariables = []): bool | ||
{ | ||
$variables = ''; | ||
if (!empty($registeredVariables)) { | ||
$variables = implode('|', $registeredVariables); | ||
} | ||
|
||
if (! is_string($value) || empty($value)) { | ||
return false; | ||
} | ||
|
||
return (bool) preg_match( | ||
'/^(' | ||
. $variables | ||
. '|CURRENT|NEW|OLD)(\[\`.+\`\]|\[[\d\w\*]*\])*(\.(\`.+\`|@?[\d\w]*)(\[\`.+\`\]|\[[\d\w\*]*\])*)*$/', | ||
$value | ||
); | ||
} | ||
} |