mirror of
https://github.com/cerbero90/json-parser.git
synced 2025-01-17 04:58:15 +01:00
Remove custom sources registration
This commit is contained in:
parent
cc1d3f18e7
commit
78a041a56a
@ -10,9 +10,8 @@ use Exception;
|
||||
*/
|
||||
abstract class JsonParserException extends Exception
|
||||
{
|
||||
public const SOURCE_INVALID = 0;
|
||||
public const SOURCE_UNSUPPORTED = 1;
|
||||
public const SOURCE_GUZZLE = 2;
|
||||
public const SOURCE_UNSUPPORTED = 0;
|
||||
public const SOURCE_GUZZLE = 1;
|
||||
|
||||
public const POINTER_INVALID = 0;
|
||||
}
|
||||
|
@ -8,17 +8,6 @@ namespace Cerbero\JsonParser\Exceptions;
|
||||
*/
|
||||
class SourceException extends JsonParserException
|
||||
{
|
||||
/**
|
||||
* Retrieve the exception when the given source is invalid
|
||||
*
|
||||
* @param string $source
|
||||
* @return static
|
||||
*/
|
||||
public static function invalid(string $source): static
|
||||
{
|
||||
return new static("[$source] is not a valid source", static::SOURCE_INVALID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the exception when a JSON source is not supported
|
||||
*
|
||||
|
@ -15,7 +15,7 @@ class AnySource extends Source
|
||||
/**
|
||||
* The supported sources.
|
||||
*
|
||||
* @var array
|
||||
* @var string[]
|
||||
*/
|
||||
protected array $supportedSources = [
|
||||
CustomSource::class,
|
||||
@ -60,10 +60,6 @@ class AnySource extends Source
|
||||
*/
|
||||
protected function sources(): Generator
|
||||
{
|
||||
foreach (static::$customSources as $source) {
|
||||
yield $source::from($this->source, $this->config);
|
||||
}
|
||||
|
||||
foreach ($this->supportedSources as $source) {
|
||||
yield $source::from($this->source, $this->config);
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace Cerbero\JsonParser\Sources;
|
||||
|
||||
use Cerbero\JsonParser\Config;
|
||||
use Cerbero\JsonParser\Exceptions\SourceException;
|
||||
use IteratorAggregate;
|
||||
use Traversable;
|
||||
|
||||
@ -13,13 +12,6 @@ use Traversable;
|
||||
*/
|
||||
abstract class Source implements IteratorAggregate
|
||||
{
|
||||
/**
|
||||
* The registered custom sources.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static array $customSources = [];
|
||||
|
||||
/**
|
||||
* The cached size of the JSON source.
|
||||
*
|
||||
@ -70,23 +62,6 @@ abstract class Source implements IteratorAggregate
|
||||
return new static($source, $config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the given custom sources
|
||||
*
|
||||
* @param string ...$customSource
|
||||
* @return void
|
||||
*/
|
||||
public static function register(string ...$customSource): void
|
||||
{
|
||||
foreach ($customSource as $class) {
|
||||
if (!is_subclass_of($class, Source::class)) {
|
||||
throw SourceException::invalid($class);
|
||||
}
|
||||
|
||||
static::$customSources[] = $class;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the underlying configuration
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user