Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
447430b7bb | ||
|
|
00093b0398 | ||
|
|
1dcf32e0da |
No files matched your search
+3
-3
@@ -10,12 +10,12 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"require": {
|
"require": {
|
||||||
"mcnd/notes": "^2.1.1"
|
"mcnd/notes": "dev-master"
|
||||||
},
|
},
|
||||||
"repositories": [
|
"repositories": [
|
||||||
{
|
{
|
||||||
"type": "composer",
|
"type": "vcs",
|
||||||
"url": "https://git.mcnd.ca/api/packages/mcndave/composer"
|
"url": "https://github.com/mcNdave/notes.git"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"autoload": {
|
"autoload": {
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
#### Date Field Symbol Table
|
|
||||||
|
|
||||||
source: https://unicode-org.github.io/icu/userguide/format_parse/datetime/#date-field-symbol-table
|
|
||||||
|
|
||||||
| Symbol | Meaning | Pattern | Example Output |
|
|
||||||
| --- | --- | --- | --- |
|
|
||||||
| `G` | era designator | `G`, `GG`, or `GGG`<br/>`GGGG`<br/>`GGGGG` | AD<br/>Anno Domini<br/>A |
|
|
||||||
| `y` | year | `yy`<br/>`y` or `yyyy` | 96<br/>1996 |
|
|
||||||
| `Y` | year in “Week of Year” based calendars in which the year transition occurs on a week boundary; may differ from calendar year ‘y’ near a year transition. This year designation is used with pattern character ‘w’ in the ISO 8601 year-week calendar, for example. | `Y` | 1997 |
|
|
||||||
| `u` | extended year | `u` | 4601 |
|
|
||||||
| `U` | cyclic year name, as in Chinese lunar calendar | `U` | 甲子 |
|
|
||||||
| `r` | related Gregorian year | `r` | 1996 |
|
|
||||||
| `Q` | quarter | `Q`<br/>`QQ`<br/>`QQQ`<br/>`QQQQ`<br/>`QQQQQ` | 2<br/>02<br/>Q2<br/>2nd quarter<br/>2 |
|
|
||||||
| `q` | stand-alone quarter | `q`<br/>`qq`<br/>`qqq`<br/>`qqqq`<br/>`qqqqq` | 2<br/>02<br/>Q2<br/>2nd quarter<br/>2 |
|
|
||||||
| `M` | month in year | `M`<br/>`MM`<br/>`MMM`<br/>`MMMM`<br/>`MMMMM` | 9<br/>09<br/>Sep<br/>September<br/>S |
|
|
||||||
| `L` | stand-alone month in year | `L`<br/>`LL`<br/>`LLL`<br/>`LLLL`<br/>`LLLLL` | 9<br/>09<br/>Sep<br/>September<br/>S |
|
|
||||||
| `w` | week of year | `w`<br/>`ww` | 27<br/>27 |
|
|
||||||
| `W` | week of month | `W` | 2 |
|
|
||||||
| `d` | day in month | `d`<br/>`dd` | 2<br/>02 |
|
|
||||||
| `D` | day of year | `D` | 189 |
|
|
||||||
| `F` | day of week in month | `F` | 2 (2nd Wed in July) |
|
|
||||||
| `g` | modified julian day | `g` | 2451334 |
|
|
||||||
| `E` | day of week | `E,` `EE`, or `EEE`<br/>`EEEE`<br/>`EEEEE`<br/>`EEEEEE` | Tue<br/>Tuesday<br/>T<br/>Tu |
|
|
||||||
| `e` | local day of week<br/>example: if Monday is 1st day, Tuesday is 2nd ) | `e`<br>`ee`<br/>`eee`<br/>`eeee`<br/>`eeeee`<br/>`eeeeee` | 2<br>02<br/>Tue<br/>Tuesday<br/>T<br/>Tu |
|
|
||||||
| `c` | stand-alone local day of week | `c` or `cc`<br/>`ccc`<br/>`cccc`<br/>`ccccc`<br/>`cccccc` | 2<br/>Tue<br/>Tuesday<br/>T<br/>Tu |
|
|
||||||
| `a` | AM or PM | `a`, `aa`, or `aaa`<br/>`aaaa`<br/>`aaaaa` | PM [abbrev]<br/>PM [wide]<br/>p |
|
|
||||||
| `b` | am, pm, noon, midnight | `b`, `bb`, or `bbb`<br/>`bbbb`<br/>`bbbbb` | mid.<br/>midnight<br/>md |
|
|
||||||
| `B` | flexible day periods | `B`, `BB`, or `BBB`<br/>`BBBB`<br/>`BBBBB` | at night [abbrev]<br/>at night [wide]<br/>at night [narrow] |
|
|
||||||
| `h` | hour in am/pm (1~12) | `h`<br/>`hh` | 7<br/>07 |
|
|
||||||
| `H` | hour in day (0~23) | `H`<br/>`HH` | 0<br/>00 |
|
|
||||||
| `k` | hour in day (1~24) | `k`<br/>`kk` | 24<br/>24 |
|
|
||||||
| `K` | hour in am/pm (0~11) | `K`<br/>`KK` | 0<br/>00 |
|
|
||||||
| `m` | minute in hour | `m`<br/>`mm` | 4<br/>04 |
|
|
||||||
| `s` | second in minute | `s`<br/>`ss` | 5<br/>05 |
|
|
||||||
| `S` | fractional second - truncates (like other time fields)<br/>to the count of letters when formatting. Appends<br/>zeros if more than 3 letters specified. Truncates at<br/>three significant digits when parsing. | `S`<br/>`SS`<br/>`SSS`<br/>`SSSS` | 2<br/>23<br/>235<br/>2350 |
|
|
||||||
| `A` | milliseconds in day | `A` | 61201235 |
|
|
||||||
| `z` | Time Zone: specific non-location | `z`, `zz`, or `zzz`<br/>`zzzz` | PDT<br/>Pacific Daylight Time |
|
|
||||||
| `Z` | Time Zone: ISO8601 basic hms? / RFC 822<br/>Time Zone: long localized GMT (=OOOO)<br/>Time Zone: ISO8601 extended hms? (=XXXXX) | `Z`, `ZZ`, or `ZZZ`<br/>`ZZZZ`<br/>`ZZZZZ` | -0800<br/>GMT-08:00<br/>-08:00, -07:52:58, Z |
|
|
||||||
| `O` | Time Zone: short localized GMT<br/>Time Zone: long localized GMT (=ZZZZ) | `O`<br/>`OOOO` | GMT-8<br/>GMT-08:00 |
|
|
||||||
| `v` | Time Zone: generic non-location<br/>(falls back first to VVVV) | `v`<br/>`vvvv` | PT<br/>Pacific Time or Los Angeles Time |
|
|
||||||
| `V` | Time Zone: short time zone ID<br/>Time Zone: long time zone ID<br/>Time Zone: time zone exemplar city<br/>Time Zone: generic location (falls back to OOOO) | `V`<br/>`VV`<br/>`VVV`<br/>`VVVV` | uslax<br/>America/Los_Angeles<br/>Los Angeles<br/>Los Angeles Time |
|
|
||||||
| `X` | Time Zone: ISO8601 basic hm?, with Z for 0<br/>Time Zone: ISO8601 basic hm, with Z<br/>Time Zone: ISO8601 extended hm, with Z<br/>Time Zone: ISO8601 basic hms?, with Z<br/>Time Zone: ISO8601 extended hms?, with Z | `X`<br/>`XX`<br/>`XXX`<br/>`XXXX`<br/>`XXXXX` | -08, +0530, Z<br/>-0800, Z<br/>-08:00, Z<br/>-0800, -075258, Z<br/>-08:00, -07:52:58, Z |
|
|
||||||
| `x` | Time Zone: ISO8601 basic hm?, without Z for 0<br/>Time Zone: ISO8601 basic hm, without Z<br/>Time Zone: ISO8601 extended hm, without Z<br/>Time Zone: ISO8601 basic hms?, without Z<br/>Time Zone: ISO8601 extended hms?, without Z | `x`<br/>`xx`<br/>`xxx`<br/>`xxxx`<br/>`xxxxx` | -08, +0530<br/>-0800<br/>-08:00<br/>-0800, -075258<br/>-08:00, -07:52:58 |
|
|
||||||
| `'` | escape for text | `'` | (nothing) |
|
|
||||||
| `''` | two single quotes produce one | `''` | ' |
|
|
||||||
|
|
||||||
> :point_right: **Note**: *Any characters in the pattern that are not in the ranges of
|
|
||||||
['a'..'z'] and ['A'..'Z'] will be treated as quoted text. For instance,
|
|
||||||
characters like `':'`, `'.'`, `' '`, `'#'` and `'@'` will appear in the resulting time
|
|
||||||
text even they are not enclosed within single quotes. The single quote is used to
|
|
||||||
'escape' letters. Two single quotes in a row, whether inside or outside a quoted
|
|
||||||
sequence, represent a 'real' single quote.*
|
|
||||||
|
|
||||||
> :point_right: **Note**: *A pattern containing any invalid pattern letter results in a failing `UErrorCode`
|
|
||||||
result during formatting or parsing.*
|
|
||||||
|
|
||||||
| Format Pattern | Result |
|
|
||||||
| --- | --- |
|
|
||||||
| `"yyyy.MM.dd G 'at' HH:mm:ss zzz"` | "1996.07.10 AD at 15:08:56 PDT" |
|
|
||||||
| `"EEE, MMM d, ''yy"` | "Wed, July 10, '96" |
|
|
||||||
| `"h:mm a"` | "12:08 PM" |
|
|
||||||
| `"hh 'o''clock' a, zzzz"` | "12 o'clock PM, Pacific Daylight Time" |
|
|
||||||
| `"K:mm a, z"` | "0:00 PM, PST" |
|
|
||||||
| `"yyyyy.MMMM.dd GGG hh:mm aaa"` | "01996.July.10 AD 12:08 PM" |
|
|
||||||
@@ -79,7 +79,7 @@ class MySQL implements AdapterInterface, MigrateInterface, SqlAdapterInterface {
|
|||||||
$pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
|
$pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
|
||||||
$pdo->setAttribute(\PDO::ATTR_AUTOCOMMIT, false);
|
$pdo->setAttribute(\PDO::ATTR_AUTOCOMMIT, false);
|
||||||
$pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC);
|
$pdo->setAttribute(\PDO::ATTR_DEFAULT_FETCH_MODE, \PDO::FETCH_ASSOC);
|
||||||
$pdo->setAttribute(\Pdo\Mysql::ATTR_USE_BUFFERED_QUERY, false);
|
$pdo->setAttribute(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
|
||||||
}
|
}
|
||||||
catch(\PDOException $ex){
|
catch(\PDOException $ex){
|
||||||
throw $ex;
|
throw $ex;
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ use Ulmus\Repository;
|
|||||||
|
|
||||||
class Attribute
|
class Attribute
|
||||||
{
|
{
|
||||||
public static function handleArrayField(null|\Stringable|string|array $field, null|string|false $alias = Repository::DEFAULT_ALIAS, string $separator = ', ') : mixed
|
public static function handleArrayField(null|\Stringable|string|array $field, null|string|bool $alias = Repository::DEFAULT_ALIAS, string $separator = ', ') : mixed
|
||||||
{
|
{
|
||||||
if ( is_array($field) ) {
|
if ( is_array($field) ) {
|
||||||
if (count($field) < 2) {
|
if (count($field) < 2) {
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class Where {
|
|||||||
public null|array|\Closure $generateValue = null,
|
public null|array|\Closure $generateValue = null,
|
||||||
) {
|
) {
|
||||||
$this->field = Attribute::handleArrayField($field);
|
$this->field = Attribute::handleArrayField($field);
|
||||||
$this->fieldValue = Attribute::handleArrayField($fieldValue, false);
|
$this->fieldValue = Attribute::handleArrayField($fieldValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getValue(/* null|EntityInterface */ $entity = null) : mixed
|
public function getValue(/* null|EntityInterface */ $entity = null) : mixed
|
||||||
|
|||||||
+1
-1
@@ -59,7 +59,7 @@ trait CacheTrait
|
|||||||
$this->eventRegister(new class($this->cache, $this->entityCacheKey()) implements Event\Query\Update {
|
$this->eventRegister(new class($this->cache, $this->entityCacheKey()) implements Event\Query\Update {
|
||||||
use Cache\CacheEventTrait;
|
use Cache\CacheEventTrait;
|
||||||
|
|
||||||
public function execute(RepositoryInterface $repository, object|array $entity, array $dataset, array $diff, bool $replace = false): void
|
public function execute(RepositoryInterface $repository, object|array $entity, ?array $dataset = null, bool $replace = false): void
|
||||||
{
|
{
|
||||||
$this->purgeCache();
|
$this->purgeCache();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ class EntityResolver {
|
|||||||
|
|
||||||
public string $entityClass;
|
public string $entityClass;
|
||||||
|
|
||||||
public readonly ReflectedClass $reflectedClass;
|
public ReflectedClass $reflectedClass;
|
||||||
|
|
||||||
protected array $fieldList = [];
|
protected array $fieldList = [];
|
||||||
|
|
||||||
@@ -129,11 +129,6 @@ class EntityResolver {
|
|||||||
return $this->reflectedClass->getProperties(true)[$name]->getTypes()[0]->type ?? false;
|
return $this->reflectedClass->getProperties(true)[$name]->getTypes()[0]->type ?? false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function searchPropertyAttributeList(array|string $className, bool $deepSearch = true) : array
|
|
||||||
{
|
|
||||||
return $this->reflectedClass->getPropertyAttributeListFromClassname($className, $deepSearch, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function searchFieldAnnotation(string $field, array|object|string $annotationType, bool $caseSensitive = true) : ? object
|
public function searchFieldAnnotation(string $field, array|object|string $annotationType, bool $caseSensitive = true) : ? object
|
||||||
{
|
{
|
||||||
return $this->searchFieldAnnotationList($field, $annotationType, $caseSensitive)[0] ?? null;
|
return $this->searchFieldAnnotationList($field, $annotationType, $caseSensitive)[0] ?? null;
|
||||||
@@ -141,6 +136,8 @@ class EntityResolver {
|
|||||||
|
|
||||||
public function searchFieldAnnotationList(string $field, array|object|string $attributeType, bool $caseSensitive = true) : false|array
|
public function searchFieldAnnotationList(string $field, array|object|string $attributeType, bool $caseSensitive = true) : false|array
|
||||||
{
|
{
|
||||||
|
$list = [];
|
||||||
|
|
||||||
$properties = $this->reflectedClass->getProperties(true);
|
$properties = $this->reflectedClass->getProperties(true);
|
||||||
|
|
||||||
$search = $caseSensitive ? $properties : array_change_key_case($properties, \CASE_LOWER);
|
$search = $caseSensitive ? $properties : array_change_key_case($properties, \CASE_LOWER);
|
||||||
|
|||||||
@@ -1,8 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Ulmus\Entity\Field;
|
|
||||||
|
|
||||||
class Date extends DatetimeImmutable {
|
|
||||||
|
|
||||||
public string $format = "Y-m-d";
|
|
||||||
}
|
|
||||||
@@ -5,5 +5,66 @@ namespace Ulmus\Entity\Field;
|
|||||||
use Ulmus\Entity\EntityObjectInterface;
|
use Ulmus\Entity\EntityObjectInterface;
|
||||||
|
|
||||||
class Datetime extends \DateTime implements EntityObjectInterface, \JsonSerializable {
|
class Datetime extends \DateTime implements EntityObjectInterface, \JsonSerializable {
|
||||||
use DatetimeTrait;
|
|
||||||
}
|
public string $format = "Y-m-d H:i:s";
|
||||||
|
|
||||||
|
public function load(mixed ...$arguments)
|
||||||
|
{
|
||||||
|
$value = $arguments[0];
|
||||||
|
|
||||||
|
try {
|
||||||
|
# From Timestamp
|
||||||
|
if ( is_numeric($value) ) {
|
||||||
|
$obj = new static("@$value");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$obj = new static($value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(\Throwable $ex) {
|
||||||
|
throw new \Exception(sprintf("An error occured trying to instanciate from '%s'. %s", $value, $ex->getMessage()), $ex->getCode(), $ex);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $obj;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTime($hour, $minute, $second = 0, $microsecond = 0) : \DateTime
|
||||||
|
{
|
||||||
|
$fromParent = parent::setTime($hour, $minute, $second, $microsecond);
|
||||||
|
|
||||||
|
return new static($fromParent);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function save()
|
||||||
|
{
|
||||||
|
return $this->__toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __toString()
|
||||||
|
{
|
||||||
|
return $this->format($this->format);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[\Deprecated]
|
||||||
|
public function formatLocale(string $format) : string
|
||||||
|
{
|
||||||
|
return strftime($format, $this->getTimestamp());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function formatLocaleIntl(int $dateFormatter = \IntlDateFormatter::LONG, int $timeFormatter = \IntlDateFormatter::NONE, ? string $pattern = null) : string
|
||||||
|
{
|
||||||
|
$formatter = new \IntlDateFormatter(\Locale::getDefault(), $dateFormatter, $timeFormatter, \date_default_timezone_get(), \IntlDateFormatter::GREGORIAN, $pattern);
|
||||||
|
|
||||||
|
return $formatter->format($this->getTimestamp());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function ageAt(null|\DateTime $dateTime) : int
|
||||||
|
{
|
||||||
|
return (int) ( (int) ($dateTime ?: new DateTime())->format('Ymd') - (int) $this->format('Ymd') ) / 10000;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function jsonSerialize(): mixed
|
||||||
|
{
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Ulmus\Entity\Field;
|
|
||||||
|
|
||||||
use Ulmus\Entity\EntityObjectInterface;
|
|
||||||
|
|
||||||
class DatetimeImmutable extends \DateTimeImmutable implements EntityObjectInterface {
|
|
||||||
use DatetimeTrait;
|
|
||||||
}
|
|
||||||
@@ -1,70 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Ulmus\Entity\Field;
|
|
||||||
|
|
||||||
trait DatetimeTrait
|
|
||||||
{
|
|
||||||
public string $format = "Y-m-d H:i:s";
|
|
||||||
|
|
||||||
public function load(mixed ...$arguments)
|
|
||||||
{
|
|
||||||
$value = $arguments[0];
|
|
||||||
|
|
||||||
try {
|
|
||||||
# From Timestamp
|
|
||||||
if ( is_numeric($value) ) {
|
|
||||||
$obj = new static("@$value");
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$obj = new static($value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch(\Throwable $ex) {
|
|
||||||
throw new \Exception(sprintf("An error occured trying to instanciate from '%s'. %s", $value, $ex->getMessage()), $ex->getCode(), $ex);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $obj;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setTime($hour, $minute, $second = 0, $microsecond = 0) : \DateTime
|
|
||||||
{
|
|
||||||
$fromParent = parent::setTime($hour, $minute, $second, $microsecond);
|
|
||||||
|
|
||||||
return new static($fromParent);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function save()
|
|
||||||
{
|
|
||||||
return $this->__toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function __toString()
|
|
||||||
{
|
|
||||||
return $this->format($this->format);
|
|
||||||
}
|
|
||||||
|
|
||||||
#[\Deprecated]
|
|
||||||
public function formatLocale(string $format) : string
|
|
||||||
{
|
|
||||||
return strftime($format, $this->getTimestamp());
|
|
||||||
}
|
|
||||||
|
|
||||||
# patterns: https://unicode-org.github.io/icu/userguide/format_parse/datetime/#date-field-symbol-table
|
|
||||||
# see also 100-datetime-format.md file in DOC
|
|
||||||
public function formatLocaleIntl(int $dateFormatter = \IntlDateFormatter::LONG, int $timeFormatter = \IntlDateFormatter::NONE, ? string $pattern = null) : string
|
|
||||||
{
|
|
||||||
$formatter = new \IntlDateFormatter(\Locale::getDefault(), $dateFormatter, $timeFormatter, \date_default_timezone_get(), \IntlDateFormatter::GREGORIAN, $pattern);
|
|
||||||
|
|
||||||
return $formatter->format($this->getTimestamp());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function ageAt(null|\DateTime $dateTime) : int
|
|
||||||
{
|
|
||||||
return (int) (( (int) ($dateTime ?: new DateTime())->format('Ymd') - (int) $this->format('Ymd') ) / 10000);
|
|
||||||
}
|
|
||||||
|
|
||||||
public function jsonSerialize(): mixed
|
|
||||||
{
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Ulmus\Entity\Field;
|
|
||||||
|
|
||||||
class Time extends DatetimeImmutable {
|
|
||||||
|
|
||||||
public string $format = "H:i:s";
|
|
||||||
}
|
|
||||||
@@ -322,7 +322,7 @@ class EntityCollection extends \ArrayObject implements \JsonSerializable {
|
|||||||
case is_string($value):
|
case is_string($value):
|
||||||
$value = (string) $value;
|
$value = (string) $value;
|
||||||
|
|
||||||
$list[(string) $key] = $item->$value;
|
$list[$key] = $item->$value;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-14
@@ -93,7 +93,7 @@ trait EntityTrait {
|
|||||||
$this->$field = $value;
|
$this->$field = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->eventExecute(Event\Entity\DatasetFill::class, $generator, $this);
|
$this->eventExecute(Event\Entity\DatasetFill::class, $this);
|
||||||
|
|
||||||
$this->entityDatasetUnmatchedFields = $generator->getReturn();
|
$this->entityDatasetUnmatchedFields = $generator->getReturn();
|
||||||
|
|
||||||
@@ -268,19 +268,6 @@ trait EntityTrait {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[Ignore]
|
|
||||||
public function __debugInfo() : array
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
return $this->toArray(true) ;
|
|
||||||
}
|
|
||||||
catch (\Throwable $ex) {
|
|
||||||
return $this->entityGetDataset(false, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return [ "An error occured trying to export this dataset..." ];
|
|
||||||
}
|
|
||||||
|
|
||||||
#[Ignore]
|
#[Ignore]
|
||||||
public function jsonSerialize() : mixed
|
public function jsonSerialize() : mixed
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -5,5 +5,5 @@ namespace Ulmus\Event\Query;
|
|||||||
use Ulmus\Repository\RepositoryInterface;
|
use Ulmus\Repository\RepositoryInterface;
|
||||||
|
|
||||||
interface Update {
|
interface Update {
|
||||||
public function execute(RepositoryInterface $repository, object|array $entity, array $dataset, array $diff, bool $replace = false) : void;
|
public function execute(RepositoryInterface $repository, object|array $entity, ? array $dataset = null, bool $replace = false) : void;
|
||||||
}
|
}
|
||||||
@@ -70,10 +70,6 @@ class FieldDefinition {
|
|||||||
$default = $this->getDefault();
|
$default = $this->getDefault();
|
||||||
$syntax = $this->adapter->tableSyntax();
|
$syntax = $this->adapter->tableSyntax();
|
||||||
|
|
||||||
if (is_callable($default)) {
|
|
||||||
$default = "(" . call_user_func($default) . ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
return implode(' ', array_filter([
|
return implode(' ', array_filter([
|
||||||
$this->isUnsigned() ? $syntax['unsigned'] : null,
|
$this->isUnsigned() ? $syntax['unsigned'] : null,
|
||||||
$this->nullable ? "NULL" : "NOT NULL",
|
$this->nullable ? "NULL" : "NOT NULL",
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ class Having extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# whitelisting operators
|
# whitelisting operators
|
||||||
return in_array(strtoupper($this->operator), [ '=', '!=', '>', '>=', '<', '<=', '<>', 'LIKE', 'IS', 'IS NOT', 'REGEXP', 'IN' ]) ? $this->operator : "=";
|
return in_array(strtoupper($this->operator), [ '=', '!=', '<>', 'LIKE' ]) ? $this->operator : "=";
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function value()
|
protected function value()
|
||||||
|
|||||||
+122
-15
@@ -8,13 +8,12 @@ use Ulmus\Attribute\Property\{
|
|||||||
use Psr\SimpleCache\CacheInterface;
|
use Psr\SimpleCache\CacheInterface;
|
||||||
use Ulmus\Common\EntityResolver;
|
use Ulmus\Common\EntityResolver;
|
||||||
use Ulmus\Entity\EntityInterface;
|
use Ulmus\Entity\EntityInterface;
|
||||||
use Ulmus\Repository\JoinBuilder;
|
|
||||||
use Ulmus\Repository\RepositoryInterface;
|
use Ulmus\Repository\RepositoryInterface;
|
||||||
use Ulmus\Repository\WithOptionEnum;
|
use Ulmus\Repository\WithOptionEnum;
|
||||||
|
|
||||||
class Repository implements RepositoryInterface
|
class Repository implements RepositoryInterface
|
||||||
{
|
{
|
||||||
use EventTrait, CacheTrait, Repository\ConditionTrait, Repository\EscapeTrait, Repository\QueryBuildingTrait, Repository\JoinBuilderTrait;
|
use EventTrait, CacheTrait, Repository\ConditionTrait, Repository\EscapeTrait, Repository\QueryBuildingTrait;
|
||||||
|
|
||||||
const DEFAULT_ALIAS = "this";
|
const DEFAULT_ALIAS = "this";
|
||||||
|
|
||||||
@@ -158,20 +157,26 @@ class Repository implements RepositoryInterface
|
|||||||
throw new \Exception("Your entity class `" . get_class($entity) . "` cannot match entity type of repository `{$this->entityClass}`");
|
throw new \Exception("Your entity class `" . get_class($entity) . "` cannot match entity type of repository `{$this->entityClass}`");
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($primaryKeyDefinition = Ulmus::resolveEntity($this->entityClass)->getPrimaryKeyField()) {
|
$primaryKeyDefinition = Ulmus::resolveEntity($this->entityClass)->getPrimaryKeyField();
|
||||||
|
|
||||||
|
if ( $primaryKeyDefinition !== null ) {
|
||||||
$pkField = key($primaryKeyDefinition);
|
$pkField = key($primaryKeyDefinition);
|
||||||
|
|
||||||
$this->eventExecute(Event\Query\Delete::class, $this, $entity);
|
$this->eventExecute(Event\Query\Delete::class, $this, $entity);
|
||||||
|
|
||||||
return $this->deleteFromPk($entity->$pkField);
|
return $this->deleteFromPk($entity->$pkField);
|
||||||
}
|
}
|
||||||
elseif ($compoundKeyFields = Ulmus::resolveEntity($this->entityClass)->getCompoundKeyFields()) {
|
|
||||||
$this->eventExecute(Event\Query\Delete::class, $this, $entity);
|
|
||||||
|
|
||||||
return $this->deleteFromCompoundKeys(array_combine($compoundKeyFields->column, array_map(fn($column) => $entity->$column, $compoundKeyFields->column)));
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
throw new \Exception(sprintf("No primary key found for entity %s", $this->entityClass));
|
$compoundKeyFields = Ulmus::resolveEntity($this->entityClass)->getCompoundKeyFields();
|
||||||
|
|
||||||
|
if ($compoundKeyFields) {
|
||||||
|
$this->eventExecute(Event\Query\Delete::class, $this, $entity);
|
||||||
|
|
||||||
|
return $this->deleteFromCompoundKeys(array_combine($compoundKeyFields->column, array_map(fn($column) => $entity->$column, $compoundKeyFields->column)));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new \Exception(sprintf("No primary key found for entity %s", $this->entityClass));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -258,7 +263,7 @@ class Repository implements RepositoryInterface
|
|||||||
|
|
||||||
$entity->entityFillFromDataset($dataset, true);
|
$entity->entityFillFromDataset($dataset, true);
|
||||||
|
|
||||||
$this->eventExecute(Event\Query\Update::class, $this, $entity, $dataset, $diff, $replace);
|
$this->eventExecute(Event\Query\Update::class, $this, $entity, $dataset, $replace);
|
||||||
|
|
||||||
return $update ? (bool) $update->rowCount : false;
|
return $update ? (bool) $update->rowCount : false;
|
||||||
}
|
}
|
||||||
@@ -369,11 +374,7 @@ class Repository implements RepositoryInterface
|
|||||||
$dataset = $this->generateDatasetDiff($entity, $oldValues);
|
$dataset = $this->generateDatasetDiff($entity, $oldValues);
|
||||||
|
|
||||||
foreach($dataset as $field => $value) {
|
foreach($dataset as $field => $value) {
|
||||||
$readonly = $this->entityResolver->searchFieldAnnotation($field, Field::class, false)->readonly ??
|
if ( false === ( $this->entityResolver->searchFieldAnnotation($field, Field::class, false)->readonly ?? false ) ) {
|
||||||
$this->entityResolver->searchField($field)->getAttribute(Field::class)->object->readonly ??
|
|
||||||
false;
|
|
||||||
|
|
||||||
if ( ! $readonly ) {
|
|
||||||
$intersect[$field] = $field;
|
$intersect[$field] = $field;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -449,6 +450,112 @@ class Repository implements RepositoryInterface
|
|||||||
return $this->where($this->entityClass::field($primaryKeyField[$pkField]->name ?? $pkField, $alias), $value);
|
return $this->where($this->entityClass::field($primaryKeyField[$pkField]->name ?? $pkField, $alias), $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function withJoin(string|array $fields, array $options = []) : self
|
||||||
|
{
|
||||||
|
$canSelect = null === $this->queryBuilder->getFragment(Query\Select::class);
|
||||||
|
|
||||||
|
if ( $canSelect ) {
|
||||||
|
$select = $this->entityResolver->fieldList(EntityResolver::KEY_COLUMN_NAME, true);
|
||||||
|
$this->select($this->entityClass::fields(array_map(fn($f) => $f['object']->name ?? $f['name'], $select), select: true));
|
||||||
|
}
|
||||||
|
|
||||||
|
$fields = (array) $fields;
|
||||||
|
usort($fields, fn($e1, $e2) => str_contains($e1, '.') <=> str_contains($e2, '.'));
|
||||||
|
|
||||||
|
# @TODO Apply fff annotation to this too !
|
||||||
|
foreach(array_filter($fields, fn($e) => $e && ! isset($this->joined[$e]) ) as $item) {
|
||||||
|
$this->joined[$item] = true;
|
||||||
|
|
||||||
|
$attribute = clone ($this->entityResolver->searchFieldAnnotation($item, [ Join::class ]) ?:
|
||||||
|
$this->entityResolver->searchFieldAnnotation($item, [ Relation::class ]));
|
||||||
|
|
||||||
|
$isRelation = $attribute instanceof Relation;
|
||||||
|
|
||||||
|
if ($isRelation && ( $attribute->isManyToMany() )) {
|
||||||
|
throw new \Exception("Many-to-many relation can not be preloaded within joins.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( $attribute ) {
|
||||||
|
$alias = $attribute->alias ?? $item;
|
||||||
|
$entity = $attribute->entity ?? $this->entityResolver->getPropertyEntityType($item);
|
||||||
|
|
||||||
|
foreach($entity::resolveEntity()->fieldList(Common\EntityResolver::KEY_COLUMN_NAME, true) as $key => $field) {
|
||||||
|
if ( null === $entity::resolveEntity()->searchFieldAnnotation($field->name, [ Relation\Ignore::class ]) ) {
|
||||||
|
$escAlias = $this->escapeIdentifier($alias);
|
||||||
|
$fieldName = $this->escapeIdentifier($key);
|
||||||
|
|
||||||
|
$name = $entity::resolveEntity()->searchFieldAnnotation($field->name, [ Field::class ])->name ?? $field->name;
|
||||||
|
|
||||||
|
if ($canSelect) {
|
||||||
|
# @TODO add handling of the new #[Select] attribute here !
|
||||||
|
|
||||||
|
$this->select("$escAlias.$fieldName as $alias\${$name}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->open();
|
||||||
|
|
||||||
|
if ( ! in_array(WithOptionEnum::SkipWhere, $options)) {
|
||||||
|
foreach($this->entityResolver->searchFieldAnnotationList($item, [ Where::class ] ) as $condition) {
|
||||||
|
if ( is_object($condition->field) && ( $condition->field->entityClass !== $entity ) ) {
|
||||||
|
$this->where(is_object($condition->field) ? $condition->field : $entity::field($condition->field), $condition->getValue(), $condition->operator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! in_array(WithOptionEnum::SkipHaving, $options)) {
|
||||||
|
foreach ($this->entityResolver->searchFieldAnnotationList($item, [ Having::class ]) as $condition) {
|
||||||
|
$this->having(is_object($condition->field) ? $condition->field : $entity::field($condition->field), $condition->getValue(), $condition->operator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! in_array(WithOptionEnum::SkipFilter, $options)) {
|
||||||
|
foreach ($this->entityResolver->searchFieldAnnotationList($item, [ Filter::class ]) as $filter) {
|
||||||
|
call_user_func_array([$this->entityClass, $filter->method], [$this, $item, true]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->close();
|
||||||
|
|
||||||
|
$key = is_string($attribute->key) ? $this->entityClass::field($attribute->key) : $attribute->key;
|
||||||
|
|
||||||
|
$foreignKey = is_string($attribute->foreignKey) ? $entity::field($attribute->foreignKey, $alias) : $attribute->foreignKey;
|
||||||
|
|
||||||
|
$this->join("LEFT", $entity::resolveEntity()->tableName(), $key, $foreignKey, $alias, function($join) use ($item, $entity, $alias, $options) {
|
||||||
|
if ( ! in_array(WithOptionEnum::SkipJoinWhere, $options)) {
|
||||||
|
foreach($this->entityResolver->searchFieldAnnotationList($item, [ Where::class ]) as $condition) {
|
||||||
|
if ( ! is_object($condition->field) ) {
|
||||||
|
$field = $this->entityClass::field($condition->field);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$field = clone $condition->field;
|
||||||
|
}
|
||||||
|
|
||||||
|
# Adding directly
|
||||||
|
if ( $field->entityClass === $entity ) {
|
||||||
|
$field->alias = $alias;
|
||||||
|
|
||||||
|
$join->where(is_object($field) ? $field : $entity::field($field, $alias), $condition->getValue(), $condition->operator);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! in_array(WithOptionEnum::SkipJoinFilter, $options) ) {
|
||||||
|
foreach ($this->entityResolver->searchFieldAnnotationList($item, [ FilterJoin::class ]) as $filter) {
|
||||||
|
call_user_func_array([$this->entityClass, $filter->method], [$join, $item, true]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
throw new \Exception("Referenced field `$item` which do not exist or do not contain a valid @Join or @Relation attribute.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function withSubquery(string|array $fields, array $options = []) : self
|
public function withSubquery(string|array $fields, array $options = []) : self
|
||||||
{
|
{
|
||||||
# We skip subqueries when counting results since it should not affect the row count.
|
# We skip subqueries when counting results since it should not affect the row count.
|
||||||
|
|||||||
@@ -1,153 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Ulmus\Repository;
|
|
||||||
|
|
||||||
use Ulmus\Attribute\Property\Field;
|
|
||||||
use Ulmus\Attribute\Property\Filter;
|
|
||||||
use Ulmus\Attribute\Property\FilterJoin;
|
|
||||||
use Ulmus\Attribute\Property\Having;
|
|
||||||
use Ulmus\Attribute\Property\Join;
|
|
||||||
use Ulmus\Attribute\Property\Relation;
|
|
||||||
use Ulmus\Attribute\Property\Where;
|
|
||||||
use Ulmus\Common\EntityField;
|
|
||||||
use Ulmus\Common\EntityResolver;
|
|
||||||
use Ulmus\QueryBuilder\QueryBuilderInterface;
|
|
||||||
use Ulmus\Query;
|
|
||||||
|
|
||||||
trait JoinBuilderTrait
|
|
||||||
{
|
|
||||||
public function withJoin(string|array $fields, array $options = []) : self
|
|
||||||
{
|
|
||||||
$defaultAlias = $this->escapeIdentifier(static::DEFAULT_ALIAS);
|
|
||||||
|
|
||||||
$canSelect = null === $this->queryBuilder->getFragment(Query\Select::class);
|
|
||||||
|
|
||||||
if ( $canSelect ) {
|
|
||||||
$select = $this->entityResolver->fieldList(EntityResolver::KEY_COLUMN_NAME, true);
|
|
||||||
|
|
||||||
$this->select($this->entityClass::fields(array_map(fn($f) => $f['object']->name ?? $f['name'], $select), select: true));
|
|
||||||
}
|
|
||||||
|
|
||||||
$fields = (array) $fields;
|
|
||||||
|
|
||||||
usort($fields, fn($e1, $e2) => str_contains((string) $e1, '.') <=> str_contains((string) $e2, '.'));
|
|
||||||
|
|
||||||
# @TODO Apply fff annotation to this too !
|
|
||||||
foreach(array_filter($fields, fn($e) => $e && ! isset($this->joined[$e]) ) as $item) {
|
|
||||||
$this->joined[$item] = true;
|
|
||||||
|
|
||||||
$attribute = clone ($this->entityResolver->searchFieldAnnotation($item, [ Join::class ]) ?:
|
|
||||||
$this->entityResolver->searchFieldAnnotation($item, [ Relation::class ]));
|
|
||||||
|
|
||||||
$isRelation = $attribute instanceof Relation;
|
|
||||||
|
|
||||||
if ($isRelation && ( $attribute->isManyToMany() )) {
|
|
||||||
throw new \Exception("Many-to-many relation can not be preloaded within joins.");
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( $attribute ) {
|
|
||||||
$alias = $attribute->alias ?? $item;
|
|
||||||
$entity = $attribute->entity ?? $this->entityResolver->getPropertyEntityType($item);
|
|
||||||
|
|
||||||
foreach($entity::resolveEntity()->fieldList(EntityResolver::KEY_COLUMN_NAME, true) as $key => $field) {
|
|
||||||
if ( null === $entity::resolveEntity()->searchFieldAnnotation($field->name, [ Relation\Ignore::class ]) ) {
|
|
||||||
$escAlias = $this->escapeIdentifier($alias);
|
|
||||||
$fieldName = $this->escapeIdentifier($key);
|
|
||||||
|
|
||||||
$name = $entity::resolveEntity()->searchFieldAnnotation($field->name, [ Field::class ])->name ?? $field->name;
|
|
||||||
|
|
||||||
if ($canSelect) {
|
|
||||||
# @TODO add handling of the new #[Select] attribute here !
|
|
||||||
|
|
||||||
$this->select("$escAlias.$fieldName as $alias\${$name}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->open();
|
|
||||||
|
|
||||||
if ( ! in_array(WithOptionEnum::SkipWhere, $options)) {
|
|
||||||
foreach($this->entityResolver->searchFieldAnnotationList($item, [ Where::class ] ) as $condition) {
|
|
||||||
$field = $this->joinFieldObject($condition->field, $this->entityClass);
|
|
||||||
|
|
||||||
if ( $field->entityClass === $this->entityClass ) {
|
|
||||||
$this->where($field, $this->joinFieldValue($condition->getValue(), $alias), $condition->operator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! in_array(WithOptionEnum::SkipHaving, $options)) {
|
|
||||||
foreach ($this->entityResolver->searchFieldAnnotationList($item, [ Having::class ]) as $condition) {
|
|
||||||
$field = $this->joinFieldObject($condition->field, $this->entityClass);
|
|
||||||
|
|
||||||
$this->having($field, $this->joinFieldValue($condition->getValue(), $alias), $condition->operator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! in_array(WithOptionEnum::SkipFilter, $options)) {
|
|
||||||
foreach ($this->entityResolver->searchFieldAnnotationList($item, [ Filter::class ]) as $filter) {
|
|
||||||
call_user_func_array([$this->entityClass, $filter->method], [ $this, $item, true ]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->close();
|
|
||||||
|
|
||||||
$key = is_string($attribute->key) ? $this->entityClass::field($attribute->key) : $attribute->key;
|
|
||||||
|
|
||||||
$foreignKey = is_string($attribute->foreignKey) ? $entity::field($attribute->foreignKey, $alias) : $attribute->foreignKey;
|
|
||||||
|
|
||||||
$this->join(Query\Join::TYPE_LEFT, $entity::resolveEntity()->tableName(), $key, $foreignKey, $alias, function($join) use ($item, $entity, $alias, $defaultAlias, $options) {
|
|
||||||
if ( ! in_array(WithOptionEnum::SkipJoinWhere, $options)) {
|
|
||||||
foreach($this->entityResolver->searchFieldAnnotationList($item, [ Where::class ]) as $condition) {
|
|
||||||
$field = $this->joinFieldObject($condition->field, $this->entityClass);
|
|
||||||
|
|
||||||
# Adding directly
|
|
||||||
if ( $field->entityClass === $entity ) {
|
|
||||||
if ($field->alias === $defaultAlias) {
|
|
||||||
$field->alias = $this->escapeIdentifier($alias);
|
|
||||||
}
|
|
||||||
|
|
||||||
$join->where($field, $this->joinFieldValue($condition->getValue(), $alias), $condition->operator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( ! in_array(WithOptionEnum::SkipJoinFilter, $options) ) {
|
|
||||||
foreach ($this->entityResolver->searchFieldAnnotationList($item, [ FilterJoin::class ]) as $filter) {
|
|
||||||
call_user_func_array([$this->entityClass, $filter->method], [$join, $item, true]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new \Exception("Referenced field `$item` which do not exist or do not contain a valid @Join or @Relation attribute.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function joinFieldObject(mixed $field, string $entityClass, ?string $alias = null) : \Stringable
|
|
||||||
{
|
|
||||||
if ( ! is_object($field) ) {
|
|
||||||
return $entityClass::field($field, $alias);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return clone $field;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
protected function joinFieldValue(mixed $value, ?string $alias = null) : mixed
|
|
||||||
{
|
|
||||||
if ( $value instanceof EntityField ) {
|
|
||||||
$value = clone $value;
|
|
||||||
|
|
||||||
$value->alias = $value->alias ?: $this->escapeIdentifier($alias);
|
|
||||||
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -43,7 +43,7 @@ trait QueryBuildingTrait
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function queryUpdate(string $table, string $alias, ? string $schema) : self
|
public function update(string $table, string $alias, ? string $schema) : self
|
||||||
{
|
{
|
||||||
$this->queryBuilder->update($this->escapeTable($table), $alias ? $this->escapeIdentifier($alias) : null, $this->escapedDatabase(), $schema);
|
$this->queryBuilder->update($this->escapeTable($table), $alias ? $this->escapeIdentifier($alias) : null, $this->escapedDatabase(), $schema);
|
||||||
|
|
||||||
@@ -210,7 +210,7 @@ trait QueryBuildingTrait
|
|||||||
protected function updateSqlQuery(array $dataset) : self
|
protected function updateSqlQuery(array $dataset) : self
|
||||||
{
|
{
|
||||||
if ( null === $this->queryBuilder->getFragment(Query\Update::class) ) {
|
if ( null === $this->queryBuilder->getFragment(Query\Update::class) ) {
|
||||||
$this->queryUpdate($this->entityResolver->tableName(), $this->alias, $this->entityResolver->schemaName());
|
$this->update($this->entityResolver->tableName(), $this->alias, $this->entityResolver->schemaName());
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->set($dataset);
|
$this->set($dataset);
|
||||||
|
|||||||
@@ -15,13 +15,11 @@ class ParsedSearchParameter
|
|||||||
) {}
|
) {}
|
||||||
|
|
||||||
public function value() : mixed{
|
public function value() : mixed{
|
||||||
$value = $this->value instanceof \BackedEnum ? $this->value->value : $this->value;
|
|
||||||
|
|
||||||
return match ($this->searchMethod) {
|
return match ($this->searchMethod) {
|
||||||
SearchMethodEnum::Like => "%$value%",
|
SearchMethodEnum::Like => "%$this->value%",
|
||||||
SearchMethodEnum::LikeLeft => "%$value",
|
SearchMethodEnum::LikeLeft => "%$this->value",
|
||||||
SearchMethodEnum::LikeRight => "$value%",
|
SearchMethodEnum::LikeRight => "$this->value%",
|
||||||
default => $value,
|
default => $this->value,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,8 +61,7 @@ trait SearchRequestFromRequestTrait
|
|||||||
{
|
{
|
||||||
$this->objectReflection = ObjectReflection::fromClass(static::class)->reflectClass();
|
$this->objectReflection = ObjectReflection::fromClass(static::class)->reflectClass();
|
||||||
|
|
||||||
# REMOVED - this could cause legacy problems, kept in case of a quick uncomment is needed
|
$this->page = $data['page'] ?? 1;
|
||||||
# $this->page = $data['page'] ?? 1;
|
|
||||||
|
|
||||||
$this->applyValues(
|
$this->applyValues(
|
||||||
fn($propertyName, $attribute) => $data[$propertyName] ?? null
|
fn($propertyName, $attribute) => $data[$propertyName] ?? null
|
||||||
@@ -87,9 +86,9 @@ trait SearchRequestFromRequestTrait
|
|||||||
$this->prepare($request);
|
$this->prepare($request);
|
||||||
}
|
}
|
||||||
|
|
||||||
# REMOVED - this could cause legacy problems, kept in case of a quick uncomment is needed
|
$queryParams = new \ArrayObject(array_filter($request->getQueryParams(), function($i) { return ! is_null($i) && $i !== ""; }));
|
||||||
# $queryParams = new \ArrayObject(array_filter($request->getQueryParams(), function($i) { return ! is_null($i) && $i !== ""; }));
|
|
||||||
# $this->page = $queryParams->offsetExists('page') ? $queryParams['page'] : 1;
|
$this->page = $queryParams->offsetExists('page') ? $queryParams['page'] : 1;
|
||||||
|
|
||||||
$this->applyValues(
|
$this->applyValues(
|
||||||
fn($propertyName, $attribute) =>$this->getValueFromSource($request, $propertyName, $attribute)
|
fn($propertyName, $attribute) =>$this->getValueFromSource($request, $propertyName, $attribute)
|
||||||
@@ -156,21 +155,6 @@ trait SearchRequestFromRequestTrait
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getPropertyAttribute(string $name) : ? Attribute\SearchParameter
|
|
||||||
{
|
|
||||||
foreach($this->objectReflection->getProperties() as $propertyName => $property) {
|
|
||||||
if ($propertyName === $name) {
|
|
||||||
$attribute = $property->getAttribute(Attribute\SearchParameter::class)->object ?? false;
|
|
||||||
|
|
||||||
if ($attribute) {
|
|
||||||
return $attribute;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function applyValues(\Closure $getValue) : void
|
protected function applyValues(\Closure $getValue) : void
|
||||||
{
|
{
|
||||||
foreach($this->objectReflection->getProperties() as $propertyName => $property) {
|
foreach($this->objectReflection->getProperties() as $propertyName => $property) {
|
||||||
@@ -206,28 +190,7 @@ trait SearchRequestFromRequestTrait
|
|||||||
$this->$propertyName = !empty($value);
|
$this->$propertyName = !empty($value);
|
||||||
}
|
}
|
||||||
elseif ($value !== null) {
|
elseif ($value !== null) {
|
||||||
|
|
||||||
$this->$propertyName = $this->parseValue($property, $value);
|
$this->$propertyName = $this->parseValue($property, $value);
|
||||||
/*=======
|
|
||||||
foreach ($property->getTypes() as $type) {
|
|
||||||
$enum = $type->type;
|
|
||||||
|
|
||||||
if (enum_exists($enum)) {
|
|
||||||
try {
|
|
||||||
$this->$propertyName = $value instanceof \UnitEnum ? $value : $type->type::from($value);
|
|
||||||
} catch (\ValueError $ex) {
|
|
||||||
$cases = implode(', ', array_map(fn($e) => $e->value, $enum::cases()));
|
|
||||||
|
|
||||||
throw new \ValueError(
|
|
||||||
sprintf("Given value '%s' do not exists within enum '%s'. Try one of those values instead : %s", $value, $enum, $cases)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
elseif ($type->builtIn || $value instanceof \Stringable ) {
|
|
||||||
$this->$propertyName = $value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
>>>>>>> d917678 (- Moved withJoin() method of repository into a trait)*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->parseAttributeMethod($attribute, $field, $propertyName);
|
$this->parseAttributeMethod($attribute, $field, $propertyName);
|
||||||
|
|||||||
Reference in new issue
Block a user