Skip to content
Permalink
Browse files

Merge pull request #65 from tarlepp/feat/no-more-form-types-in-contro…

…llers

Refactor/Remove form types in controllers
  • Loading branch information...
tarlepp committed Jun 22, 2019
2 parents 474000c + 9b4be56 commit 25c7fc84dc1dba95b266e72a51877b914c335d6b
Showing with 3,162 additions and 2,708 deletions.
  1. +2 −0 .codeclimate.yml
  2. +3 −1 .idea/php.xml
  3. +2 −0 .idea/symfony-flex-backend.iml
  4. +5 −0 Makefile
  5. +1 −0 composer.json
  6. +92 −2 composer.lock
  7. +1 −0 config/bundles.php
  8. +1 −1 config/packages/test/framework.yaml
  9. +6 −2 config/packages/test/services.yaml
  10. +6 −0 config/services.yaml
  11. +1 −1 docker-entrypoint-dev.sh
  12. +111 −0 src/ArgumentResolver/RestDtoValueResolver.php
  13. +3 −3 src/ArgumentResolver/UserValueResolver.php
  14. +44 −0 src/AutoMapper/ApiKey/AutoMapperConfiguration.php
  15. +69 −0 src/AutoMapper/ApiKey/RequestMapper.php
  16. +48 −0 src/AutoMapper/RestAutoMapperConfiguration.php
  17. +111 −0 src/AutoMapper/RestRequestMapper.php
  18. +44 −0 src/AutoMapper/User/AutoMapperConfiguration.php
  19. +68 −0 src/AutoMapper/User/RequestMapper.php
  20. +102 −0 src/Collection/CollectionTrait.php
  21. +1 −1 src/Command/ApiKey/CreateApiKeyCommand.php
  22. +1 −1 src/Command/ApiKey/EditApiKeyCommand.php
  23. +1 −1 src/Command/User/CreateUserCommand.php
  24. +1 −1 src/Command/User/CreateUserGroupCommand.php
  25. +1 −1 src/Command/User/EditUserCommand.php
  26. +1 −1 src/Command/User/EditUserGroupCommand.php
  27. +9 −0 src/Controller/ApiKeyController.php
  28. +1 −2 src/Controller/AuthController.php
  29. +7 −12 src/Controller/UserController.php
  30. +10 −10 src/Controller/UserGroupController.php
  31. +13 −49 src/DTO/{ → ApiKey}/ApiKey.php
  32. +19 −0 src/DTO/ApiKey/ApiKeyCreate.php
  33. +22 −0 src/DTO/ApiKey/ApiKeyPatch.php
  34. +19 −0 src/DTO/ApiKey/ApiKeyUpdate.php
  35. +30 −1 src/DTO/RestDto.php
  36. +19 −12 src/DTO/RestDtoInterface.php
  37. +33 −0 src/DTO/Traits/PatchUserGroups.php
  38. +16 −57 src/DTO/{ → User}/User.php
  39. +29 −0 src/DTO/User/UserCreate.php
  40. +22 −0 src/DTO/User/UserPatch.php
  41. +19 −0 src/DTO/User/UserUpdate.php
  42. +8 −8 src/DTO/{ → UserGroup}/UserGroup.php
  43. +27 −0 src/DTO/UserGroup/UserGroupCreate.php
  44. +19 −0 src/DTO/UserGroup/UserGroupPatch.php
  45. +27 −0 src/DTO/UserGroup/UserGroupUpdate.php
  46. +7 −7 src/Entity/ApiKey.php
  47. +9 −8 src/Entity/Traits/UserRelations.php
  48. +1 −1 src/Entity/User.php
  49. +51 −0 src/Entity/UserGroupAwareInterface.php
  50. +2 −2 src/EventSubscriber/AuthenticationFailureSubscriber.php
  51. +5 −12 src/EventSubscriber/LockedUserSubscriber.php
  52. +9 −3 src/Form/Type/Console/ApiKeyType.php
  53. +137 −2 src/Form/Type/Console/UserGroupType.php
  54. +9 −3 src/Form/Type/Console/UserType.php
  55. +0 −38 src/Form/Type/Rest/User/UserCreateType.php
  56. +0 −103 src/Form/Type/Rest/User/UserPatchType.php
  57. +0 −90 src/Form/Type/Rest/User/UserType.php
  58. +0 −37 src/Form/Type/Rest/User/UserUpdateType.php
  59. +0 −147 src/Form/Type/Rest/UserGroup/UserGroupType.php
  60. +1 −2 src/Repository/BaseRepositoryInterface.php
  61. +2 −11 src/Repository/Traits/RepositoryMethodsTrait.php
  62. +2 −0 src/Resource/ApiKeyResource.php
  63. +21 −58 src/Resource/Collection.php
  64. +2 −0 src/Resource/DateDimensionResource.php
  65. +2 −0 src/Resource/HealthzResource.php
  66. +2 −1 src/Resource/LogLoginFailureResource.php
  67. +2 −0 src/Resource/LogLoginResource.php
  68. +2 −0 src/Resource/LogRequestResource.php
  69. +2 −0 src/Resource/RoleResource.php
  70. +2 −0 src/Resource/UserGroupResource.php
  71. +5 −2 src/Resource/UserResource.php
  72. +11 −0 src/Rest/Controller.php
  73. +68 −0 src/Rest/ControllerCollection.php
  74. +4 −38 src/Rest/ControllerInterface.php
  75. +20 −55 src/Rest/RestResource.php
  76. +29 −19 src/Rest/RestResourceInterface.php
  77. +5 −12 src/Rest/Traits/Actions/Admin/CreateAction.php
  78. +6 −16 src/Rest/Traits/Actions/Admin/PatchAction.php
  79. +6 −16 src/Rest/Traits/Actions/Admin/UpdateAction.php
  80. +5 −12 src/Rest/Traits/Actions/Anon/CreateAction.php
  81. +6 −16 src/Rest/Traits/Actions/Anon/PatchAction.php
  82. +6 −16 src/Rest/Traits/Actions/Anon/UpdateAction.php
  83. +5 −12 src/Rest/Traits/Actions/Authenticated/CreateAction.php
  84. +6 −16 src/Rest/Traits/Actions/Authenticated/PatchAction.php
  85. +6 −16 src/Rest/Traits/Actions/Authenticated/UpdateAction.php
  86. +5 −12 src/Rest/Traits/Actions/Logged/CreateAction.php
  87. +6 −16 src/Rest/Traits/Actions/Logged/PatchAction.php
  88. +6 −16 src/Rest/Traits/Actions/Logged/UpdateAction.php
  89. +60 −0 src/Rest/Traits/Actions/RestActionBase.php
  90. +5 −12 src/Rest/Traits/Actions/Root/CreateAction.php
  91. +6 −16 src/Rest/Traits/Actions/Root/PatchAction.php
  92. +6 −16 src/Rest/Traits/Actions/Root/UpdateAction.php
  93. +5 −12 src/Rest/Traits/Actions/User/CreateAction.php
  94. +6 −16 src/Rest/Traits/Actions/User/PatchAction.php
  95. +6 −16 src/Rest/Traits/Actions/User/UpdateAction.php
  96. +0 −47 src/Rest/Traits/Methods/AbstractFormMethods.php
  97. +10 −15 src/Rest/Traits/Methods/AbstractGenericMethods.php
  98. +1 −11 src/Rest/Traits/Methods/CountMethod.php
  99. +7 −18 src/Rest/Traits/Methods/CreateMethod.php
  100. +1 −11 src/Rest/Traits/Methods/DeleteMethod.php
  101. +1 −11 src/Rest/Traits/Methods/FindMethod.php
  102. +1 −11 src/Rest/Traits/Methods/FindOneMethod.php
  103. +1 −11 src/Rest/Traits/Methods/IdsMethod.php
  104. +8 −23 src/Rest/Traits/Methods/PatchMethod.php
  105. +8 −23 src/Rest/Traits/Methods/UpdateMethod.php
  106. +4 −97 src/Rest/Traits/RestMethodHelper.php
  107. +51 −6 src/Rest/Traits/RestResourceBaseMethods.php
  108. +9 −9 src/Rest/Traits/RestResourceFind.php
  109. +1 −0 src/Rest/Traits/RestResourceLifeCycles.php
  110. +51 −0 src/Rest/Traits/RestResourcePatch.php
  111. +13 −13 src/Utils/Tests/RestTraitTestCase.php
  112. +6 −0 symfony.lock
  113. +11 −14 tests/E2E/Controller/ApiKeyControllerTest.php
  114. +25 −34 tests/E2E/Controller/AuthControllerTest.php
  115. +5 −4 tests/E2E/Controller/DefaultControllerTest.php
  116. +12 −36 tests/E2E/Controller/ProfileControllerTest.php
  117. +17 −25 tests/E2E/Controller/RoleControllerTest.php
  118. +127 −116 tests/E2E/Controller/UserControllerTest.php
  119. +22 −43 tests/E2E/Controller/UserGroupControllerTest.php
  120. +9 −6 tests/E2E/Rest/Traits/Actions/src/AdminActionsController.php
  121. +8 −4 tests/E2E/Rest/Traits/Actions/src/AnonActionsController.php
  122. +8 −4 tests/E2E/Rest/Traits/Actions/src/AuthenticatedActionsController.php
  123. +8 −4 tests/E2E/Rest/Traits/Actions/src/LoggedActionsController.php
  124. +8 −4 tests/E2E/Rest/Traits/Actions/src/RootActionsController.php
  125. +8 −4 tests/E2E/Rest/Traits/Actions/src/UserActionsController.php
  126. +102 −0 tests/Integration/AutoMapper/ApiKey/RequestMapperTest.php
  127. +99 −0 tests/Integration/AutoMapper/GenericRestRequestMapperTest.php
  128. +63 −0 tests/Integration/AutoMapper/RestRequestMapperTestCase.php
  129. +102 −0 tests/Integration/AutoMapper/User/RequestMapperTest.php
  130. +41 −0 tests/Integration/AutoMapper/src/TestRestRequestMapper.php
  131. +84 −0 tests/Integration/AutoMapper/src/TestRestRequestMapperDto.php
  132. +23 −0 tests/Integration/DTO/ApiKey/ApiKeyCreateTest.php
  133. +23 −0 tests/Integration/DTO/ApiKey/ApiKeyPatchTest.php
  134. +9 −4 tests/Integration/DTO/{ → ApiKey}/ApiKeyTest.php
  135. +23 −0 tests/Integration/DTO/ApiKey/ApiKeyUpdateTest.php
  136. +30 −48 tests/Integration/DTO/DtoTestCase.php
  137. +1 −1 tests/Integration/DTO/GenericDtoTest.php
  138. +23 −0 tests/Integration/DTO/User/UserCreateTest.php
  139. +23 −0 tests/Integration/DTO/User/UserPatchTest.php
  140. +12 −10 tests/Integration/DTO/{ → User}/UserTest.php
  141. +23 −0 tests/Integration/DTO/User/UserUpdateTest.php
  142. +23 −0 tests/Integration/DTO/UserGroup/UserGroupCreateTest.php
  143. +23 −0 tests/Integration/DTO/UserGroup/UserGroupPatchTest.php
  144. +5 −4 tests/Integration/DTO/{ → UserGroup}/UserGroupTest.php
  145. +23 −0 tests/Integration/DTO/UserGroup/UserGroupUpdateTest.php
  146. +13 −0 tests/Integration/DTO/src/DummyDto.php
  147. +5 −1 tests/Integration/Form/Type/Console/ApiKeyTypeTest.php
  148. +5 −1 tests/Integration/Form/Type/Console/UserGroupTypeTest.php
  149. +5 −1 tests/Integration/Form/Type/Console/UserTypeTest.php
  150. +0 −65 tests/Integration/Form/Type/Rest/User/UserCreateTypeTest.php
  151. +0 −63 tests/Integration/Form/Type/Rest/User/UserPatchTypeTest.php
  152. +0 −65 tests/Integration/Form/Type/Rest/User/UserUpdateTypeTest.php
  153. +0 −133 tests/Integration/Form/Type/Rest/UserGroup/UserGroupTypeTest.php
  154. +4 −20 tests/Integration/Resource/GenericResourceTest.php
  155. +108 −0 tests/Integration/Rest/ControllerCollectionTest.php
  156. +0 −46 tests/Integration/Rest/ControllerTest.php
  157. +3 −2 tests/Integration/Rest/Traits/Actions/Admin/ActionTest.php
  158. +3 −2 tests/Integration/Rest/Traits/Actions/Anon/ActionTest.php
  159. +3 −2 tests/Integration/Rest/Traits/Actions/Authenticated/ActionTest.php
  160. +3 −2 tests/Integration/Rest/Traits/Actions/Logged/ActionTest.php
  161. +3 −2 tests/Integration/Rest/Traits/Actions/Root/ActionTest.php
  162. +8 −7 tests/Integration/Rest/Traits/Actions/User/ActionTest.php
  163. +29 −141 tests/Integration/Rest/Traits/Methods/CreateMethodTest.php
  164. +35 −162 tests/Integration/Rest/Traits/Methods/PatchMethodTest.php
  165. +16 −180 tests/Integration/Rest/Traits/Methods/UpdateMethodTest.php
  166. +2 −0 tests/Integration/Rest/Traits/Methods/src/CountMethodInvalidTestClass.php
  167. +2 −0 tests/Integration/Rest/Traits/Methods/src/CreateMethodInvalidTestClass.php
  168. +0 −1 tests/Integration/Rest/Traits/Methods/src/CreateMethodTestClass.php
  169. +2 −0 tests/Integration/Rest/Traits/Methods/src/DeleteMethodInvalidTestClass.php
  170. +2 −0 tests/Integration/Rest/Traits/Methods/src/FindMethodInvalidTestClass.php
  171. +2 −0 tests/Integration/Rest/Traits/Methods/src/FindOneMethodInvalidTestClass.php
  172. +2 −0 tests/Integration/Rest/Traits/Methods/src/IdsMethodInvalidTestClass.php
  173. +3 −1 tests/Integration/Rest/Traits/Methods/src/PatchMethodInvalidTestClass.php
  174. +3 −1 tests/Integration/Rest/Traits/Methods/src/UpdateMethodInvalidTestClass.php
  175. +42 −1 tests/Unit/IntegrityTest.php
  176. +7 −7 vendor-bin/infection/composer.lock
  177. +12 −61 vendor-bin/phpunit/composer.lock
@@ -7,6 +7,8 @@ plugins:
languages:
php:
mass_threshold: 55
editorconfig:
enabled: true
fixme:
enabled: true
phpmd:
@@ -128,6 +128,8 @@
<path value="$PROJECT_DIR$/vendor/symfony/console" />
<path value="$PROJECT_DIR$/vendor/symfony/debug-pack" />
<path value="$PROJECT_DIR$/vendor" />
<path value="$PROJECT_DIR$/vendor/mark-gerarts/auto-mapper-plus" />
<path value="$PROJECT_DIR$/vendor/mark-gerarts/automapper-plus-bundle" />
</include_path>
</component>
<component name="PhpInterpreters">
@@ -226,4 +228,4 @@
<phpunit_by_interpreter interpreter_id="7377c17b-0802-4cb1-95f7-8eb151a88214" load_method="CUSTOM_LOADER" configuration_file_path="/app/phpunit.xml.dist" custom_loader_path="/app/vendor-bin/phpunit/vendor/autoload.php" phpunit_phar_path="" use_configuration_file="true" />
</phpunit_settings>
</component>
</project>
</project>
@@ -67,6 +67,8 @@
<excludeFolder url="file://$MODULE_DIR$/vendor/jdorn/sql-formatter" />
<excludeFolder url="file://$MODULE_DIR$/vendor/lcobucci/jwt" />
<excludeFolder url="file://$MODULE_DIR$/vendor/lexik/jwt-authentication-bundle" />
<excludeFolder url="file://$MODULE_DIR$/vendor/mark-gerarts/auto-mapper-plus" />
<excludeFolder url="file://$MODULE_DIR$/vendor/mark-gerarts/automapper-plus-bundle" />
<excludeFolder url="file://$MODULE_DIR$/vendor/matthiasnoback/symfony-console-form" />
<excludeFolder url="file://$MODULE_DIR$/vendor/monolog/monolog" />
<excludeFolder url="file://$MODULE_DIR$/vendor/mustangostang/spyc" />
@@ -202,3 +202,8 @@ check-vendor-dependencies: ## Checks if any vendor dependency can be updated
@echo "\033[32mChecking dependencies\033[39m"
@bin/console check-vendor-dependencies
###< clear vendor-bin ###

###> update composer dependencies ###
update: ## Update composer dependencies
@php -d memory_limit=-1 /usr/bin/composer update
###< update composer dependencies ###
@@ -31,6 +31,7 @@
"doctrine/doctrine-migrations-bundle": "2.0.0",
"easycorp/easy-log-handler": "1.0.7",
"lexik/jwt-authentication-bundle": "2.6.3",
"mark-gerarts/automapper-plus-bundle": "1.1.0",
"matthiasnoback/symfony-console-form": "3.6.0",
"nelmio/api-doc-bundle": "3.4.0",
"nelmio/cors-bundle": "1.5.6",

Some generated files are not rendered by default. Learn more.

@@ -19,4 +19,5 @@
Symfony\Bundle\WebServerBundle\WebServerBundle::class => ['dev' => true],
Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true],
Symfony\Bundle\MakerBundle\MakerBundle::class => ['dev' => true],
AutoMapperPlus\AutoMapperPlusBundle\AutoMapperPlusBundle::class => ['all' => true],
];
@@ -1,5 +1,5 @@
framework:
test: ~
test: true
session:
storage_id: session.storage.mock_file
profiler:
@@ -14,11 +14,15 @@ services:

App\Tests\E2E\Rest\src\Controller\:
resource: '../../../tests/E2E/Rest/src/Controller/*'
tags: [ 'controller.service_arguments' ]
tags:
- 'controller.service_arguments'
- 'app.rest.controller'

App\Tests\E2E\Rest\Traits\Actions\src\:
resource: '../../../tests/E2E/Rest/Traits/Actions/src/*'
tags: [ 'controller.service_arguments' ]
tags:
- 'controller.service_arguments'
- 'app.rest.controller'

App\Tests\Integration\Helpers\src\:
resource: '../../../tests/Integration/Helpers/src/*'
@@ -20,6 +20,9 @@ services:
# The best practice is to be explicit about your dependencies anyway.
bind:
$projectDir: '%kernel.project_dir%'
_instanceof:
App\Rest\ControllerInterface:
tags: [ 'app.rest.controller' ]

# makes classes in src/ available to be used as services
# this creates a service per class whose id is the fully-qualified class name
@@ -45,6 +48,9 @@ services:
App\Resource\Collection:
arguments: [ !tagged app.rest.resource ]

App\Rest\ControllerCollection:
arguments: [ !tagged app.rest.controller ]

App\Security\RolesService:
arguments: [ '%security.role_hierarchy.roles%' ]

@@ -36,7 +36,7 @@ rm -rf /app/var
mkdir -p /app/var

# Step 3
composer install
php -d memory_limit=-1 /usr/bin/composer install

# Step 4
make generate-jwt-keys
@@ -0,0 +1,111 @@
<?php
declare(strict_types = 1);
/**
* /src/ArgumentResolver/RestDtoValueResolver.php
*
* @author TLe, Tarmo Leppänen <tarmo.leppanen@protacon.com>
*/
namespace App\ArgumentResolver;
use App\DTO\RestDtoInterface;
use App\Rest\Controller;
use App\Rest\ControllerCollection;
use AutoMapperPlus\AutoMapperInterface;
use AutoMapperPlus\Exception\UnregisteredMappingException;
use Generator;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\Controller\ArgumentValueResolverInterface;
use Symfony\Component\HttpKernel\ControllerMetadata\ArgumentMetadata;
use function count;
use function explode;
use function in_array;
/**
* Class RestDtoValueResolver
*
* @package App\ArgumentResolver
* @author TLe, Tarmo Leppänen <tarmo.leppanen@protacon.com>
*/
class RestDtoValueResolver implements ArgumentValueResolverInterface
{
/**
* @var array|string[]
*/
private $supportedActions = [
Controller::ACTION_CREATE,
Controller::ACTION_UPDATE,
Controller::ACTION_PATCH,
];
/**
* @var array|array<string, string>
*/
private $actionMethodMap = [
Controller::ACTION_CREATE => Controller::METHOD_CREATE,
Controller::ACTION_UPDATE => Controller::METHOD_UPDATE,
Controller::ACTION_PATCH => Controller::METHOD_PATCH,
];
/**
* @var ControllerCollection
*/
private $controllerCollection;
/**
* @var AutoMapperInterface
*/
private $autoMapper;
/**
* RestDtoValueResolver constructor.
*
* @param ControllerCollection $controllerCollection
* @param AutoMapperInterface $autoMapper
*/
public function __construct(ControllerCollection $controllerCollection, AutoMapperInterface $autoMapper)
{
$this->controllerCollection = $controllerCollection;
$this->autoMapper = $autoMapper;
}
/**
* Whether this resolver can resolve the value for the given ArgumentMetadata.
*
* @param Request $request
* @param ArgumentMetadata $argument
*
* @return bool
*/
public function supports(Request $request, ArgumentMetadata $argument): bool
{
if (count(explode('::', $request->attributes->get('_controller'))) !== 2) {
return false;
}
[$controllerName, $actionName] = explode('::', $request->attributes->get('_controller'));
return $argument->getType() === RestDtoInterface::class
&& in_array($actionName, $this->supportedActions, true)
&& $this->controllerCollection->has($controllerName);
}
/**
* Returns the possible value(s).
*
* @param Request $request
* @param ArgumentMetadata $argumentMetadata
*
* @return Generator
*
* @throws UnregisteredMappingException
*/
public function resolve(Request $request, ArgumentMetadata $argumentMetadata): Generator
{
[$controllerName, $actionName] = explode('::', $request->attributes->get('_controller'));
$dtoClass = $this->controllerCollection->get($controllerName)->getDtoClass($this->actionMethodMap[$actionName]);
yield $this->autoMapper->map($request, $dtoClass);
}
}
@@ -78,14 +78,14 @@ public function supports(Request $request, ArgumentMetadata $argument): bool
/**
* Returns the possible value(s).
*
* @param Request $request
* @param ArgumentMetadata $argument
* @param Request $request
* @param ArgumentMetadata $argumentMetadata
*
* @return Generator
*
* @throws Throwable
*/
public function resolve(Request $request, ArgumentMetadata $argument): Generator
public function resolve(Request $request, ArgumentMetadata $argumentMetadata): Generator
{
/** @noinspection NullPointerExceptionInspection */
/**

0 comments on commit 25c7fc8

Please sign in to comment.
You can’t perform that action at this time.