Remove custom sources registration

This commit is contained in:
Andrea Marco Sartori
2022-12-03 21:03:39 +10:00
parent cc1d3f18e7
commit 78a041a56a
4 changed files with 3 additions and 44 deletions

View File

@ -10,9 +10,8 @@ use Exception;
*/ */
abstract class JsonParserException extends Exception abstract class JsonParserException extends Exception
{ {
public const SOURCE_INVALID = 0; public const SOURCE_UNSUPPORTED = 0;
public const SOURCE_UNSUPPORTED = 1; public const SOURCE_GUZZLE = 1;
public const SOURCE_GUZZLE = 2;
public const POINTER_INVALID = 0; public const POINTER_INVALID = 0;
} }

View File

@ -8,17 +8,6 @@ namespace Cerbero\JsonParser\Exceptions;
*/ */
class SourceException extends JsonParserException 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 * Retrieve the exception when a JSON source is not supported
* *

View File

@ -15,7 +15,7 @@ class AnySource extends Source
/** /**
* The supported sources. * The supported sources.
* *
* @var array * @var string[]
*/ */
protected array $supportedSources = [ protected array $supportedSources = [
CustomSource::class, CustomSource::class,
@ -60,10 +60,6 @@ class AnySource extends Source
*/ */
protected function sources(): Generator protected function sources(): Generator
{ {
foreach (static::$customSources as $source) {
yield $source::from($this->source, $this->config);
}
foreach ($this->supportedSources as $source) { foreach ($this->supportedSources as $source) {
yield $source::from($this->source, $this->config); yield $source::from($this->source, $this->config);
} }

View File

@ -3,7 +3,6 @@
namespace Cerbero\JsonParser\Sources; namespace Cerbero\JsonParser\Sources;
use Cerbero\JsonParser\Config; use Cerbero\JsonParser\Config;
use Cerbero\JsonParser\Exceptions\SourceException;
use IteratorAggregate; use IteratorAggregate;
use Traversable; use Traversable;
@ -13,13 +12,6 @@ use Traversable;
*/ */
abstract class Source implements IteratorAggregate abstract class Source implements IteratorAggregate
{ {
/**
* The registered custom sources.
*
* @var array
*/
protected static array $customSources = [];
/** /**
* The cached size of the JSON source. * The cached size of the JSON source.
* *
@ -70,23 +62,6 @@ abstract class Source implements IteratorAggregate
return new static($source, $config); 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 * Retrieve the underlying configuration
* *