-
Guillaume Perréal authoredab705132
<?php declare(strict_types=1);
/*
* This file is part of "irstea/ng-model-generator-bundle".
*
* "irstea/ng-model-generator-bundle" generates Typescript interfaces for Angular using api-platform metadata.
* Copyright (C) 2018 IRSTEA
*
* This program is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
* Software Foundation, either version 3 of the License, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License and the GNU
* Lesser General Public License along with this program. If not, see
* <https://www.gnu.org/licenses/>.
*/
namespace Irstea\NgModelGeneratorBundle\Models\Types;
/**
* Class AbstractCollection.
*/
abstract class AbstractCollection extends AbstractType
{
/**
* @var Type
*/
protected $valueType;
/**
* Collection constructor.
*
* @param Type $valueType
*/
public function __construct(Type $valueType)
{
$this->valueType = $valueType;
}
/**
* @return Type
*/
public function getValueType(): Type
{
return $this->valueType;
}
/**
* {@inheritdoc}
*/
public function getIterator()
{
yield $this->getKeyType();
yield $this->valueType;
}
/**
* {@inheritdoc}
*/
public function getUsage(): string
{
return sprintf('%s<%s>', $this->getGenericUsage(), $this->valueType->getUsage());
}
/**
* @return array
71727374757677787980818283848586878889909192939495
*/
public function jsonSerialize()
{
return ['type' => $this->getGenericUsage(), 'keyType' => $this->getKeyType(), 'valueType' => $this->valueType];
}
/**
* @return Type
*/
abstract protected function getKeyType(): Type;
/**
* @return string
*/
abstract protected function getGenericUsage(): string;
/**
* {@inheritdoc}
*/
public function findType(string $typeClass): ?Type
{
return parent::findType($typeClass) ?: $this->valueType->findType($typeClass);
}
}