Skip to content

Commit

Permalink
chubbyphp-parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikzogg committed Feb 7, 2024
1 parent 356c691 commit befa852
Show file tree
Hide file tree
Showing 60 changed files with 918 additions and 1,007 deletions.
7 changes: 2 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,17 @@
],
"require": {
"php": "^8.1",
"chubbyphp/chubbyphp-api-http": "^6.0",
"chubbyphp/chubbyphp-clean-directories": "^1.3.1",
"chubbyphp/chubbyphp-cors": "^1.5",
"chubbyphp/chubbyphp-decode-encode": "^1.1",
"chubbyphp/chubbyphp-deserialization": "^4.1",
"chubbyphp/chubbyphp-framework": "^5.1.1",
"chubbyphp/chubbyphp-framework-router-fastroute": "^2.1",
"chubbyphp/chubbyphp-http-exception": "^1.1",
"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-serialization": "^4.0",
"chubbyphp/chubbyphp-validation": "^4.0",
"chubbyphp/chubbyphp-negotiation": "^2.1",
"chubbyphp/chubbyphp-parsing": "^1.0@dev",
"doctrine/orm": "^2.17.2",
"monolog/monolog": "^3.5",
"ramsey/uuid": "^4.7.5",
Expand Down
64 changes: 26 additions & 38 deletions config/prod.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

declare(strict_types=1);

use App\Factory\Collection\PetCollectionFactory;
use App\Factory\Model\PetFactory;
use App\Enrich\EnrichInterface;
use App\Mapping\Orm\PetMapping;
use App\Mapping\Orm\VaccinationMapping;
use App\Middleware\ApiExceptionMiddleware;
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 @@ -20,9 +22,7 @@
use App\ServiceFactory\Command\CommandsFactory;
use App\ServiceFactory\DecodeEncode\TypeDecodersFactory;
use App\ServiceFactory\DecodeEncode\TypeEncodersFactory;
use App\ServiceFactory\Deserialization\DenormalizationObjectMappingsFactory;
use App\ServiceFactory\Factory\Collection\PetCollectionFactoryFactory;
use App\ServiceFactory\Factory\Model\PetFactoryFactory;
use App\ServiceFactory\Enrich\PetEnrichFactory;
use App\ServiceFactory\Framework\ExceptionMiddlewareFactory;
use App\ServiceFactory\Framework\MiddlewaresFactory;
use App\ServiceFactory\Framework\RouteMatcherFactory;
Expand All @@ -32,8 +32,12 @@
use App\ServiceFactory\Http\ResponseFactoryFactory;
use App\ServiceFactory\Http\StreamFactoryFactory;
use App\ServiceFactory\Logger\LoggerFactory;
use App\ServiceFactory\Middleware\ApiExceptionMiddlewareFactory;
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 @@ -42,23 +46,14 @@
use App\ServiceFactory\RequestHandler\Api\Crud\PetUpdateRequestHandlerFactory;
use App\ServiceFactory\RequestHandler\PingRequestHandlerFactory;
use App\ServiceFactory\RequestHandler\OpenapiRequestHandlerFactory;
use App\ServiceFactory\Serialization\NormalizationObjectMappingsFactory;
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\Deserialization\DeserializerInterface;
use Chubbyphp\Deserialization\Mapping\DenormalizationObjectMappingInterface;
use Chubbyphp\Deserialization\ServiceFactory\DeserializerFactory;
use Chubbyphp\DecodeEncode\ServiceFactory\DecoderFactory;
use Chubbyphp\DecodeEncode\ServiceFactory\EncoderFactory;
use Chubbyphp\Framework\Middleware\ExceptionMiddleware;
use Chubbyphp\Framework\Middleware\RouteMatcherMiddleware;
use Chubbyphp\Framework\Router\RouteMatcherInterface;
Expand All @@ -72,16 +67,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\Serialization\Mapping\NormalizationObjectMappingInterface;
use Chubbyphp\Serialization\SerializerInterface;
use Chubbyphp\Serialization\ServiceFactory\SerializerFactory;
use Chubbyphp\Validation\Mapping\ValidationMappingProviderInterface;
use Chubbyphp\Validation\Mapping\ValidationMappingProviderRegistryInterface;
use Chubbyphp\Validation\ServiceFactory\ValidationMappingProviderRegistryFactory;
use Chubbyphp\Validation\ServiceFactory\ValidatorFactory;
use Chubbyphp\Validation\ValidatorInterface;
use Chubbyphp\Parsing\ParserInterface;
use Doctrine\DBAL\Tools\Console\ConnectionProvider;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
Expand Down Expand Up @@ -116,50 +108,46 @@
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,
DenormalizationObjectMappingInterface::class . '[]' => DenormalizationObjectMappingsFactory::class,
DeserializerInterface::class => DeserializerFactory::class,
DecoderInterface::class => DecoderFactory::class,
EncoderInterface::class => EncoderFactory::class,
EntityManagerInterface::class => EntityManagerFactory::class,
EntityManagerProvider::class => ContainerEntityManagerProviderFactory::class,
ExceptionMiddleware::class => ExceptionMiddlewareFactory::class,
LoggerInterface::class => LoggerFactory::class,
MappingDriver::class => ClassMapDriverFactory::class,
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,
PetFactory::class => PetFactoryFactory::class,
PetCollectionParsing::class => PetCollectionParsingFactory::class,
PetParsing::class => PetParsingFactory::class,
PetRepository::class => PetRepositoryFactory::class,
PingRequestHandler::class => PingRequestHandlerFactory::class,
RequestManagerInterface::class => RequestManagerFactory::class,
ResponseFactoryInterface::class => ResponseFactoryFactory::class,
ResponseManagerInterface::class => ResponseManagerFactory::class,
RouteMatcherInterface::class => RouteMatcherFactory::class,
RouteMatcherMiddleware::class => RouteMatcherMiddlewareFactory::class,
RoutesByNameInterface::class => RoutesByNameFactory::class,
SerializerInterface::class => SerializerFactory::class,
StreamFactoryInterface::class => StreamFactoryFactory::class,
TypeDecoderInterface::class . '[]' => TypeDecodersFactory::class,
TypeEncoderInterface::class . '[]' => TypeEncodersFactory::class,
UrlGeneratorInterface::class => UrlGeneratorFactory::class,
ValidationMappingProviderInterface::class . '[]' => ValidationMappingProviderFactory::class,
ValidationMappingProviderRegistryInterface::class => ValidationMappingProviderRegistryFactory::class,
ValidatorInterface::class => ValidatorFactory::class,
],
],
'directories' => [
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;
}
}
31 changes: 31 additions & 0 deletions src/Dto/Collection/PetCollectionResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

declare(strict_types=1);

namespace App\Dto\Collection;

final class PetCollectionResponse
{
public int $offset;

public int $limit;

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

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

public PetCollectionResponseEmbedded $_embedded;

public int $count;

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

declare(strict_types=1);

namespace App\Dto\Collection;

final class PetCollectionResponseEmbedded
{
/**
* @var array<PetResponse>
*/
public array $items;
}
22 changes: 22 additions & 0 deletions src/Dto/LinkResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace App\Dto;

final class LinkResponse
{
public string $href;

public bool $templated;

/**
* @var array<string>
*/
public array $rel;

/**
* @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;
}
Loading

0 comments on commit befa852

Please sign in to comment.