Skip to content

Commit

Permalink
chubbyphp-parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
dominikzogg committed Feb 10, 2024
1 parent 356c691 commit 176a6ca
Show file tree
Hide file tree
Showing 106 changed files with 2,547 additions and 2,823 deletions.
115 changes: 62 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/orm][16]: ^2.17.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/orm][13]: ^2.17.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,94 @@ 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.
Data transer objects, for example coverting data from request to model and viseversa.

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

### Mapping
### Middleware

Mappings are used for deserialization, orm, serialization and validation defintions. They are all done in PHP.
Middlewares which can be added generic or to specific routes.

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

### Model

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

* [App\Model][90]

### ORM

ORM Mapping definitions.

* [App\ORM][100]

### Parsing

Parsing data to DTO's, for example in request/response cycle.

* [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

2024 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/orm
[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/orm
[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/Orm

[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@dev",
"doctrine/orm": "^2.17.2",
"monolog/monolog": "^3.5",
"ramsey/uuid": "^4.7.5",
Expand Down Expand Up @@ -91,7 +88,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
73 changes: 29 additions & 44 deletions config/prod.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,24 @@

declare(strict_types=1);

use App\Factory\Collection\PetCollectionFactory;
use App\Factory\Model\PetFactory;
use App\Mapping\Orm\PetMapping;
use App\Mapping\Orm\VaccinationMapping;
use App\Middleware\ApiExceptionMiddleware;
use App\Model\Pet;
use App\Model\Vaccination;
use App\Orm\PetMapping;
use App\Orm\VaccinationMapping;
use App\Parsing\PetCollectionParsing;
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 Doctrine\DBAL\Connection;
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 @@ -32,33 +29,28 @@
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;
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 @@ -72,28 +64,26 @@
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\Connection;
use Doctrine\DBAL\Tools\Console\ConnectionProvider;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\Tools\Console\EntityManagerProvider;
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 @@ -116,50 +106,45 @@
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 . 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
11 changes: 4 additions & 7 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,17 +1,14 @@
parameters:
ignoreErrors:
-
message: '#Method App\\Mapping\\Orm\\PetMapping\:\:configureMapping\(\) has parameter \$metadata with generic class Doctrine\\ORM\\Mapping\\ClassMetadata but does not specify its types\: T#'
path: %currentWorkingDirectory%/src/Mapping/Orm/PetMapping.php
message: '#Method App\\Orm\\PetMapping\:\:configureMapping\(\) has parameter \$metadata with generic class Doctrine\\ORM\\Mapping\\ClassMetadata but does not specify its types\: T#'
path: %currentWorkingDirectory%/src/Orm/PetMapping.php
-
message: '#Method App\\Mapping\\Orm\\VaccinationMapping\:\:configureMapping\(\) has parameter \$metadata with generic class Doctrine\\ORM\\Mapping\\ClassMetadata but does not specify its types\: T#'
path: %currentWorkingDirectory%/src/Mapping/Orm/VaccinationMapping.php
message: '#Method App\\Orm\\VaccinationMapping\:\:configureMapping\(\) has parameter \$metadata with generic class Doctrine\\ORM\\Mapping\\ClassMetadata but does not specify its types\: T#'
path: %currentWorkingDirectory%/src/Orm/VaccinationMapping.php
-
message: '#PHPDoc tag @var for variable \$entityRepository contains generic class Doctrine\\ORM\\EntityRepository but does not specify its types\: T#'
path: %currentWorkingDirectory%/src/Repository/PetRepository.php
-
message: '#Property App\\Model\\Vaccination\:\:\$pet is never read, only written\.#'
path: %currentWorkingDirectory%/src/Model/Vaccination.php
-
message: '#PHPDoc tag @var for variable \$queryParams has no value type specified in iterable type array\.#'
path: %currentWorkingDirectory%/src/Mapping/Serialization/AbstractCollectionMapping.php
Loading

0 comments on commit 176a6ca

Please sign in to comment.