Skip to content

Commit

Permalink
Update source
Browse files Browse the repository at this point in the history
  • Loading branch information
cerbero90 committed Dec 19, 2023
1 parent 333facb commit da798a5
Showing 1 changed file with 17 additions and 29 deletions.
46 changes: 17 additions & 29 deletions src/Sources/AnySource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,45 @@

use Cerbero\LazyJsonPages\Exceptions\UnsupportedSourceException;
use Generator;
use Traversable;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;

class AnySource implements Source
class AnySource extends Source
{
/**
* @var class-string<Source>[]
*/
protected array $supportedSources = [
CustomSource::class,
Endpoint::class,
LaravelClientRequest::class,
LaravelClientResponse::class,
LaravelRequest::class,
Psr7Request::class,
SymfonyRequest::class,
];

/**
* The matching source.
*
* @var Source|null
*/
protected ?Source $matchingSource;

/**
* Retrieve the JSON fragments
*
* @return Traversable<int, string>
* @throws UnsupportedSourceException
* Determine whether the JSON source can be handled
*/
public function getIterator(): Traversable
public function matches(): bool
{
return $this->matchingSource();
return true;
}

public function request(): RequestInterface
{
return $this->matchingSource()->request();
}

/**
* Retrieve the matching source
*
* @return Source
* @throws UnsupportedSourceException
*/
protected function matchingSource(): Source
Expand All @@ -67,27 +70,12 @@ protected function matchingSource(): Source
protected function sources(): Generator
{
foreach ($this->supportedSources as $source) {
yield new $source($this->source, $this->config);
yield new $source($this->source);
}
}

/**
* Determine whether the JSON source can be handled
*
* @return bool
*/
public function matches(): bool
{
return true;
}

/**
* Retrieve the calculated size of the JSON source
*
* @return int|null
*/
protected function calculateSize(): ?int
public function response(?string $key = null): mixed
{
return $this->matchingSource()->size();
return $this->matchingSource()->response($key);
}
}

0 comments on commit da798a5

Please sign in to comment.