Skip to content

Commit

Permalink
chubbyphp-parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikzogg committed Feb 5, 2024
1 parent 356c691 commit 5790ae0
Show file tree
Hide file tree
Showing 34 changed files with 714 additions and 127 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"chubbyphp/chubbyphp-laminas-config": "^1.4",
"chubbyphp/chubbyphp-laminas-config-doctrine": "^2.1",
"chubbyphp/chubbyphp-laminas-config-factory": "^1.3",
"chubbyphp/chubbyphp-negotiation": "^2.0",
"chubbyphp/chubbyphp-negotiation": "^2.1",
"chubbyphp/chubbyphp-parsing": "^1.0@dev",
"chubbyphp/chubbyphp-serialization": "^4.0",
"chubbyphp/chubbyphp-validation": "^4.0",
"doctrine/orm": "^2.17.2",
Expand Down
27 changes: 24 additions & 3 deletions config/prod.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@

declare(strict_types=1);

use App\Enrich\EnrichInterface;
use App\Factory\Collection\PetCollectionFactory;
use App\Factory\Model\PetFactory;
use App\Mapping\Orm\PetMapping;
use App\Mapping\Orm\VaccinationMapping;
use App\Model\Pet;
use App\Model\Vaccination;
use App\Parsing\PetCollectionParsing;
use App\Parsing\PetParsing;
use App\Repository\PetRepository;
use App\RequestHandler\Api\Crud\CreateRequestHandler;
use App\RequestHandler\Api\Crud\DeleteRequestHandler;
Expand All @@ -21,6 +24,7 @@
use App\ServiceFactory\DecodeEncode\TypeDecodersFactory;
use App\ServiceFactory\DecodeEncode\TypeEncodersFactory;
use App\ServiceFactory\Deserialization\DenormalizationObjectMappingsFactory;
use App\ServiceFactory\Enrich\PetEnrichFactory;
use App\ServiceFactory\Factory\Collection\PetCollectionFactoryFactory;
use App\ServiceFactory\Factory\Model\PetFactoryFactory;
use App\ServiceFactory\Framework\ExceptionMiddlewareFactory;
Expand All @@ -34,6 +38,9 @@
use App\ServiceFactory\Logger\LoggerFactory;
use App\ServiceFactory\Negotiation\AcceptNegotiatorSupportedMediaTypesFactory;
use App\ServiceFactory\Negotiation\ContentTypeNegotiatorSupportedMediaTypesFactory;
use App\ServiceFactory\Parsing\ParserFactory;
use App\ServiceFactory\Parsing\PetCollectionParsingFactory;
use App\ServiceFactory\Parsing\PetParsingFactory;
use App\ServiceFactory\Repository\PetRepositoryFactory;
use App\ServiceFactory\RequestHandler\Api\Crud\PetCreateRequestHandlerFactory;
use App\ServiceFactory\RequestHandler\Api\Crud\PetDeleteRequestHandlerFactory;
Expand All @@ -46,16 +53,18 @@
use App\ServiceFactory\Validation\ValidationMappingProviderFactory;
use Chubbyphp\ApiHttp\Manager\RequestManagerInterface;
use Chubbyphp\ApiHttp\Manager\ResponseManagerInterface;
use Chubbyphp\ApiHttp\Middleware\AcceptAndContentTypeMiddleware;
use Chubbyphp\ApiHttp\Middleware\ApiExceptionMiddleware;
use Chubbyphp\ApiHttp\ServiceFactory\AcceptAndContentTypeMiddlewareFactory;
use Chubbyphp\ApiHttp\ServiceFactory\ApiExceptionMiddlewareFactory;
use Chubbyphp\ApiHttp\ServiceFactory\RequestManagerFactory;
use Chubbyphp\ApiHttp\ServiceFactory\ResponseManagerFactory;
use Chubbyphp\Cors\CorsMiddleware;
use Chubbyphp\Cors\ServiceFactory\CorsMiddlewareFactory;
use Chubbyphp\DecodeEncode\Decoder\DecoderInterface;
use Chubbyphp\DecodeEncode\Decoder\TypeDecoderInterface;
use Chubbyphp\DecodeEncode\Encoder\EncoderInterface;
use Chubbyphp\DecodeEncode\Encoder\TypeEncoderInterface;
use Chubbyphp\DecodeEncode\ServiceFactory\DecoderFactory;
use Chubbyphp\DecodeEncode\ServiceFactory\EncoderFactory;
use Chubbyphp\Deserialization\DeserializerInterface;
use Chubbyphp\Deserialization\Mapping\DenormalizationObjectMappingInterface;
use Chubbyphp\Deserialization\ServiceFactory\DeserializerFactory;
Expand All @@ -72,8 +81,13 @@
use Chubbyphp\Laminas\Config\Doctrine\ServiceFactory\Persistence\Mapping\Driver\ClassMapDriverFactory;
use Chubbyphp\Negotiation\AcceptNegotiatorInterface;
use Chubbyphp\Negotiation\ContentTypeNegotiatorInterface;
use Chubbyphp\Negotiation\Middleware\AcceptMiddleware;
use Chubbyphp\Negotiation\Middleware\ContentTypeMiddleware;
use Chubbyphp\Negotiation\ServiceFactory\AcceptMiddlewareFactory;
use Chubbyphp\Negotiation\ServiceFactory\AcceptNegotiatorFactory;
use Chubbyphp\Negotiation\ServiceFactory\ContentTypeMiddlewareFactory;
use Chubbyphp\Negotiation\ServiceFactory\ContentTypeNegotiatorFactory;
use Chubbyphp\Parsing\ParserInterface;
use Chubbyphp\Serialization\Mapping\NormalizationObjectMappingInterface;
use Chubbyphp\Serialization\SerializerInterface;
use Chubbyphp\Serialization\ServiceFactory\SerializerFactory;
Expand Down Expand Up @@ -116,19 +130,22 @@
EntityManager::class => EntityManagerInterface::class,
],
'factories' => [
AcceptAndContentTypeMiddleware::class => AcceptAndContentTypeMiddlewareFactory::class,
AcceptMiddleware::class => AcceptMiddlewareFactory::class,
AcceptNegotiatorInterface::class . 'supportedMediaTypes[]' => AcceptNegotiatorSupportedMediaTypesFactory::class,
AcceptNegotiatorInterface::class => AcceptNegotiatorFactory::class,
ApiExceptionMiddleware::class => ApiExceptionMiddlewareFactory::class,
CacheItemPoolInterface::class => ApcuAdapterFactory::class,
Command::class . '[]' => CommandsFactory::class,
Connection::class => ConnectionFactory::class,
ConnectionProvider::class => ContainerConnectionProviderFactory::class,
ContentTypeMiddleware::class => ContentTypeMiddlewareFactory::class,
ContentTypeNegotiatorInterface::class . 'supportedMediaTypes[]' => ContentTypeNegotiatorSupportedMediaTypesFactory::class,
ContentTypeNegotiatorInterface::class => ContentTypeNegotiatorFactory::class,
CorsMiddleware::class => CorsMiddlewareFactory::class,
DecoderInterface::class => DecoderFactory::class,
DenormalizationObjectMappingInterface::class . '[]' => DenormalizationObjectMappingsFactory::class,
DeserializerInterface::class => DeserializerFactory::class,
EncoderInterface::class => EncoderFactory::class,
EntityManagerInterface::class => EntityManagerFactory::class,
EntityManagerProvider::class => ContainerEntityManagerProviderFactory::class,
ExceptionMiddleware::class => ExceptionMiddlewareFactory::class,
Expand All @@ -137,13 +154,17 @@
MiddlewareInterface::class . '[]' => MiddlewaresFactory::class,
NormalizationObjectMappingInterface::class . '[]' => NormalizationObjectMappingsFactory::class,
OpenapiRequestHandler::class => OpenapiRequestHandlerFactory::class,
ParserInterface::class => ParserFactory::class,
Pet::class . CreateRequestHandler::class => PetCreateRequestHandlerFactory::class,
Pet::class . DeleteRequestHandler::class => PetDeleteRequestHandlerFactory::class,
Pet::class . EnrichInterface::class => PetEnrichFactory::class,
Pet::class . ListRequestHandler::class => PetListRequestHandlerFactory::class,
Pet::class . ReadRequestHandler::class => PetReadRequestHandlerFactory::class,
Pet::class . UpdateRequestHandler::class => PetUpdateRequestHandlerFactory::class,
PetCollectionFactory::class => PetCollectionFactoryFactory::class,
PetCollectionParsing::class => PetCollectionParsingFactory::class,
PetFactory::class => PetFactoryFactory::class,
PetParsing::class => PetParsingFactory::class,
PetRepository::class => PetRepositoryFactory::class,
PingRequestHandler::class => PingRequestHandlerFactory::class,
RequestManagerInterface::class => RequestManagerFactory::class,
Expand Down
20 changes: 20 additions & 0 deletions src/Collection/AbstractCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,24 @@ final public function getItems(): array
{
return $this->items;
}

/**
* @return array{offset: int, limit: int, filters: array<string, string>, sort: array<string, string>, items: array<ModelInterface>, count: int}
*/
public function jsonSerialize(): array
{
$items = [];
foreach ($this->items as $item) {
$items[] = $item->jsonSerialize();
}

return [
'offset' => $this->offset,
'limit' => $this->limit,
'filters' => $this->filters,
'sort' => $this->sort,
'items' => $items,
'count' => $this->count,
];
}
}
2 changes: 1 addition & 1 deletion src/Collection/CollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use App\Model\ModelInterface;

interface CollectionInterface
interface CollectionInterface extends \JsonSerializable
{
public const LIMIT = 20;

Expand Down
12 changes: 12 additions & 0 deletions src/Dto/Collection/CollectionRequestInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace App\Dto\Collection;

use App\Collection\CollectionInterface;

interface CollectionRequestInterface
{
public function createCollection(): CollectionInterface;
}
36 changes: 36 additions & 0 deletions src/Dto/Collection/PetCollectionRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace App\Dto\Collection;

use App\Collection\CollectionInterface;
use App\Collection\PetCollection;

final class PetCollectionRequest implements CollectionRequestInterface
{
public int $offset;

public int $limit;

/**
* @var array<string, string>
*/
public array $filters;

/**
* @var array<string, string>
*/
public array $sort;

public function createCollection(): CollectionInterface
{
$collection = new PetCollection();
$collection->setOffset($this->offset);
$collection->setLimit($this->limit);
$collection->setFilters($this->filters);
$collection->setSort($this->sort);

return $collection;
}
}
36 changes: 36 additions & 0 deletions src/Dto/Collection/PetCollectionResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

declare(strict_types=1);

namespace App\Dto\Collection;

use App\Dto\Model\PetResponse;

final class PetCollectionResponse
{
public int $offset;

public int $limit;

/**
* @var array<string, string>
*/
public array $filters;

/**
* @var array<string, string>
*/
public array $sort;

/**
* @var array<PetResponse>
*/
public array $items;

public int $count;

/**
* @var array<string, LinkResponse>
*/
public array $_links;
}
15 changes: 15 additions & 0 deletions src/Dto/LinkResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace App\Dto;

final class LinkResponse
{
public string $href;

/**
* @var array<string, string>
*/
public array $attributes;
}
14 changes: 14 additions & 0 deletions src/Dto/Model/ModelRequestInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace App\Dto\Model;

use App\Model\ModelInterface;

interface ModelRequestInterface
{
public function createModel(): ModelInterface;

public function updateModel(ModelInterface $model): ModelInterface;
}
59 changes: 59 additions & 0 deletions src/Dto/Model/PetRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

namespace App\Dto\Model;

use App\Model\ModelInterface;
use App\Model\Pet;
use App\Model\Vaccination;

final class PetRequest implements ModelRequestInterface
{
public string $name;

public null|string $tag;

/**
* @var array<VaccinationRequest>
*/
public array $vaccinations;

public function createModel(): ModelInterface
{
$vaccinations = [];
foreach ($this->vaccinations as $vaccinationRequest) {
$vaccination = new Vaccination();
$vaccination->setName($vaccinationRequest->name);

$vaccinations[] = $vaccination;
}

$model = new Pet();
$model->setName($this->name);
$model->setTag($this->tag);
$model->setVaccinations($vaccinations);

return $model;
}

/**
* @param Pet $model
*/
public function updateModel(ModelInterface $model): ModelInterface
{
$vaccinations = [];
foreach ($this->vaccinations as $vaccinationRequest) {
$vaccination = new Vaccination();
$vaccination->setName($vaccinationRequest->name);

$vaccinations[] = $vaccination;
}

$model->setName($this->name);
$model->setTag($this->tag);
$model->setVaccinations($vaccinations);

return $model;
}
}
30 changes: 30 additions & 0 deletions src/Dto/Model/PetResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace App\Dto\Model;

use App\Dto\LinkResponse;

final class PetResponse
{
public string $id;

public string $createdAt;

public null|string $updatedAt;

public string $name;

public null|string $tag;

/**
* @var array<VaccinationResponse>
*/
public array $vaccinations;

/**
* @var array<string, LinkResponse>
*/
public array $_links;
}
10 changes: 10 additions & 0 deletions src/Dto/Model/VaccinationRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace App\Dto\Model;

final class VaccinationRequest
{
public string $name;
}
10 changes: 10 additions & 0 deletions src/Dto/Model/VaccinationResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace App\Dto\Model;

final class VaccinationResponse
{
public string $name;
}
Loading

0 comments on commit 5790ae0

Please sign in to comment.