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 187 additions and 0 deletions
+187 -0
<?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 PropertyMetadata.
*/
final class PropertyMetadata
{
/** @var string */
public $name;
/** @var TypeMetadata */
public $type;
/** @var bool */
public $required;
/** @var bool */
public $readonly;
/** @var bool */
public $identifier;
/**
* PropertyMetadata constructor.
*
* @param string $name
* @param TypeMetadata $type
* @param bool $required
* @param bool $readonly
*/
public function __construct(string $name, TypeMetadata $type, bool $required, bool $readonly, bool $identifier)
{
$this->name = $name;
$this->type = $type;
$this->required = $required;
$this->readonly = $readonly;
$this->identifier = $identifier;
}
}
<?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 ApiPlatform\Core\Annotation as API;
use Assert\Assertion;
/**
* Class ResourceMetadata.
*
* @API\ApiResource
*/
final class ResourceMetadata extends ObjectMetadata
{
/**
* @API\ApiProperty(identifier=true)
*
* @var string
*/
public $shortName;
/** @var array<OperationMetadata> */
public $operations = [];
/**
* ResourceMetadata constructor.
*
* @param string $shortName
* @param OperationMetadata[] $operations
*/
public function __construct(string $shortName, array $properties, array $operations)
{
Assertion::allIsInstanceOf($operations, OperationMetadata::class);
parent::__construct($properties);
$this->shortName = $shortName;
$this->operations = $operations;
}
}
<?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 ScalarMetadata.
*/
final class ScalarMetadata 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;
use Doctrine\Common\Inflector\Inflector;
/**
* Class TypeMetadata.
*/
abstract class TypeMetadata implements \JsonSerializable
{
/**
* @return array|mixed
*/
public function jsonSerialize()
{
$fqcn = get_class($this);
$pos = strrpos($fqcn, '\\');
return [
'$type' => Inflector::tableize(substr($fqcn, $pos + 1, strlen($fqcn) - $pos - 9)),
] + \get_object_vars($this);
}
}
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