An error occurred while loading the file. Please try again.
-
Guillaume Perréal authored7ff53dc7
<?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-2019 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;
use Irstea\NgModelGeneratorBundle\Metadata\SerializationMetadata;
use Irstea\NgModelGeneratorBundle\Models\Types\Factory\BuiltinTypeFactory;
use Irstea\NgModelGeneratorBundle\Models\Types\Factory\CollectionTypeFactory;
use Irstea\NgModelGeneratorBundle\Models\Types\Factory\CompositeTypeFactory;
use Irstea\NgModelGeneratorBundle\Models\Types\Factory\Context;
use Irstea\NgModelGeneratorBundle\Models\Types\Factory\ContextInterface;
use Irstea\NgModelGeneratorBundle\Models\Types\Factory\DeferrableTypeFactory;
use Irstea\NgModelGeneratorBundle\Models\Types\Factory\NullableTypeFactory;
use Irstea\NgModelGeneratorBundle\Models\Types\Factory\ReflectionTypeFactory;
use Irstea\NgModelGeneratorBundle\Models\Types\Factory\TypeCache;
use Irstea\NgModelGeneratorBundle\Models\Types\Factory\TypeFactoryInterface;
use Symfony\Component\PropertyInfo\PropertyInfoExtractor;
/**
* Class ContextFactory.
*/
final class ContextFactory implements ContextFactoryInterface
{
/** @var TypeFactoryInterface */
private $nullableTypeFactory;
/** @var TypeFactoryInterface */
private $collectionTypeFactory;
/** @var TypeFactoryInterface */
private $reflectionTypeFactory;
/** @var TypeFactoryInterface */
private $builtinClassesTypeFactory;
/** @var TypeFactoryInterface */
private $builtinScalarsTypeFactory;
/**
* ContextFactory constructor.
* @param PropertyInfoExtractor $propertyInfoExtractor
*/
public function __construct(PropertyInfoExtractor $propertyInfoExtractor)
{
$this->nullableTypeFactory = new NullableTypeFactory();
$this->collectionTypeFactory = new CollectionTypeFactory();
$this->reflectionTypeFactory = TypeCache::decorate(new ReflectionTypeFactory($propertyInfoExtractor));
$this->builtinClassesTypeFactory = BuiltinTypeFactory::createWithClasses();
$this->builtinScalarsTypeFactory = BuiltinTypeFactory::createWithScalars();
}
/**
71727374757677787980818283848586878889909192939495
* {@inheritDoc}
*/
public function create(SerializationMetadata $serialization, bool $withAtFields): ContextInterface
{
$serializationMapper = new SerializationMapper($serialization, $withAtFields);
$typeFactory = TypeCache::decorate(
new CompositeTypeFactory([
$this->nullableTypeFactory,
$this->collectionTypeFactory,
$this->builtinClassesTypeFactory,
DeferrableTypeFactory::decorate(
new CompositeTypeFactory([
$serializationMapper,
$this->reflectionTypeFactory
])
),
$this->builtinScalarsTypeFactory
])
);
return new Context($typeFactory);
}
}