diff --git a/src/Exceptions/ConverterException.php b/src/Exceptions/ConverterException.php deleted file mode 100644 index e11c9456..00000000 --- a/src/Exceptions/ConverterException.php +++ /dev/null @@ -1,6 +0,0 @@ -popFromOperandStack(); } - $arguments = Converter::normalizeArguments( + $arguments = Normalizer::normalizeValues( $arguments, $signature['arguments'] ); diff --git a/src/Kernel/Types/_Array/Collection.php b/src/Kernel/Types/_Array/Collection.php index 645f5fb6..e16bcf5c 100644 --- a/src/Kernel/Types/_Array/Collection.php +++ b/src/Kernel/Types/_Array/Collection.php @@ -6,9 +6,10 @@ use PHPJava\Utilities\Extractor; use PHPJava\Utilities\TypeResolver; -class Collection implements \ArrayAccess +class Collection implements \ArrayAccess, \Countable, \IteratorAggregate { private $data; + private $position = 0; public function __construct(array &$data, string $type = null) { @@ -54,4 +55,14 @@ public function offsetSet($offset, $value) { $this->data[$offset] = $value; } + + public function count() + { + return count($this->data); + } + + public function getIterator() + { + return new \ArrayIterator($this->data); + } } diff --git a/src/Utilities/Converter.php b/src/Utilities/Converter.php deleted file mode 100644 index 6d29e0e1..00000000 --- a/src/Utilities/Converter.php +++ /dev/null @@ -1,48 +0,0 @@ - &$argument) { - /** - * @var Type|Collection $argument - */ - if ($argument instanceof Collection) { - // TODO: convert an array contents. - continue; - } - $realType = $acceptedArguments[$key] ?? null; - if ($realType === null) { - throw new ConverterException('Broken arguments parser.'); - } - if ($realType['type'] === 'class') { - // TODO: implements up-cast and down-cast - continue; - } - $initiateClass = TypeResolver::TYPES_MAP[$realType['type']]; - if ($argument instanceof $initiateClass) { - continue; - } - $argument = new $initiateClass(Extractor::realValue($argument)); - } - - return $arguments; - } -} diff --git a/src/Utilities/Normalizer.php b/src/Utilities/Normalizer.php new file mode 100644 index 00000000..f769ac61 --- /dev/null +++ b/src/Utilities/Normalizer.php @@ -0,0 +1,57 @@ + &$value) { + $realType = $normalizeTypes[$key] ?? null; + if ($realType === null) { + throw new NormalizerException('Broken arguments parser.'); + } + /** + * @var Type|Collection $value + */ + if ($value instanceof Collection) { + $value = static::normalizeValues( + $value, + array_fill( + 0, + count($value), + $realType + ) + ); + continue; + } + if ($realType['type'] === 'class') { + // TODO: implements up-cast and down-cast + continue; + } + $initiateClass = TypeResolver::TYPES_MAP[$realType['type']]; + if ($value instanceof $initiateClass) { + continue; + } + $value = new $initiateClass( + Extractor::realValue($value) + ); + } + + return $values; + } +}