Skip to content

Commit

Permalink
Merge pull request #42 from chubbyphp/chubbyphp-mongo-parsing
Browse files Browse the repository at this point in the history
chubbyphp-mongo-parsing
  • Loading branch information
dominikzogg committed Feb 11, 2024
2 parents 21e518e + a8c445b commit fd2da7d
Show file tree
Hide file tree
Showing 108 changed files with 2,550 additions and 2,831 deletions.
116 changes: 63 additions & 53 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,22 @@ A simple skeleton to build api's based on the [chubbyphp-framework][1].
## Requirements

* php: ^8.1
* [chubbyphp/chubbyphp-api-http][2]: ^6.0
* [chubbyphp/chubbyphp-clean-directories][3]: ^1.3.1
* [chubbyphp/chubbyphp-cors][4]: ^1.5
* [chubbyphp/chubbyphp-decode-encode][5]: ^1.1
* [chubbyphp/chubbyphp-deserialization][6]: ^4.1
* [chubbyphp/chubbyphp-framework][7]: ^5.1.1
* [chubbyphp/chubbyphp-framework-router-fastroute][8]: ^2.1
* [chubbyphp/chubbyphp-http-exception][9]: ^1.1
* [chubbyphp/chubbyphp-laminas-config][10]: ^1.4
* [chubbyphp/chubbyphp-laminas-config-doctrine][11]: ^2.2
* [chubbyphp/chubbyphp-laminas-config-factory][12]: ^1.3
* [chubbyphp/chubbyphp-negotiation][13]: ^2.0
* [chubbyphp/chubbyphp-serialization][14]: ^4.0
* [chubbyphp/chubbyphp-validation][15]: ^4.0
* [doctrine/mongodb-odm][16]: ^2.4.2
* [monolog/monolog][17]: ^3.5
* [ramsey/uuid][18]: ^4.7.5
* [slim/psr7][19]: ^1.6.1
* [symfony/console][20]: ^6.4.2
* [chubbyphp/chubbyphp-clean-directories][2]: ^1.3.1
* [chubbyphp/chubbyphp-cors][3]: ^1.5
* [chubbyphp/chubbyphp-decode-encode][4]: ^1.1
* [chubbyphp/chubbyphp-framework][5]: ^5.1.1
* [chubbyphp/chubbyphp-framework-router-fastroute][6]: ^2.1
* [chubbyphp/chubbyphp-http-exception][7]: ^1.1
* [chubbyphp/chubbyphp-laminas-config][8]: ^1.4
* [chubbyphp/chubbyphp-laminas-config-doctrine][9]: ^2.2
* [chubbyphp/chubbyphp-laminas-config-factory][10]: ^1.3
* [chubbyphp/chubbyphp-negotiation][11]: ^2.0
* [chubbyphp/chubbyphp-parsing][12]: ^1.0
* [doctrine/mongodb-odm][13]: ^2.4.2
* [monolog/monolog][14]: ^3.5
* [ramsey/uuid][15]: ^4.7.5
* [slim/psr7][16]: ^1.6.1
* [symfony/console][17]: ^6.4.2

## Environment

Expand Down Expand Up @@ -86,82 +83,95 @@ Collections are sortable, filterable paginated lists of models.

* [App\Collection][60]

### Factory
### Dto

Factories to create collections, model or whatever you need to be created.
A DTO, or Data Transfer Object, is a simple object used to transport data between software application components.

* [App\Factory][70]
* [App\Dto][70]

### Mapping
### Middleware

Mappings are used for deserialization, odm, serialization and validation defintions. They are all done in PHP.
Middleware functions can execute code, make changes to the request and response objects.
Middleware can generally be added globally or on a per-route basis.

* [App\Mapping][80]
* [App\Middleware][80]

### Model

Models, entities, documents what ever fits your purpose the best.

* [App\Model][90]

### ODM

ODM Mapping definitions.

* [App\ODM][100]

### Parsing

Parses and validates data against predefined schemas, ensuring that incoming data conforms to expected structures and criteria.

* [App\Parsing][110]

### Repository

Repositories get data from storages like databases, elasticsearch, redis or whereever your models are stored or cached.

* [App\Repository][100]
* [App\Repository][120]

### RequestHandler

RequestHandler alias Controller, or Controller actions to be more precise.
There is a directory with generic crud controllers. If you like the idea adapt them for your generic use case, if not drop them.
I highly recommend to not extend them.

* [App\RequestHandler][110]
* [App\RequestHandler][130]

### ServiceFactory

Service factories are the glue code of the dependeny injection container.

* [App\ServiceFactory][120]
* [App\ServiceFactory][140]

## Copyright

2023 Dominik Zogg

[1]: https://github.com/chubbyphp/chubbyphp-framework

[2]: https://packagist.org/packages/chubbyphp/chubbyphp-api-http
[3]: https://packagist.org/packages/chubbyphp/chubbyphp-clean-directories
[4]: https://packagist.org/packages/chubbyphp/chubbyphp-cors
[5]: https://packagist.org/packages/chubbyphp/chubbyphp-decode-encode
[6]: https://packagist.org/packages/chubbyphp/chubbyphp-deserialization
[7]: https://packagist.org/packages/chubbyphp/chubbyphp-framework
[8]: https://packagist.org/packages/chubbyphp/chubbyphp-framework-router-fastroute
[9]: https://packagist.org/packages/chubbyphp/chubbyphp-http-exception
[10]: https://packagist.org/packages/chubbyphp/chubbyphp-laminas-config
[11]: https://packagist.org/packages/chubbyphp/chubbyphp-laminas-config-doctrine
[12]: https://packagist.org/packages/chubbyphp/chubbyphp-laminas-config-factory
[13]: https://packagist.org/packages/chubbyphp/chubbyphp-negotiation
[14]: https://packagist.org/packages/chubbyphp/chubbyphp-serialization
[15]: https://packagist.org/packages/chubbyphp/chubbyphp-validation
[16]: https://packagist.org/packages/doctrine/mongodb-odm
[17]: https://packagist.org/packages/monolog/monolog
[18]: https://packagist.org/packages/ramsey/uuid
[19]: https://packagist.org/packages/slim/psr7
[20]: https://packagist.org/packages/symfony/console
[2]: https://packagist.org/packages/chubbyphp/chubbyphp-clean-directories
[3]: https://packagist.org/packages/chubbyphp/chubbyphp-cors
[4]: https://packagist.org/packages/chubbyphp/chubbyphp-decode-encode
[5]: https://packagist.org/packages/chubbyphp/chubbyphp-framework
[6]: https://packagist.org/packages/chubbyphp/chubbyphp-framework-router-fastroute
[7]: https://packagist.org/packages/chubbyphp/chubbyphp-http-exception
[8]: https://packagist.org/packages/chubbyphp/chubbyphp-laminas-config
[9]: https://packagist.org/packages/chubbyphp/chubbyphp-laminas-config-doctrine
[10]: https://packagist.org/packages/chubbyphp/chubbyphp-laminas-config-factory
[11]: https://packagist.org/packages/chubbyphp/chubbyphp-negotiation
[12]: https://packagist.org/packages/chubbyphp/chubbyphp-parsing
[13]: https://packagist.org/packages/doctrine/mongodb-odm
[14]: https://packagist.org/packages/monolog/monolog
[15]: https://packagist.org/packages/ramsey/uuid
[16]: https://packagist.org/packages/slim/psr7
[17]: https://packagist.org/packages/symfony/console

[40]: https://packagist.org/packages/chubbyphp/petstore

[60]: src/Collection

[70]: src/Factory
[70]: src/Dto

[80]: src/Mapping
[80]: src/Middleware

[90]: src/Model

[100]: src/Repository
[100]: src/Odm

[110]: src/Parsing

[120]: src/Repository

[110]: src/RequestHandler
[130]: src/RequestHandler

[120]: src/ServiceFactory
[140]: src/ServiceFactory
9 changes: 3 additions & 6 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",
"doctrine/mongodb-odm": "^2.4.3",
"monolog/monolog": "^3.5",
"ramsey/uuid": "^4.7.5",
Expand Down Expand Up @@ -86,7 +83,7 @@
"@test:cs"
],
"test:cs": "mkdir -p build && PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --dry-run --stop-on-violation --cache-file=build/phpcs.cache",
"test:infection": "vendor/bin/infection --threads=$(nproc) --min-msi=97 --verbose --coverage=build/phpunit",
"test:infection": "vendor/bin/infection --threads=$(nproc) --min-msi=94 --verbose --coverage=build/phpunit",
"test:integration": "vendor/bin/phpunit --configuration phpunit.integration.xml --cache-result-file=build/phpunit/result.integration.cache",
"test:lint": "mkdir -p build && find src tests -name '*.php' -print0 | xargs -0 -n1 -P$(nproc) php -l | tee build/phplint.log",
"test:static-analysis": "mkdir -p build && bash -c 'vendor/bin/phpstan analyse src --no-progress --level=8 --error-format=junit | tee build/phpstan.junit.xml; if [ ${PIPESTATUS[0]} -ne \"0\" ]; then exit 1; fi'",
Expand Down
78 changes: 31 additions & 47 deletions config/prod.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,23 @@

declare(strict_types=1);

use App\Factory\Collection\PetCollectionFactory;
use App\Factory\Model\PetFactory;
use App\Mapping\Odm\PetMapping;
use App\Mapping\Odm\VaccinationMapping;
use App\Middleware\ApiExceptionMiddleware;
use App\Model\Pet;
use App\Model\Vaccination;
use App\Odm\PetMapping;
use App\Odm\VaccinationMapping;
use App\Parsing\PetParsing;
use App\Repository\PetRepository;
use App\RequestHandler\Api\Crud\CreateRequestHandler;
use App\RequestHandler\Api\Crud\DeleteRequestHandler;
use App\RequestHandler\Api\Crud\ListRequestHandler;
use App\RequestHandler\Api\Crud\ReadRequestHandler;
use App\RequestHandler\Api\Crud\UpdateRequestHandler;
use App\RequestHandler\PingRequestHandler;
use App\RequestHandler\OpenapiRequestHandler;
use App\RequestHandler\PingRequestHandler;
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\Framework\ExceptionMiddlewareFactory;
use App\ServiceFactory\Framework\MiddlewaresFactory;
use App\ServiceFactory\Framework\RouteMatcherFactory;
Expand All @@ -31,33 +28,27 @@
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\PetParsingFactory;
use App\ServiceFactory\Repository\PetRepositoryFactory;
use App\ServiceFactory\RequestHandler\Api\Crud\PetCreateRequestHandlerFactory;
use App\ServiceFactory\RequestHandler\Api\Crud\PetDeleteRequestHandlerFactory;
use App\ServiceFactory\RequestHandler\Api\Crud\PetListRequestHandlerFactory;
use App\ServiceFactory\RequestHandler\Api\Crud\PetReadRequestHandlerFactory;
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 App\ServiceFactory\RequestHandler\PingRequestHandlerFactory;
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 @@ -68,25 +59,22 @@
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\ODM\MongoDB\DocumentManager;
use Doctrine\Persistence\Mapping\Driver\MappingDriver;
use Monolog\Level;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Http\Message\ResponseFactoryInterface;
use Psr\Http\Message\StreamFactoryInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
use Psr\Cache\CacheItemPoolInterface;

$rootDir = \realpath(__DIR__ . '/..');
$cacheDir = $rootDir . '/var/cache/' . $env;
Expand All @@ -106,47 +94,43 @@
'debug' => false,
'dependencies' => [
'factories' => [
AcceptAndContentTypeMiddleware::class => AcceptAndContentTypeMiddlewareFactory::class,
AcceptNegotiatorInterface::class => AcceptNegotiatorFactory::class,
AcceptMiddleware::class => AcceptMiddlewareFactory::class,
AcceptNegotiatorInterface::class . 'supportedMediaTypes[]' => AcceptNegotiatorSupportedMediaTypesFactory::class,
AcceptNegotiatorInterface::class . 'supportedMediaTypes[]' => AcceptNegotiatorSupportedMediaTypesFactory::class,
AcceptNegotiatorInterface::class => AcceptNegotiatorFactory::class,
ApiExceptionMiddleware::class => ApiExceptionMiddlewareFactory::class,
CacheItemPoolInterface::class => ApcuAdapterFactory::class,
Command::class . '[]' => CommandsFactory::class,
ContentTypeNegotiatorInterface::class => ContentTypeNegotiatorFactory::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,
DocumentManager::class => DocumentManagerFactory::class,
EncoderInterface::class => EncoderFactory::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,
OpenapiRequestHandler::class => OpenapiRequestHandlerFactory::class,
ParserInterface::class => ParserFactory::class,
Pet::class . CreateRequestHandler::class => PetCreateRequestHandlerFactory::class,
Pet::class . DeleteRequestHandler::class => PetDeleteRequestHandlerFactory::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,
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,
UrlGeneratorInterface::class => UrlGeneratorFactory::class,
SerializerInterface::class => SerializerFactory::class,
StreamFactoryInterface::class => StreamFactoryFactory::class,
OpenapiRequestHandler::class => OpenapiRequestHandlerFactory::class,
TypeDecoderInterface::class . '[]' => TypeDecodersFactory::class,
TypeEncoderInterface::class . '[]' => TypeEncodersFactory::class,
ValidationMappingProviderInterface::class . '[]' => ValidationMappingProviderFactory::class,
ValidationMappingProviderRegistryInterface::class => ValidationMappingProviderRegistryFactory::class,
ValidatorInterface::class => ValidatorFactory::class,
UrlGeneratorInterface::class => UrlGeneratorFactory::class,
],
],
'directories' => [
Expand Down
11 changes: 4 additions & 7 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
parameters:
ignoreErrors:
-
message: '#Method App\\Mapping\\Odm\\PetMapping\:\:configureMapping\(\) has parameter \$metadata with generic class Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata but does not specify its types\: T#'
path: %currentWorkingDirectory%/src/Mapping/Odm/PetMapping.php
message: '#Method App\\Odm\\PetMapping\:\:configureMapping\(\) has parameter \$metadata with generic class Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata but does not specify its types\: T#'
path: %currentWorkingDirectory%/src/Odm/PetMapping.php
-
message: '#Method App\\Mapping\\Odm\\VaccinationMapping\:\:configureMapping\(\) has parameter \$metadata with generic class Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata but does not specify its types\: T#'
path: %currentWorkingDirectory%/src/Mapping/Odm/VaccinationMapping.php
-
message: '#PHPDoc tag @var for variable \$queryParams has no value type specified in iterable type array\.#'
path: %currentWorkingDirectory%/src/Mapping/Serialization/AbstractCollectionMapping.php
message: '#Method App\\Odm\\VaccinationMapping\:\:configureMapping\(\) has parameter \$metadata with generic class Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata but does not specify its types\: T#'
path: %currentWorkingDirectory%/src/Odm/VaccinationMapping.php
-
message: '#PHPDoc tag @var for variable \$documentRepository contains generic class Doctrine\\ODM\\MongoDB\\Repository\\DocumentRepository but does not specify its types\: T#'
path: %currentWorkingDirectory%/src/Repository/PetRepository.php
Expand Down

0 comments on commit fd2da7d

Please sign in to comment.