Skip to content

Commit

Permalink
Merge branch 'hotfix/2.0.1' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
cerbero90 committed Sep 13, 2024
2 parents 1875e33 + 336cc1d commit 80eb732
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,13 @@
}],
"require": {
"php": "^8.1",
"cerbero/lazy-json": "^2.0",
"cerbero/json-parser": "^1.1",
"guzzlehttp/guzzle": "^7.2",
"illuminate/support": ">=6.20"
"illuminate/collections": ">=8.12"
},
"require-dev": {
"illuminate/http": ">=6.20",
"mockery/mockery": "^1.3.4",
"orchestra/testbench": ">=7.0",
"orchestra/testbench": ">=6.0",
"pestphp/pest": "^2.0",
"phpstan/phpstan": "^1.9",
"scrutinizer/ocular": "^1.8",
Expand Down
4 changes: 2 additions & 2 deletions src/Concerns/ParsesPages.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace Cerbero\LazyJsonPages\Concerns;

use Cerbero\JsonParser\JsonParser;
use Cerbero\LazyJson\Pointers\DotsConverter;
use Cerbero\LazyJsonPages\Data\Dot;
use Generator;
use Psr\Http\Message\ResponseInterface;

Expand All @@ -30,7 +30,7 @@ protected function yieldItemsAndGetKey(ResponseInterface $response, string $key)
$pointers = [$this->config->itemsPointer];

if (($value = $response->getHeaderLine($key)) === '') {
$pointers[DotsConverter::toPointer($key)] = fn(mixed $value) => (object) compact('value');
$pointers[(new Dot($key))->toPointer()] = fn(mixed $value) => (object) compact('value');
}

foreach (JsonParser::parse($response)->pointers($pointers) as $item) {
Expand Down
27 changes: 27 additions & 0 deletions src/Data/Dot.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Cerbero\LazyJsonPages\Data;

/**
* The dot value object.
*/
final class Dot
{
/**
* Instantiate the class.
*/
public function __construct(public readonly string $dot) {}

/**
* Retrieve the JSON pointer of this dot.
*/
public function toPointer(): string
{
$search = ['~', '/', '.', '*', '\\', '"'];
$replace = ['~0', '~1', '/', '-', '\\\\', '\"'];

return $this->dot == '*' ? '' : '/' . str_replace($search, $replace, $this->dot);
}
}
4 changes: 2 additions & 2 deletions src/LazyJsonPages.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace Cerbero\LazyJsonPages;

use Cerbero\LazyJson\Pointers\DotsConverter;
use Cerbero\LazyJsonPages\Data\Config;
use Cerbero\LazyJsonPages\Data\Dot;
use Cerbero\LazyJsonPages\Paginations\AnyPagination;
use Cerbero\LazyJsonPages\Services\ClientFactory;
use Cerbero\LazyJsonPages\Sources\AnySource;
Expand Down Expand Up @@ -281,7 +281,7 @@ public function onError(Closure $callback): self
*/
public function collect(string $dot = '*'): LazyCollection
{
$this->config[Config::OPTION_ITEMS_POINTER] = DotsConverter::toPointer($dot);
$this->config[Config::OPTION_ITEMS_POINTER] = (new Dot($dot))->toPointer();

return new LazyCollection(function () {
$client = $this->client->make();
Expand Down

0 comments on commit 80eb732

Please sign in to comment.