Commit b6fbac68 authored by Guillaume Perréal's avatar Guillaume Perréal
Browse files

Ajout des classes déjà écrites.

parent bd9d5374
No related merge requests found
Showing with 2392 additions and 377 deletions
+2392 -377
This file is part of "%package%".
"%package%" generates Typescript interfaces for Angular using api-platform metadata.
Copyright (C) %yearRange% IRSTEA
This program is free software: you can redistribute it and/or modify it under
......
......@@ -30,6 +30,7 @@
},
"require": {
"php": "^7.1",
"api-platform/core": "^2.4",
"beberlei/assert": "^3.2"
},
"require-dev": {
......@@ -42,7 +43,8 @@
"phpunit/phpunit": "^7.5",
"roave/security-advisories": "dev-master",
"sebastian/phpcpd": "^4.1",
"sensiolabs/security-checker": "^5.0"
"sensiolabs/security-checker": "^5.0",
"symfony/http-kernel": "^4.2"
},
"autoload": {
"psr-4": {
......
This diff is collapsed.
<?php declare(strict_types=1);
/*
* This file is part of "irstea/api-metadata".
*
* Copyright (C) 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\ApiMetadata\Bridge\Bundle;
/**
* Class IrsteaApiMetadataBundle.
*/
final class IrsteaApiMetadataBundle
{
}
<?php declare(strict_types=1);
/*
* This file is part of "irstea/api-metadata".
*
* Copyright (C) 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\ApiMetadata\DataProvider;
use ApiPlatform\Core\Api\OperationMethodResolverInterface;
use ApiPlatform\Core\Api\OperationType;
use ApiPlatform\Core\DataProvider\CollectionDataProviderInterface;
use ApiPlatform\Core\DataProvider\ItemDataProviderInterface;
use ApiPlatform\Core\DataProvider\RestrictedDataProviderInterface;
use ApiPlatform\Core\Exception\PropertyNotFoundException;
use ApiPlatform\Core\Exception\ResourceClassNotFoundException;
use ApiPlatform\Core\Metadata\Property\Factory\PropertyMetadataFactoryInterface;
use ApiPlatform\Core\Metadata\Property\Factory\PropertyNameCollectionFactoryInterface;
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface;
use ApiPlatform\Core\Metadata\Resource\ResourceMetadata as APIResourceMetadata;
use ApiPlatform\Core\PathResolver\OperationPathResolverInterface;
use Irstea\ApiMetadata\Model\EmbeddedMetadata;
use Irstea\ApiMetadata\Model\LinkMetadata;
use Irstea\ApiMetadata\Model\OperationMetadata;
use Irstea\ApiMetadata\Model\PropertyMetadata;
use Irstea\ApiMetadata\Model\ResourceMetadata;
use Irstea\ApiMetadata\Model\ScalarMetadata;
use Irstea\ApiMetadata\Model\TypeMetadata;
use Symfony\Component\PropertyInfo\Type;
/**
* Class ResourceMetadataProvider.
*/
class ResourceMetadataProvider implements CollectionDataProviderInterface, ItemDataProviderInterface, RestrictedDataProviderInterface
{
/**
* @var ResourceNameCollectionFactoryInterface
*/
private $resourceNameCollectionFactory;
/**
* @var ResourceMetadataFactoryInterface
*/
private $resourceMetadataFactory;
/**
* @var PropertyMetadataFactoryInterface
*/
private $propertyMetadataFactory;
/**
* @var PropertyNameCollectionFactoryInterface
*/
private $propertyNameCollectionFactory;
/**
* @var OperationMethodResolverInterface
*/
private $operationMethodResolver;
/**
* @var OperationPathResolverInterface
*/
private $operationPathResolver;
/**
* ResourceMetadataProvider constructor.
*
* @param ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory
* @param ResourceMetadataFactoryInterface $resourceMetadataFactory
* @param PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory
* @param PropertyMetadataFactoryInterface $propertyMetadataFactory
* @param OperationMethodResolverInterface $operationMethodResolver
* @param OperationPathResolverInterface $operationPathResolver
*/
public function __construct(
ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory,
ResourceMetadataFactoryInterface $resourceMetadataFactory,
PropertyNameCollectionFactoryInterface $propertyNameCollectionFactory,
PropertyMetadataFactoryInterface $propertyMetadataFactory,
OperationMethodResolverInterface $operationMethodResolver,
OperationPathResolverInterface $operationPathResolver
) {
$this->resourceNameCollectionFactory = $resourceNameCollectionFactory;
$this->resourceMetadataFactory = $resourceMetadataFactory;
$this->propertyMetadataFactory = $propertyMetadataFactory;
$this->propertyNameCollectionFactory = $propertyNameCollectionFactory;
$this->operationMethodResolver = $operationMethodResolver;
$this->operationPathResolver = $operationPathResolver;
}
/**
* @param string $resourceClass
* @param string|null $operationName
* @param array $context
*
* @return bool
*/
public function supports(string $resourceClass, string $operationName = null, array $context = []): bool
{
return $resourceClass === ResourceMetadata::class && $operationName === 'get';
}
/**
* {@inheritdoc}
*/
public function getCollection(string $resourceClass, string $operationName = null): \Generator
{
foreach ($this->resourceNameCollectionFactory->create() as $className) {
$metadata = $this->getResourceMetadata($className);
yield $metadata->shortName => $metadata;
}
}
/**
* {@inheritdoc}
*/
public function getItem(string $resourceClass, $id, string $operationName = null, array $context = [])
{
foreach ($this->resourceNameCollectionFactory->create() as $className) {
$resource = $this->resourceMetadataFactory->create($className);
if ($resource->getShortName() === $id) {
return $this->getResourceMetadata($className);
}
}
return null;
}
/**
* @param string $resourceClass
*
* @throws PropertyNotFoundException
* @throws ResourceClassNotFoundException
*
* @return ResourceMetadata
*/
private function getResourceMetadata(string $resourceClass): ResourceMetadata
{
$resource = $this->resourceMetadataFactory->create($resourceClass);
$properties = [];
foreach ($this->propertyNameCollectionFactory->create($resourceClass) as $name) {
$prop = $this->getPropertyMetadata($resourceClass, $name);
$properties[$prop->name] = $prop;
}
$operations = [];
foreach ($resource->getItemOperations() as $name => $attributes) {
$operations[] = $this->getOperationMetadata($resource, $resourceClass, OperationType::ITEM, $name, $attributes);
}
foreach ($resource->getCollectionOperations() as $name => $attributes) {
$operations[] = $this->getOperationMetadata($resource, $resourceClass, OperationType::COLLECTION, $name, $attributes);
}
return new ResourceMetadata(
$resource->getShortName(),
$properties,
$operations
);
}
/**
* @param string $resourceClass
* @param string $name
*
* @throws PropertyNotFoundException
*
* @return PropertyMetadata
*/
private function getPropertyMetadata(string $resourceClass, string $name): PropertyMetadata
{
$property = $this->propertyMetadataFactory->create($resourceClass, $name);
$type = $property->getType();
return new PropertyMetadata(
$name,
$this->getTypeMetadata($type),
$type && !$type->isNullable(),
!$property->isWritable() ?: false,
$property->isIdentifier() ?: false
);
}
/**
* @param Type|null $type
*
* @return TypeMetadata
*/
private function getTypeMetadata(?Type $type): TypeMetadata
{
if (!$type) {
return ScalarMetadata::create('any');
}
if ($type->isCollection()) {
return $this->getCollectionMetadata($type->getCollectionKeyType(), $type->getCollectionValueType());
}
if (!$type->getClassName()) {
return ScalarMetadata::create($type->getBuiltinType());
}
$className = $type->getClassName();
try {
$this->resourceMetadataFactory->create($className);
return LinkMetadata::create($className);
} catch (ResourceClassNotFoundException $ex) {
// Pass
}
return EmbeddedMetadata::create($className);
}
/**
* @param APIResourceMetadata $resource
* @param string $resourceClass
* @param string $type
* @param string $name
* @param array $attributes
*
* @return OperationMetadata
*/
private function getOperationMetadata(APIResourceMetadata $resource, string $resourceClass, string $type, string $name, array $attributes): OperationMetadata
{
$path = $this->operationPathResolver->resolveOperationPath($resource->getShortName(), $attributes, $type, $name);
$getter = $type === 'collection' ? 'getCollectionOperationMethod' : 'getItemOperationMethod';
$method = $this->operationMethodResolver->$getter($resourceClass, $name);
return new OperationMetadata(
$type,
$name,
$path,
$method,
null,
null
);
}
}
<?php declare(strict_types=1);
/*
* This file is part of "irstea/api-metadata".
*
* Copyright (C) 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\ApiMetadata\Factory;
use Irstea\ApiMetadata\Model\OperationMetadata;
/**
* Class OperationFactory.
*/
final class OperationFactory implements OperationFactoryInterface
{
/**
* {@inheritdoc}
*/
public function create(string $class, string $type, string $name): OperationMetadata
{
throw new \RuntimeException('Not yet implemented');
}
/**
* {@inheritdoc}
*/
public function enumerate(string $class): array
{
throw new \RuntimeException('Not yet implemented');
}
}
<?php declare(strict_types=1);
/*
* This file is part of "irstea/api-metadata".
*
* Copyright (C) 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\ApiMetadata\Factory;
use Irstea\ApiMetadata\Model\OperationMetadata;
/**
* Class OperationFactoryInterface.
*/
interface OperationFactoryInterface
{
/**
* @param string $class
* @param string $type
* @param string $name
*
* @return OperationMetadata
*/
public function create(string $class, string $type, string $name): OperationMetadata;
/**
* @param string $class
*
* @return OperationMetadata[]
*/
public function enumerate(string $class): array;
}
<?php declare(strict_types=1);
/*
* This file is part of "irstea/api-metadata".
*
* Copyright (C) 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\ApiMetadata\Factory;
use Irstea\ApiMetadata\Model\PropertyMetadata;
/**
* Class PropertyFactory.
*/
final class PropertyFactory implements PropertyFactoryInterface
{
/**
* {@inheritdoc}
*/
public function create(string $class, string $name): PropertyMetadata
{
throw new \RuntimeException('Not yet implemented');
}
/**
* {@inheritdoc}
*/
public function enumerate(string $class): array
{
throw new \RuntimeException('Not yet implemented');
}
}
<?php declare(strict_types=1);
/*
* This file is part of "irstea/api-metadata".
*
* Copyright (C) 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\ApiMetadata\Factory;
use Irstea\ApiMetadata\Model\PropertyMetadata;
/**
* Class PropertyFactoryInterface.
*/
interface PropertyFactoryInterface
{
/**
* @param string $class
* @param string $name
*
* @return PropertyMetadata
*/
public function create(string $class, string $name): PropertyMetadata;
/**
* @param string $class
*
* @return PropertyMetadata[]
*/
public function enumerate(string $class): array;
}
<?php declare(strict_types=1);
/*
* This file is part of "irstea/api-metadata".
*
* Copyright (C) 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\ApiMetadata\Factory;
/**
* Class ResourcePropertyFactory.
*/
final class ResourcePropertyFactory
{
}
<?php declare(strict_types=1);
/*
* This file is part of "irstea/api-metadata".
*
* Copyright (C) 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\ApiMetadata\Factory;
use ApiPlatform\Core\Exception\ResourceClassNotFoundException;
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
use Irstea\ApiMetadata\Model\ResourceMetadata;
use Irstea\ApiMetadata\Model\TypeMetadata;
use Symfony\Component\PropertyInfo\Type;
/**
* Class ResourceTypeFactory.
*/
final class ResourceTypeFactory implements TypeFactoryInterface
{
/** @var OperationFactoryInterface */
private $operationFactory;
/** @var PropertyFactoryInterface */
private $propertyFactory;
/** @var ResourceMetadataFactoryInterface */
private $resourceMetadataFactory;
/**
* @var TypeFactoryInterface
*/
private $decorated;
/**
* ResourceTypeFactory constructor.
*
* @param PropertyFactoryInterface $propertyFactory
* @param OperationFactoryInterface $operationFactory
* @param ResourceMetadataFactoryInterface $resourceMetadataFactory
* @param TypeFactoryInterface|null $decorated
*/
public function __construct(
PropertyFactoryInterface $propertyFactory,
OperationFactoryInterface $operationFactory,
ResourceMetadataFactoryInterface $resourceMetadataFactory,
TypeFactoryInterface $decorated = null
) {
$this->operationFactory = $operationFactory;
$this->propertyFactory = $propertyFactory;
$this->resourceMetadataFactory = $resourceMetadataFactory;
$this->decorated = $decorated;
}
/**
* {@inheritdoc}
*/
public function create(?Type $type): TypeMetadata
{
$resourceClass = $type ? $type->getClassName() : null;
if (!$resourceClass) {
return $this->decorated->create($type);
}
try {
$resource = $this->resourceMetadataFactory->create($resourceClass);
} catch (ResourceClassNotFoundException $ex) {
if ($this->decorated) {
return $this->decorated->create($type);
}
throw $ex;
}
/* $properties = [];
foreach ($this->propertyNameCollectionFactory->create($resourceClass) as $name) {
$prop = $this->getPropertyMetadata($resourceClass, $name);
$properties[$prop->name] = $prop;
}
$operations = [];
foreach ($resource->getItemOperations() as $name => $attributes) {
$operations[] = $this->getOperationMetadata($resource, $resourceClass, OperationType::ITEM, $name, $attributes);
}
foreach ($resource->getCollectionOperations() as $name => $attributes) {
$operations[] = $this->getOperationMetadata($resource, $resourceClass, OperationType::COLLECTION, $name, $attributes);
}*/
return new ResourceMetadata(
$resource->getShortName(),
$this->propertyFactory->enumerate($resourceClass),
$this->operationFactory->enumerate($resourceClass)
);
}
}
<?php declare(strict_types=1);
/*
* This file is part of "irstea/api-metadata".
*
* Copyright (C) 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\ApiMetadata\Factory;
use Irstea\ApiMetadata\Model\ArrayMetadata;
use Irstea\ApiMetadata\Model\EmbeddedMetadata;
use Irstea\ApiMetadata\Model\MapMetadata;
use Irstea\ApiMetadata\Model\ScalarMetadata;
use Irstea\ApiMetadata\Model\TypeMetadata;
use Symfony\Component\PropertyInfo\Type;
/**
* Class TypeFactory.
*/
final class TypeFactory implements TypeFactoryInterface
{
/**
* @var TypeFactoryInterface
*/
private $typeFactory;
/**
* TypeFactory constructor.
*
* @param TypeFactoryInterface|null $typeFactory
*/
public function __construct(TypeFactoryInterface $typeFactory = null)
{
$this->typeFactory = $typeFactory ?: $this;
}
/**
* Set typeFactory.
*
* @param TypeFactoryInterface $typeFactory
*/
public function setTypeFactory(TypeFactoryInterface $typeFactory): void
{
$this->typeFactory = $typeFactory;
}
/**
* {@inheritdoc}
*/
public function create(?Type $type): TypeMetadata
{
if (!$type) {
return ScalarMetadata::create('any');
}
if ($type->isCollection()) {
return $this->getCollectionMetadata($type->getCollectionKeyType(), $type->getCollectionValueType());
}
if (!$type->getClassName()) {
return ScalarMetadata::create($type->getBuiltinType());
}
$className = $type->getClassName();
return EmbeddedMetadata::create($className);
}
/**
* @param Type|null $keyType
* @param Type|null $valueType
*
* @return TypeMetadata
*/
private function getCollectionMetadata(?Type $keyType, ?Type $valueType): TypeMetadata
{
if (!$keyType) {
return ScalarMetadata::create('any');
}
if ($keyType->getBuiltinType() === 'int') {
return new ArrayMetadata($this->typeFactory->create($valueType));
}
return new MapMetadata(
$this->typeFactory->create($keyType),
$this->typeFactory->create($valueType)
);
}
}
<?php declare(strict_types=1);
/*
* This file is part of "irstea/api-metadata".
*
* Copyright (C) 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\ApiMetadata\Factory;
use Irstea\ApiMetadata\Model\TypeMetadata;
use Symfony\Component\PropertyInfo\Type;
/**
* Class TypeFactoryInterface.
*/
interface TypeFactoryInterface
{
/**
* @param Type|null $type
*
* @return TypeMetadata
*/
public function create(?Type $type): TypeMetadata;
}
<?php declare(strict_types=1);
/*
* This file is part of "irstea/api-metadata".
*
* Copyright (C) 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\ApiMetadata\Model;
/**
* Class ArrayMetadata.
*/
final class ArrayMetadata extends TypeMetadata
{
/** @var TypeMetadata */
public $valueType;
/**
* ArrayMetadata constructor.
*
* @param TypeMetadata $valueType
*/
public function __construct(TypeMetadata $valueType)
{
$this->valueType = $valueType;
}
}
<?php declare(strict_types=1);
/*
* This file is part of "irstea/api-metadata".
*
* Copyright (C) 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\ApiMetadata\Model;
/**
* Class EmbeddedMetadata.
*/
final class EmbeddedMetadata extends TypeMetadata
{
use MultitonTrait;
}
<?php declare(strict_types=1);
/*
* This file is part of "irstea/api-metadata".
*
* Copyright (C) 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\ApiMetadata\Model;
/**
* Class LinkMetadata.
*/
final class LinkMetadata extends TypeMetadata
{
use MultitonTrait;
}
<?php declare(strict_types=1);
/*
* This file is part of "irstea/api-metadata".
*
* Copyright (C) 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\ApiMetadata\Model;
/**
* Class MapMetadata.
*/
final class MapMetadata extends TypeMetadata
{
/** @var TypeMetadata */
public $keyType;
/** @var TypeMetadata */
public $valueType;
/**
* MapMetadata constructor.
*
* @param TypeMetadata $keyType
* @param TypeMetadata $valueType
*/
public function __construct(TypeMetadata $keyType, TypeMetadata $valueType)
{
$this->keyType = $keyType;
$this->valueType = $valueType;
}
}
<?php declare(strict_types=1);
/*
* This file is part of "irstea/api-metadata".
*
* Copyright (C) 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\ApiMetadata\Model;
/**
* Class MultitonTrait.
*/
trait MultitonTrait
{
/** @var string */
public $name;
/**
* ScalarMetadata constructor.
*
* @param string $name
*/
protected function __construct(string $name)
{
$this->name = $name;
}
/**
* @param string $name
*
* @return ScalarMetadata
*/
public static function create(string $name): self
{
static $instance = [];
if (!isset($instance[$name])) {
$instance[$name] = new self($name);
}
return $instance[$name];
}
}
<?php declare(strict_types=1);
/*
* This file is part of "irstea/api-metadata".
*
* Copyright (C) 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\ApiMetadata\Model;
use Assert\Assertion;
/**
* Class ObjectMetadata.
*/
class ObjectMetadata extends TypeMetadata
{
/**
* @var array<string, PropertyMetadata>
*/
public $properties;
/**
* ObjectMetadata constructor.
*
* @param PropertyMetadata[] $properties
*/
public function __construct(array $properties)
{
Assertion::allIsInstanceOf($properties, PropertyMetadata::class);
$this->properties = $properties;
}
}
<?php declare(strict_types=1);
/*
* This file is part of "irstea/api-metadata".
*
* Copyright (C) 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\ApiMetadata\Model;
/**
* Class OperationMetadata.
*/
final class OperationMetadata
{
/** @var string */
public $type;
/** @var string */
public $name;
/** @var string */
public $path;
/** @var string */
public $method;
/** @var TypeMetadata|null */
public $input;
/** @var TypeMetadata|null */
public $output;
/**
* OperationMetadata constructor.
*
* @param string $type
* @param string $name
* @param string $path
* @param string $method
* @param TypeMetadata|null $input
* @param TypeMetadata|null $output
*/
public function __construct(string $type, string $name, string $path, string $method, ?TypeMetadata $input, ?TypeMetadata $output)
{
$this->type = $type;
$this->name = $name;
$this->path = $path;
$this->method = $method;
$this->input = $input;
$this->output = $output;
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment