- Added some attributes-related manipulation in SearchRequest trait
- Removed default page setting based on query params adn - Added DateTime format doc
This commit is contained in:
1 parent
ec061bcd9f
commit
75fb7ba155
3 files changed
+86
-4
No files matched your search
@@ -49,6 +49,8 @@ trait DatetimeTrait
|
||||
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);
|
||||
|
||||
@@ -61,7 +61,8 @@ trait SearchRequestFromRequestTrait
|
||||
{
|
||||
$this->objectReflection = ObjectReflection::fromClass(static::class)->reflectClass();
|
||||
|
||||
$this->page = $data['page'] ?? 1;
|
||||
# REMOVED - this could cause legacy problems, kept in case of a quick uncomment is needed
|
||||
# $this->page = $data['page'] ?? 1;
|
||||
|
||||
$this->applyValues(
|
||||
fn($propertyName, $attribute) => $data[$propertyName] ?? null
|
||||
@@ -86,9 +87,9 @@ trait SearchRequestFromRequestTrait
|
||||
$this->prepare($request);
|
||||
}
|
||||
|
||||
$queryParams = new \ArrayObject(array_filter($request->getQueryParams(), function($i) { return ! is_null($i) && $i !== ""; }));
|
||||
|
||||
$this->page = $queryParams->offsetExists('page') ? $queryParams['page'] : 1;
|
||||
# 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 !== ""; }));
|
||||
# $this->page = $queryParams->offsetExists('page') ? $queryParams['page'] : 1;
|
||||
|
||||
$this->applyValues(
|
||||
fn($propertyName, $attribute) =>$this->getValueFromSource($request, $propertyName, $attribute)
|
||||
@@ -155,6 +156,21 @@ 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
|
||||
{
|
||||
foreach($this->objectReflection->getProperties() as $propertyName => $property) {
|
||||
|
||||
Reference in new issue
Block a user