Skip to content

Commit 3796761

Browse files
committed
move native date fields directly to StoriesRequest
1 parent be9beb8 commit 3796761

23 files changed

+576
-475
lines changed

README.md

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,19 +325,15 @@ Supported date parameters are:
325325
```php
326326
use Storyblok\Api\StoriesApi;
327327
use Storyblok\Api\StoryblokClient;
328-
use Storyblok\Api\Domain\Value\QueryParameter\Operator;
329-
use Storyblok\Api\Domain\Value\QueryParameter\PublishedAtQueryParameter;
330-
use Storyblok\Api\Domain\Value\QueryParameter\QueryParameterCollection;
328+
use Storyblok\Api\Domain\Value\QueryParameter\PublishedAtGt;
331329
use Storyblok\Api\Request\StoriesRequest;
332330

333331
$client = new StoryblokClient(/* ... */);
334332

335333
$storiesApi = new StoriesApi($client);
336334
$response = $storiesApi->all(new StoriesRequest(
337335
language: 'de',
338-
queryParameterCollection: new QueryParameterCollection([
339-
new PublishedAtQueryParameter(new DateTimeImmutable(), Operator::GreaterThan)
340-
])
336+
publishedAtGt: new PublishedAtGt($date)
341337
));
342338
```
343339

src/Domain/Value/QueryParameter/DateQueryParameter.php renamed to src/Domain/Value/QueryParameter/FirstPublishedAtGt.php

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,22 @@
1414

1515
namespace Storyblok\Api\Domain\Value\QueryParameter;
1616

17-
use Webmozart\Assert\Assert;
18-
1917
/**
20-
* Represents top level query parameters which are holding simple string values.
21-
*
2218
* @author Frank Stelzer <[email protected]>
2319
*/
24-
abstract readonly class DateQueryParameter extends QueryParameter
20+
final readonly class FirstPublishedAtGt implements QueryParameter
2521
{
26-
protected function validateValue(string $value): void
22+
public function __construct(private \DateTimeInterface $dateTime)
2723
{
28-
parent::validateValue($value);
24+
}
2925

30-
Assert::regex(
31-
$value,
32-
'/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/',
33-
\sprintf('The date must be in the format YYYY-MM-DD HH:MM, given: %s', $value),
34-
);
26+
public function getName(): string
27+
{
28+
return 'first_published_at_gt';
29+
}
30+
31+
public function toString(): string
32+
{
33+
return $this->dateTime->format(QueryParameter::DATE_TIME_FORMAT);
3534
}
3635
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of storyblok/php-content-api-client.
7+
*
8+
* (c) Storyblok GmbH <[email protected]>
9+
* in cooperation with SensioLabs Deutschland <[email protected]>
10+
*
11+
* For the full copyright and license information, please view the LICENSE
12+
* file that was distributed with this source code.
13+
*/
14+
15+
namespace Storyblok\Api\Domain\Value\QueryParameter;
16+
17+
/**
18+
* @author Frank Stelzer <[email protected]>
19+
*/
20+
final readonly class FirstPublishedAtLt implements QueryParameter
21+
{
22+
public function __construct(private \DateTimeInterface $dateTime)
23+
{
24+
}
25+
26+
public function getName(): string
27+
{
28+
return 'first_published_at_lt';
29+
}
30+
31+
public function toString(): string
32+
{
33+
return $this->dateTime->format(QueryParameter::DATE_TIME_FORMAT);
34+
}
35+
}

src/Domain/Value/QueryParameter/FirstPublishedAtQueryParameter.php

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/Domain/Value/QueryParameter/Operator.php

Lines changed: 0 additions & 21 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of storyblok/php-content-api-client.
7+
*
8+
* (c) Storyblok GmbH <[email protected]>
9+
* in cooperation with SensioLabs Deutschland <[email protected]>
10+
*
11+
* For the full copyright and license information, please view the LICENSE
12+
* file that was distributed with this source code.
13+
*/
14+
15+
namespace Storyblok\Api\Domain\Value\QueryParameter;
16+
17+
/**
18+
* @author Frank Stelzer <[email protected]>
19+
*/
20+
final readonly class PublishedAtGt implements QueryParameter
21+
{
22+
public function __construct(private \DateTimeInterface $dateTime)
23+
{
24+
}
25+
26+
public function getName(): string
27+
{
28+
return 'published_at_gt';
29+
}
30+
31+
public function toString(): string
32+
{
33+
return $this->dateTime->format(QueryParameter::DATE_TIME_FORMAT);
34+
}
35+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of storyblok/php-content-api-client.
7+
*
8+
* (c) Storyblok GmbH <[email protected]>
9+
* in cooperation with SensioLabs Deutschland <[email protected]>
10+
*
11+
* For the full copyright and license information, please view the LICENSE
12+
* file that was distributed with this source code.
13+
*/
14+
15+
namespace Storyblok\Api\Domain\Value\QueryParameter;
16+
17+
/**
18+
* @author Frank Stelzer <[email protected]>
19+
*/
20+
final readonly class PublishedAtLt implements QueryParameter
21+
{
22+
public function __construct(private \DateTimeInterface $dateTime)
23+
{
24+
}
25+
26+
public function getName(): string
27+
{
28+
return 'published_at_lt';
29+
}
30+
31+
public function toString(): string
32+
{
33+
return $this->dateTime->format(QueryParameter::DATE_TIME_FORMAT);
34+
}
35+
}

src/Domain/Value/QueryParameter/PublishedAtQueryParameter.php

Lines changed: 0 additions & 31 deletions
This file was deleted.

src/Domain/Value/QueryParameter/QueryParameter.php

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,16 @@
1414

1515
namespace Storyblok\Api\Domain\Value\QueryParameter;
1616

17-
use OskarStark\Value\TrimmedNonEmptyString;
18-
1917
/**
2018
* Represents top level query parameters which are holding simple string values.
2119
*
2220
* @author Frank Stelzer <[email protected]>
2321
*/
24-
abstract readonly class QueryParameter
22+
interface QueryParameter
2523
{
26-
public function __construct(
27-
public string $name,
28-
public string $value,
29-
) {
30-
$this->validateName($name);
31-
$this->validateValue($value);
32-
}
24+
public const string DATE_TIME_FORMAT = 'Y-m-d\TH:i:s.v\Z';
3325

34-
protected function validateName(string $name): void
35-
{
36-
TrimmedNonEmptyString::fromString($name);
37-
}
26+
public function getName(): string;
3827

39-
protected function validateValue(string $value): void
40-
{
41-
TrimmedNonEmptyString::fromString($value);
42-
}
28+
public function toString(): string;
4329
}

src/Domain/Value/QueryParameter/QueryParameterCollection.php

Lines changed: 0 additions & 105 deletions
This file was deleted.

0 commit comments

Comments
 (0)