@@ -36,34 +36,34 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | class ThemesController extends Controller { |
| 38 | 38 | |
| 39 | - private CachedTenantContextInterface $cachedTenantContext; |
|
| 40 | - private FormFactoryInterface $formFactory; |
|
| 41 | - private ThemeLoader $themeLoader; |
|
| 42 | - private ThemeServiceInterface $themeService; |
|
| 43 | - private ThemeUploaderInterface $themeUploader; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @param CachedTenantContextInterface $cachedTenantContext |
|
| 47 | - * @param FormFactoryInterface $formFactory |
|
| 48 | - * @param ThemeLoader $themeLoader |
|
| 49 | - * @param ThemeServiceInterface $themeService |
|
| 50 | - * @param ThemeUploaderInterface $themeUploader |
|
| 51 | - */ |
|
| 52 | - public function __construct(CachedTenantContextInterface $cachedTenantContext, FormFactoryInterface $formFactory, |
|
| 53 | - ThemeLoader $themeLoader, ThemeServiceInterface $themeService, |
|
| 54 | - ThemeUploaderInterface $themeUploader) { |
|
| 39 | + private CachedTenantContextInterface $cachedTenantContext; |
|
| 40 | + private FormFactoryInterface $formFactory; |
|
| 41 | + private ThemeLoader $themeLoader; |
|
| 42 | + private ThemeServiceInterface $themeService; |
|
| 43 | + private ThemeUploaderInterface $themeUploader; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @param CachedTenantContextInterface $cachedTenantContext |
|
| 47 | + * @param FormFactoryInterface $formFactory |
|
| 48 | + * @param ThemeLoader $themeLoader |
|
| 49 | + * @param ThemeServiceInterface $themeService |
|
| 50 | + * @param ThemeUploaderInterface $themeUploader |
|
| 51 | + */ |
|
| 52 | + public function __construct(CachedTenantContextInterface $cachedTenantContext, FormFactoryInterface $formFactory, |
|
| 53 | + ThemeLoader $themeLoader, ThemeServiceInterface $themeService, |
|
| 54 | + ThemeUploaderInterface $themeUploader) { |
|
| 55 | 55 | $this->cachedTenantContext = $cachedTenantContext; |
| 56 | 56 | $this->formFactory = $formFactory; |
| 57 | 57 | $this->themeLoader = $themeLoader; |
| 58 | 58 | $this->themeService = $themeService; |
| 59 | 59 | $this->themeUploader = $themeUploader; |
| 60 | - } |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @Route("/api/{version}/organization/themes/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_list_available_themes") |
|
| 65 | - */ |
|
| 66 | - public function listAvailableAction(): ResourcesListResponseInterface { |
|
| 63 | + /** |
|
| 64 | + * @Route("/api/{version}/organization/themes/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_list_available_themes") |
|
| 65 | + */ |
|
| 66 | + public function listAvailableAction(): ResourcesListResponseInterface { |
|
| 67 | 67 | $themeLoader = $this->themeLoader; |
| 68 | 68 | $themes = $themeLoader->load(); |
| 69 | 69 | $pagination = new SlidingPagination(); |
@@ -73,21 +73,21 @@ discard block |
||
| 73 | 73 | $pagination->setTotalItemCount(count($themes)); |
| 74 | 74 | |
| 75 | 75 | return new ResourcesListResponse($pagination); |
| 76 | - } |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * @Route("/api/{version}/themes/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_list_tenant_themes") |
|
| 80 | - */ |
|
| 81 | - public function listInstalledAction(ThemeRepositoryInterface $themeRepository): ResourcesListResponseInterface { |
|
| 78 | + /** |
|
| 79 | + * @Route("/api/{version}/themes/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_list_tenant_themes") |
|
| 80 | + */ |
|
| 81 | + public function listInstalledAction(ThemeRepositoryInterface $themeRepository): ResourcesListResponseInterface { |
|
| 82 | 82 | /** @var TenantInterface $tenant */ |
| 83 | 83 | $tenant = $this->cachedTenantContext->getTenant(); |
| 84 | 84 | $tenantCode = $tenant->getCode(); |
| 85 | 85 | $themes = array_filter( |
| 86 | 86 | $themeRepository->findAll(), |
| 87 | 87 | static function ($element) use (&$tenantCode) { |
| 88 | - if (strpos($element->getName(), ThemeHelper::SUFFIX_SEPARATOR . $tenantCode)) { |
|
| 88 | + if (strpos($element->getName(), ThemeHelper::SUFFIX_SEPARATOR . $tenantCode)) { |
|
| 89 | 89 | return true; |
| 90 | - } |
|
| 90 | + } |
|
| 91 | 91 | } |
| 92 | 92 | ); |
| 93 | 93 | |
@@ -98,46 +98,46 @@ discard block |
||
| 98 | 98 | $pagination->setTotalItemCount(count($themes)); |
| 99 | 99 | |
| 100 | 100 | return new ResourcesListResponse($pagination); |
| 101 | - } |
|
| 101 | + } |
|
| 102 | 102 | |
| 103 | - /** |
|
| 104 | - * @Route("/api/{version}/organization/themes/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_upload_theme") |
|
| 105 | - */ |
|
| 106 | - public function uploadThemeAction(Request $request): SingleResourceResponseInterface { |
|
| 103 | + /** |
|
| 104 | + * @Route("/api/{version}/organization/themes/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_upload_theme") |
|
| 105 | + */ |
|
| 106 | + public function uploadThemeAction(Request $request): SingleResourceResponseInterface { |
|
| 107 | 107 | $form = $this->formFactory->createNamed('', ThemeUploadType::class, []); |
| 108 | 108 | $form->handleRequest($request); |
| 109 | 109 | if ($form->isSubmitted() && $form->isValid()) { |
| 110 | - $formData = $form->getData(); |
|
| 111 | - $themeUploader = $this->themeUploader; |
|
| 110 | + $formData = $form->getData(); |
|
| 111 | + $themeUploader = $this->themeUploader; |
|
| 112 | 112 | |
| 113 | - try { |
|
| 113 | + try { |
|
| 114 | 114 | $themePath = $themeUploader->upload($formData['file']); |
| 115 | - } catch (\Exception $e) { |
|
| 115 | + } catch (\Exception $e) { |
|
| 116 | 116 | return new SingleResourceResponse(['message' => $e->getMessage()], new ResponseContext(400)); |
| 117 | - } |
|
| 118 | - $themeConfig = json_decode(file_get_contents($themePath . DIRECTORY_SEPARATOR . 'theme.json'), true); |
|
| 117 | + } |
|
| 118 | + $themeConfig = json_decode(file_get_contents($themePath . DIRECTORY_SEPARATOR . 'theme.json'), true); |
|
| 119 | 119 | |
| 120 | - return new SingleResourceResponse($themeConfig, new ResponseContext(201)); |
|
| 120 | + return new SingleResourceResponse($themeConfig, new ResponseContext(201)); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | return new SingleResourceResponse($form, new ResponseContext(400)); |
| 124 | - } |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - /** |
|
| 127 | - * @Route("/api/{version}/themes/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_install_theme") |
|
| 128 | - */ |
|
| 129 | - public function installThemeAction(Request $request): SingleResourceResponseInterface { |
|
| 126 | + /** |
|
| 127 | + * @Route("/api/{version}/themes/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_install_theme") |
|
| 128 | + */ |
|
| 129 | + public function installThemeAction(Request $request): SingleResourceResponseInterface { |
|
| 130 | 130 | $form = $this->formFactory->createNamed('', ThemeInstallType::class, []); |
| 131 | 131 | $form->handleRequest($request); |
| 132 | 132 | if ($form->isSubmitted() && $form->isValid()) { |
| 133 | - $formData = $form->getData(); |
|
| 134 | - $themeService = $this->themeService; |
|
| 135 | - [$sourceDir, $themeDir] = $themeService->getDirectoriesForTheme($formData['name']); |
|
| 136 | - $themeService->installAndProcessGeneratedData($sourceDir, $themeDir, $formData['processGeneratedData']); |
|
| 133 | + $formData = $form->getData(); |
|
| 134 | + $themeService = $this->themeService; |
|
| 135 | + [$sourceDir, $themeDir] = $themeService->getDirectoriesForTheme($formData['name']); |
|
| 136 | + $themeService->installAndProcessGeneratedData($sourceDir, $themeDir, $formData['processGeneratedData']); |
|
| 137 | 137 | |
| 138 | - return new SingleResourceResponse(['status' => 'installed'], new ResponseContext(201)); |
|
| 138 | + return new SingleResourceResponse(['status' => 'installed'], new ResponseContext(201)); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | return new SingleResourceResponse($form, new ResponseContext(400)); |
| 142 | - } |
|
| 142 | + } |
|
| 143 | 143 | } |
@@ -23,71 +23,71 @@ discard block |
||
| 23 | 23 | use Symfony\Component\Cache\Adapter\ArrayAdapter; |
| 24 | 24 | |
| 25 | 25 | class WebTestCase extends BaseWebTestCase { |
| 26 | - protected ?AbstractDatabaseTool $databaseTool; |
|
| 27 | - private static ?KernelBrowser $client = null; |
|
| 26 | + protected ?AbstractDatabaseTool $databaseTool; |
|
| 27 | + private static ?KernelBrowser $client = null; |
|
| 28 | 28 | |
| 29 | - public function setUp(): void { |
|
| 29 | + public function setUp(): void { |
|
| 30 | 30 | if (self::$client == null) { |
| 31 | - self::$client = parent::createClient(); |
|
| 31 | + self::$client = parent::createClient(); |
|
| 32 | 32 | } |
| 33 | 33 | $this->databaseTool = static::getContainer()->get(DatabaseToolCollection::class)->get(); |
| 34 | - } |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Initializes database. |
|
| 38 | - */ |
|
| 39 | - protected function initDatabase() { |
|
| 36 | + /** |
|
| 37 | + * Initializes database. |
|
| 38 | + */ |
|
| 39 | + protected function initDatabase() { |
|
| 40 | 40 | $this->clearMetadataCache(); |
| 41 | - } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Clears metadata cache of the various cache drivers. |
|
| 45 | - */ |
|
| 46 | - private function clearMetadataCache() { |
|
| 43 | + /** |
|
| 44 | + * Clears metadata cache of the various cache drivers. |
|
| 45 | + */ |
|
| 46 | + private function clearMetadataCache() { |
|
| 47 | 47 | $entityManager = $this->getContainer()->get('doctrine.orm.entity_manager'); |
| 48 | 48 | |
| 49 | 49 | $cacheDriver = $entityManager->getConfiguration()->getMetadataCacheImpl(); |
| 50 | 50 | |
| 51 | 51 | if (!$cacheDriver instanceof ArrayAdapter) { |
| 52 | - $cacheDriver->deleteAll(); |
|
| 52 | + $cacheDriver->deleteAll(); |
|
| 53 | + } |
|
| 53 | 54 | } |
| 54 | - } |
|
| 55 | 55 | |
| 56 | - protected function tearDown(): void { |
|
| 56 | + protected function tearDown(): void { |
|
| 57 | 57 | unset($this->databaseTool); |
| 58 | 58 | $reflection = new \ReflectionObject($this); |
| 59 | 59 | foreach ($reflection->getProperties() as $prop) { |
| 60 | - if (!$prop->isStatic() && 0 !== strpos($prop->getDeclaringClass()->getName(), 'PHPUnit_')) { |
|
| 60 | + if (!$prop->isStatic() && 0 !== strpos($prop->getDeclaringClass()->getName(), 'PHPUnit_')) { |
|
| 61 | 61 | $prop->setAccessible(true); |
| 62 | 62 | if ($prop->name == 'databaseTool') { |
| 63 | - continue; |
|
| 63 | + continue; |
|
| 64 | 64 | } |
| 65 | 65 | $prop->setValue($this, null); |
| 66 | - } |
|
| 66 | + } |
|
| 67 | 67 | } |
| 68 | 68 | parent::tearDown(); |
| 69 | - } |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - protected function loadCustomFixtures(array $fixtures) { |
|
| 71 | + protected function loadCustomFixtures(array $fixtures) { |
|
| 72 | 72 | $env = $this->getContainer()->getParameter('test_env'); |
| 73 | 73 | |
| 74 | 74 | $registry = new FixtureRegistry(); |
| 75 | 75 | $registry->setEnvironment($env); |
| 76 | 76 | |
| 77 | 77 | return $this->databaseTool->loadFixtures($registry->getFixtures($fixtures))->getReferenceRepository(); |
| 78 | - } |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - public static function createClient(array $options = [], array $server = []) { |
|
| 80 | + public static function createClient(array $options = [], array $server = []) { |
|
| 81 | 81 | if (!array_key_exists('HTTP_Authorization', $server)) { |
| 82 | - $server['HTTP_Authorization'] = base64_encode('test_token:'); |
|
| 82 | + $server['HTTP_Authorization'] = base64_encode('test_token:'); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | if (null === $server['HTTP_Authorization']) { |
| 86 | - unset($server['HTTP_Authorization']); |
|
| 86 | + unset($server['HTTP_Authorization']); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | if(!array_key_exists("HTTP_HOST", $server)) { |
| 90 | - $server['HTTP_HOST'] = 'localhost'; |
|
| 90 | + $server['HTTP_HOST'] = 'localhost'; |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | $newClient = clone self::$client; |
@@ -95,5 +95,5 @@ discard block |
||
| 95 | 95 | $newClient->getKernel()->shutdown(); |
| 96 | 96 | $newClient->getKernel()->boot(); |
| 97 | 97 | return $newClient; |
| 98 | - } |
|
| 98 | + } |
|
| 99 | 99 | } |
@@ -102,7 +102,7 @@ |
||
| 102 | 102 | } |
| 103 | 103 | $this->load($name); |
| 104 | 104 | if (array_key_exists($name, $this->copiedValues)) { |
| 105 | - return $this->copiedValues[$name]; |
|
| 105 | + return $this->copiedValues[$name]; |
|
| 106 | 106 | } |
| 107 | 107 | return null; |
| 108 | 108 | } |
@@ -131,14 +131,14 @@ discard block |
||
| 131 | 131 | $finder->in($configsPath)->files()->name('*.{yaml,yml}'); |
| 132 | 132 | $files = []; |
| 133 | 133 | foreach ($finder as $file) { |
| 134 | - $files[] = $file->getRealPath(); |
|
| 134 | + $files[] = $file->getRealPath(); |
|
| 135 | 135 | } |
| 136 | 136 | return $files; |
| 137 | 137 | }); |
| 138 | 138 | |
| 139 | - foreach ($files as $file) { |
|
| 139 | + foreach ($files as $file) { |
|
| 140 | 140 | $this->addNewConfig($file); |
| 141 | - } |
|
| 141 | + } |
|
| 142 | 142 | } |
| 143 | 143 | } |
| 144 | 144 | |
@@ -190,11 +190,11 @@ discard block |
||
| 190 | 190 | { |
| 191 | 191 | $cacheKey = md5($filePath); |
| 192 | 192 | $configuration = $this->metadataCache->get($cacheKey, function () use ($filePath) { |
| 193 | - if (!is_readable($filePath)) { |
|
| 194 | - throw new \InvalidArgumentException('Configuration file is not readable for parser'); |
|
| 195 | - } |
|
| 196 | - $parser = new Parser(); |
|
| 197 | - return $parser->parse(file_get_contents($filePath)); |
|
| 193 | + if (!is_readable($filePath)) { |
|
| 194 | + throw new \InvalidArgumentException('Configuration file is not readable for parser'); |
|
| 195 | + } |
|
| 196 | + $parser = new Parser(); |
|
| 197 | + return $parser->parse(file_get_contents($filePath)); |
|
| 198 | 198 | }); |
| 199 | 199 | $this->addAvailableConfig($configuration); |
| 200 | 200 | $this->supportedCache = []; |
@@ -222,15 +222,15 @@ discard block |
||
| 222 | 222 | { |
| 223 | 223 | $configuration = $meta->getConfiguration(); |
| 224 | 224 | if(array_key_exists("name" ,$configuration)) { |
| 225 | - $name = $configuration['name']; |
|
| 226 | - if (!array_key_exists($name, $this->registeredMeta)) { |
|
| 225 | + $name = $configuration['name']; |
|
| 226 | + if (!array_key_exists($name, $this->registeredMeta)) { |
|
| 227 | 227 | $this->registeredMeta[$name] = $configuration; |
| 228 | 228 | if (null !== $meta) { |
| 229 | - $this[$name] = $meta; |
|
| 229 | + $this[$name] = $meta; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | return true; |
| 233 | - } |
|
| 233 | + } |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | return false; |
@@ -41,29 +41,29 @@ discard block |
||
| 41 | 41 | use FOS\RestBundle\Controller\Annotations\Route; |
| 42 | 42 | |
| 43 | 43 | class OrganizationRuleController extends AbstractController { |
| 44 | - private FormFactoryInterface $formFactory; |
|
| 45 | - private EventDispatcherInterface $eventDispatcher; |
|
| 46 | - private CachedTenantContextInterface $cachedTenantContext; |
|
| 47 | - private EntityManagerInterface $entityManager; |
|
| 48 | - private RuleRepositoryInterface $ruleRepository; |
|
| 49 | - private RulesMatcherInterface $rulesMatcher; |
|
| 50 | - private FactoryInterface $ruleFactory; |
|
| 51 | - private DataTransformerInterface $dataTransformer; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * @param FormFactoryInterface $formFactory |
|
| 55 | - * @param EventDispatcherInterface $eventDispatcher |
|
| 56 | - * @param CachedTenantContextInterface $cachedTenantContext |
|
| 57 | - * @param EntityManagerInterface $entityManager |
|
| 58 | - * @param RuleRepositoryInterface $ruleRepository |
|
| 59 | - * @param RulesMatcherInterface $rulesMatcher |
|
| 60 | - * @param FactoryInterface $ruleFactory |
|
| 61 | - * @param DataTransformerInterface $dataTransformer |
|
| 62 | - */ |
|
| 63 | - public function __construct(FormFactoryInterface $formFactory, EventDispatcherInterface $eventDispatcher, |
|
| 64 | - CachedTenantContextInterface $cachedTenantContext, EntityManagerInterface $entityManager, |
|
| 65 | - RuleRepositoryInterface $ruleRepository, RulesMatcherInterface $rulesMatcher, |
|
| 66 | - FactoryInterface $ruleFactory, DataTransformerInterface $dataTransformer) { |
|
| 44 | + private FormFactoryInterface $formFactory; |
|
| 45 | + private EventDispatcherInterface $eventDispatcher; |
|
| 46 | + private CachedTenantContextInterface $cachedTenantContext; |
|
| 47 | + private EntityManagerInterface $entityManager; |
|
| 48 | + private RuleRepositoryInterface $ruleRepository; |
|
| 49 | + private RulesMatcherInterface $rulesMatcher; |
|
| 50 | + private FactoryInterface $ruleFactory; |
|
| 51 | + private DataTransformerInterface $dataTransformer; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * @param FormFactoryInterface $formFactory |
|
| 55 | + * @param EventDispatcherInterface $eventDispatcher |
|
| 56 | + * @param CachedTenantContextInterface $cachedTenantContext |
|
| 57 | + * @param EntityManagerInterface $entityManager |
|
| 58 | + * @param RuleRepositoryInterface $ruleRepository |
|
| 59 | + * @param RulesMatcherInterface $rulesMatcher |
|
| 60 | + * @param FactoryInterface $ruleFactory |
|
| 61 | + * @param DataTransformerInterface $dataTransformer |
|
| 62 | + */ |
|
| 63 | + public function __construct(FormFactoryInterface $formFactory, EventDispatcherInterface $eventDispatcher, |
|
| 64 | + CachedTenantContextInterface $cachedTenantContext, EntityManagerInterface $entityManager, |
|
| 65 | + RuleRepositoryInterface $ruleRepository, RulesMatcherInterface $rulesMatcher, |
|
| 66 | + FactoryInterface $ruleFactory, DataTransformerInterface $dataTransformer) { |
|
| 67 | 67 | $this->formFactory = $formFactory; |
| 68 | 68 | $this->eventDispatcher = $eventDispatcher; |
| 69 | 69 | $this->cachedTenantContext = $cachedTenantContext; |
@@ -72,13 +72,13 @@ discard block |
||
| 72 | 72 | $this->rulesMatcher = $rulesMatcher; |
| 73 | 73 | $this->ruleFactory = $ruleFactory; |
| 74 | 74 | $this->dataTransformer = $dataTransformer; |
| 75 | - } |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * @Route("/api/{version}/organization/rules/evaluate", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_organization_rules_evaluate") |
|
| 80 | - */ |
|
| 81 | - public function rulesEvaluationAction(Request $request): SingleResourceResponseInterface { |
|
| 78 | + /** |
|
| 79 | + * @Route("/api/{version}/organization/rules/evaluate", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_organization_rules_evaluate") |
|
| 80 | + */ |
|
| 81 | + public function rulesEvaluationAction(Request $request): SingleResourceResponseInterface { |
|
| 82 | 82 | $content = $request->getContent(); |
| 83 | 83 | $dispatcher = $this->eventDispatcher; |
| 84 | 84 | $package = $this->dataTransformer->transform($content); |
@@ -89,12 +89,12 @@ discard block |
||
| 89 | 89 | $context = new ResponseContext(); |
| 90 | 90 | $context->setSerializationGroups(['Default', 'api']); |
| 91 | 91 | return new SingleResourceResponse($rules, $context); |
| 92 | - } |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - /** |
|
| 95 | - * @Route("/api/{version}/organization/rules/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_organization_rules") |
|
| 96 | - */ |
|
| 97 | - public function rulesAction(Request $request): ResourcesListResponseInterface { |
|
| 94 | + /** |
|
| 95 | + * @Route("/api/{version}/organization/rules/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_organization_rules") |
|
| 96 | + */ |
|
| 97 | + public function rulesAction(Request $request): ResourcesListResponseInterface { |
|
| 98 | 98 | $tenantContext = $this->cachedTenantContext; |
| 99 | 99 | |
| 100 | 100 | $this->getEventDispatcher()->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); |
@@ -111,12 +111,12 @@ discard block |
||
| 111 | 111 | ); |
| 112 | 112 | |
| 113 | 113 | return new ResourcesListResponse($rules); |
| 114 | - } |
|
| 114 | + } |
|
| 115 | 115 | |
| 116 | - /** |
|
| 117 | - * @Route("/api/{version}/organization/rules/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_create_organization_rule") |
|
| 118 | - */ |
|
| 119 | - public function createAction(Request $request): SingleResourceResponseInterface { |
|
| 116 | + /** |
|
| 117 | + * @Route("/api/{version}/organization/rules/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_create_organization_rule") |
|
| 118 | + */ |
|
| 119 | + public function createAction(Request $request): SingleResourceResponseInterface { |
|
| 120 | 120 | $ruleRepository = $this->getRuleRepository(); |
| 121 | 121 | |
| 122 | 122 | $rule = $this->ruleFactory->create(); |
@@ -124,54 +124,54 @@ discard block |
||
| 124 | 124 | $form->handleRequest($request); |
| 125 | 125 | |
| 126 | 126 | if ($form->isSubmitted() && $form->isValid()) { |
| 127 | - $ruleRepository->add($rule); |
|
| 128 | - $rule->setTenantCode(null); |
|
| 129 | - $ruleRepository->flush(); |
|
| 127 | + $ruleRepository->add($rule); |
|
| 128 | + $rule->setTenantCode(null); |
|
| 129 | + $ruleRepository->flush(); |
|
| 130 | 130 | |
| 131 | - return new SingleResourceResponse($rule, new ResponseContext(201)); |
|
| 131 | + return new SingleResourceResponse($rule, new ResponseContext(201)); |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | return new SingleResourceResponse($form, new ResponseContext(400)); |
| 135 | - } |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - /** |
|
| 138 | - * @Route("/api/{version}/organization/rules/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_show_organization_rule", requirements={"id"="\d+"}) |
|
| 139 | - */ |
|
| 140 | - public function getAction(int $id): SingleResourceResponseInterface { |
|
| 137 | + /** |
|
| 138 | + * @Route("/api/{version}/organization/rules/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_show_organization_rule", requirements={"id"="\d+"}) |
|
| 139 | + */ |
|
| 140 | + public function getAction(int $id): SingleResourceResponseInterface { |
|
| 141 | 141 | return new SingleResourceResponse($this->findOr404($id)); |
| 142 | - } |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - /** |
|
| 145 | - * @Route("/api/{version}/organization/rules/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_organization_rule", requirements={"id"="\d+"}) |
|
| 146 | - */ |
|
| 147 | - public function updateRuleAction(Request $request, int $id) { |
|
| 144 | + /** |
|
| 145 | + * @Route("/api/{version}/organization/rules/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_organization_rule", requirements={"id"="\d+"}) |
|
| 146 | + */ |
|
| 147 | + public function updateRuleAction(Request $request, int $id) { |
|
| 148 | 148 | $objectManager = $this->entityManager; |
| 149 | 149 | $rule = $this->findOr404($id); |
| 150 | 150 | $form = $this->formFactory->createNamed('', RuleType::class, $rule, ['method' => $request->getMethod()]); |
| 151 | 151 | |
| 152 | 152 | $form->handleRequest($request); |
| 153 | 153 | if ($form->isSubmitted() && $form->isValid()) { |
| 154 | - $objectManager->flush(); |
|
| 155 | - $objectManager->refresh($rule); |
|
| 154 | + $objectManager->flush(); |
|
| 155 | + $objectManager->refresh($rule); |
|
| 156 | 156 | |
| 157 | - return new SingleResourceResponse($rule); |
|
| 157 | + return new SingleResourceResponse($rule); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | return new SingleResourceResponse($form, new ResponseContext(500)); |
| 161 | - } |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | - /** |
|
| 164 | - * @Route("/api/{version}/organization/rules/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_core_delete_organization_rule", requirements={"id"="\d+"}) |
|
| 165 | - */ |
|
| 166 | - public function deleteAction(int $id) { |
|
| 163 | + /** |
|
| 164 | + * @Route("/api/{version}/organization/rules/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_core_delete_organization_rule", requirements={"id"="\d+"}) |
|
| 165 | + */ |
|
| 166 | + public function deleteAction(int $id) { |
|
| 167 | 167 | $rule = $this->findOr404($id); |
| 168 | 168 | $ruleRepository = $this->ruleRepository; |
| 169 | 169 | $ruleRepository->remove($rule); |
| 170 | 170 | |
| 171 | 171 | return new SingleResourceResponse(null, new ResponseContext(204)); |
| 172 | - } |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | - private function findOr404(int $id) { |
|
| 174 | + private function findOr404(int $id) { |
|
| 175 | 175 | $tenantContext = $this->cachedTenantContext; |
| 176 | 176 | $this->getEventDispatcher()->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); |
| 177 | 177 | |
@@ -180,17 +180,17 @@ discard block |
||
| 180 | 180 | 'organization' => $tenantContext->getTenant()->getOrganization(), |
| 181 | 181 | 'tenantCode' => null, |
| 182 | 182 | ]))) { |
| 183 | - throw new NotFoundHttpException('Organization rule was not found.'); |
|
| 183 | + throw new NotFoundHttpException('Organization rule was not found.'); |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | return $rule; |
| 187 | - } |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | - private function getRuleRepository() { |
|
| 189 | + private function getRuleRepository() { |
|
| 190 | 190 | return $this->ruleRepository; |
| 191 | - } |
|
| 191 | + } |
|
| 192 | 192 | |
| 193 | - private function getEventDispatcher() { |
|
| 193 | + private function getEventDispatcher() { |
|
| 194 | 194 | return $this->eventDispatcher; |
| 195 | - } |
|
| 195 | + } |
|
| 196 | 196 | } |
@@ -17,7 +17,7 @@ |
||
| 17 | 17 | { |
| 18 | 18 | // this up() migration is auto-generated, please modify it to your needs |
| 19 | 19 | $this->abortIf('postgresql' !== $this->connection->getDatabasePlatform()->getName(), 'Migration can only be executed safely on \'postgresql\'.'); |
| 20 | - $this->addSql('ALTER TABLE swp_article ADD COLUMN IF NOT EXISTS feature_media INT DEFAULT NULL'); |
|
| 20 | + $this->addSql('ALTER TABLE swp_article ADD COLUMN IF NOT EXISTS feature_media INT DEFAULT NULL'); |
|
| 21 | 21 | $this->addSql('ALTER TABLE swp_article ADD CONSTRAINT FK_FB21E858A372AB05 FOREIGN KEY (feature_media) REFERENCES swp_article_media (id) ON DELETE SET NULL NOT DEFERRABLE INITIALLY IMMEDIATE'); |
| 22 | 22 | $this->addSql('CREATE INDEX IDX_FB21E858A372AB05 ON swp_article (feature_media)'); |
| 23 | 23 | } |
@@ -27,73 +27,73 @@ |
||
| 27 | 27 | use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
| 28 | 28 | |
| 29 | 29 | class WebhookController extends AbstractAPIController { |
| 30 | - private WebhookRepositoryInterface $webhookRepository; |
|
| 31 | - private FormFactoryInterface $formFactory; |
|
| 32 | - private FactoryInterface $webhookFactory; |
|
| 33 | - private EntityManagerInterface $entityManager; |
|
| 34 | - private EventDispatcherInterface $eventDispatcher; |
|
| 30 | + private WebhookRepositoryInterface $webhookRepository; |
|
| 31 | + private FormFactoryInterface $formFactory; |
|
| 32 | + private FactoryInterface $webhookFactory; |
|
| 33 | + private EntityManagerInterface $entityManager; |
|
| 34 | + private EventDispatcherInterface $eventDispatcher; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @param WebhookRepositoryInterface $webhookRepository |
|
| 38 | - * @param FormFactoryInterface $formFactory |
|
| 39 | - * @param FactoryInterface $webhookFactory |
|
| 40 | - * @param EntityManagerInterface $entityManager |
|
| 41 | - * @param EventDispatcherInterface $eventDispatcher |
|
| 42 | - */ |
|
| 43 | - public function __construct(WebhookRepositoryInterface $webhookRepository, FormFactoryInterface $formFactory, |
|
| 44 | - FactoryInterface $webhookFactory, EntityManagerInterface $entityManager, |
|
| 45 | - EventDispatcherInterface $eventDispatcher) { |
|
| 36 | + /** |
|
| 37 | + * @param WebhookRepositoryInterface $webhookRepository |
|
| 38 | + * @param FormFactoryInterface $formFactory |
|
| 39 | + * @param FactoryInterface $webhookFactory |
|
| 40 | + * @param EntityManagerInterface $entityManager |
|
| 41 | + * @param EventDispatcherInterface $eventDispatcher |
|
| 42 | + */ |
|
| 43 | + public function __construct(WebhookRepositoryInterface $webhookRepository, FormFactoryInterface $formFactory, |
|
| 44 | + FactoryInterface $webhookFactory, EntityManagerInterface $entityManager, |
|
| 45 | + EventDispatcherInterface $eventDispatcher) { |
|
| 46 | 46 | $this->webhookRepository = $webhookRepository; |
| 47 | 47 | $this->formFactory = $formFactory; |
| 48 | 48 | $this->webhookFactory = $webhookFactory; |
| 49 | 49 | $this->entityManager = $entityManager; |
| 50 | 50 | $this->eventDispatcher = $eventDispatcher; |
| 51 | - } |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @Route("/api/{version}/webhooks/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_webhook") |
|
| 56 | - */ |
|
| 57 | - public function listAction(Request $request): ResourcesListResponseInterface { |
|
| 54 | + /** |
|
| 55 | + * @Route("/api/{version}/webhooks/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_webhook") |
|
| 56 | + */ |
|
| 57 | + public function listAction(Request $request): ResourcesListResponseInterface { |
|
| 58 | 58 | return $this->listWebhooks($this->eventDispatcher,$this->webhookRepository, $request); |
| 59 | - } |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * @Route("/api/{version}/webhooks/{id}", requirements={"id"="\d+"}, options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_get_webhook") |
|
| 63 | - */ |
|
| 64 | - public function getAction(int $id): SingleResourceResponseInterface { |
|
| 61 | + /** |
|
| 62 | + * @Route("/api/{version}/webhooks/{id}", requirements={"id"="\d+"}, options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_get_webhook") |
|
| 63 | + */ |
|
| 64 | + public function getAction(int $id): SingleResourceResponseInterface { |
|
| 65 | 65 | return $this->getSingleWebhook($this->findOr404($id)); |
| 66 | - } |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * @Route("/api/{version}/webhooks/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_create_webhook") |
|
| 70 | - */ |
|
| 71 | - public function createAction(Request $request): SingleResourceResponseInterface { |
|
| 68 | + /** |
|
| 69 | + * @Route("/api/{version}/webhooks/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_create_webhook") |
|
| 70 | + */ |
|
| 71 | + public function createAction(Request $request): SingleResourceResponseInterface { |
|
| 72 | 72 | $ruleRepository = $this->webhookRepository; |
| 73 | 73 | $ruleFactory = $this->webhookFactory; |
| 74 | 74 | $formFactory = $this->formFactory; |
| 75 | 75 | |
| 76 | 76 | return $this->createWebhook($ruleRepository, $ruleFactory, $request, $formFactory); |
| 77 | - } |
|
| 77 | + } |
|
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * @Route("/api/{version}/webhooks/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_core_delete_webhook", requirements={"id"="\d+"}) |
|
| 81 | - */ |
|
| 82 | - public function deleteAction(int $id): SingleResourceResponseInterface { |
|
| 79 | + /** |
|
| 80 | + * @Route("/api/{version}/webhooks/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"DELETE"}, name="swp_api_core_delete_webhook", requirements={"id"="\d+"}) |
|
| 81 | + */ |
|
| 82 | + public function deleteAction(int $id): SingleResourceResponseInterface { |
|
| 83 | 83 | $webhookRepository = $this->webhookRepository; |
| 84 | 84 | |
| 85 | 85 | return $this->deleteWebhook($webhookRepository, $this->findOr404($id)); |
| 86 | - } |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * @Route("/api/{version}/webhooks/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_webhook", requirements={"id"="\d+"}) |
|
| 90 | - */ |
|
| 91 | - public function updateAction(Request $request, int $id): SingleResourceResponseInterface { |
|
| 88 | + /** |
|
| 89 | + * @Route("/api/{version}/webhooks/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_webhook", requirements={"id"="\d+"}) |
|
| 90 | + */ |
|
| 91 | + public function updateAction(Request $request, int $id): SingleResourceResponseInterface { |
|
| 92 | 92 | $objectManager = $this->entityManager; |
| 93 | 93 | $formFactory = $this->formFactory; |
| 94 | 94 | |
| 95 | 95 | return $this->updateWebhook($objectManager, $request, $this->findOr404($id), $formFactory); |
| 96 | - } |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | 98 | private function findOr404(int $id) |
| 99 | 99 | { |
@@ -35,39 +35,39 @@ discard block |
||
| 35 | 35 | |
| 36 | 36 | class PublishDestinationController extends Controller { |
| 37 | 37 | |
| 38 | - private FormFactoryInterface $formFactory; |
|
| 39 | - private EventDispatcherInterface $eventDispatcher; |
|
| 40 | - private CachedTenantContextInterface $cachedTenantContext; |
|
| 41 | - private RepositoryInterface $publishDestinationRepository; |
|
| 42 | - private EntityManagerInterface $entityManager; |
|
| 43 | - private FactoryInterface $publishDestinationFactory; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * @param FormFactoryInterface $formFactory |
|
| 47 | - * @param EventDispatcherInterface $eventDispatcher |
|
| 48 | - * @param CachedTenantContextInterface $cachedTenantContext |
|
| 49 | - * @param RepositoryInterface $publishDestinationRepository |
|
| 50 | - * @param EntityManagerInterface $entityManager |
|
| 51 | - * @param FactoryInterface $publishDestinationFactory |
|
| 52 | - */ |
|
| 53 | - public function __construct(FormFactoryInterface $formFactory, |
|
| 54 | - EventDispatcherInterface $eventDispatcher, |
|
| 55 | - CachedTenantContextInterface $cachedTenantContext, |
|
| 56 | - RepositoryInterface $publishDestinationRepository, |
|
| 57 | - EntityManagerInterface $entityManager, |
|
| 58 | - FactoryInterface $publishDestinationFactory) { |
|
| 38 | + private FormFactoryInterface $formFactory; |
|
| 39 | + private EventDispatcherInterface $eventDispatcher; |
|
| 40 | + private CachedTenantContextInterface $cachedTenantContext; |
|
| 41 | + private RepositoryInterface $publishDestinationRepository; |
|
| 42 | + private EntityManagerInterface $entityManager; |
|
| 43 | + private FactoryInterface $publishDestinationFactory; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * @param FormFactoryInterface $formFactory |
|
| 47 | + * @param EventDispatcherInterface $eventDispatcher |
|
| 48 | + * @param CachedTenantContextInterface $cachedTenantContext |
|
| 49 | + * @param RepositoryInterface $publishDestinationRepository |
|
| 50 | + * @param EntityManagerInterface $entityManager |
|
| 51 | + * @param FactoryInterface $publishDestinationFactory |
|
| 52 | + */ |
|
| 53 | + public function __construct(FormFactoryInterface $formFactory, |
|
| 54 | + EventDispatcherInterface $eventDispatcher, |
|
| 55 | + CachedTenantContextInterface $cachedTenantContext, |
|
| 56 | + RepositoryInterface $publishDestinationRepository, |
|
| 57 | + EntityManagerInterface $entityManager, |
|
| 58 | + FactoryInterface $publishDestinationFactory) { |
|
| 59 | 59 | $this->formFactory = $formFactory; |
| 60 | 60 | $this->eventDispatcher = $eventDispatcher; |
| 61 | 61 | $this->cachedTenantContext = $cachedTenantContext; |
| 62 | 62 | $this->publishDestinationRepository = $publishDestinationRepository; |
| 63 | 63 | $this->entityManager = $entityManager; |
| 64 | 64 | $this->publishDestinationFactory = $publishDestinationFactory; |
| 65 | - } |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * @Route("/api/{version}/organization/destinations/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_publishing_destination_create") |
|
| 69 | - */ |
|
| 70 | - public function createAction(Request $request): SingleResourceResponse { |
|
| 67 | + /** |
|
| 68 | + * @Route("/api/{version}/organization/destinations/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_publishing_destination_create") |
|
| 69 | + */ |
|
| 70 | + public function createAction(Request $request): SingleResourceResponse { |
|
| 71 | 71 | $tenantContext = $this->cachedTenantContext; |
| 72 | 72 | |
| 73 | 73 | $this->eventDispatcher->dispatch(new GenericEvent(), MultiTenancyEvents::TENANTABLE_DISABLE); |
@@ -78,26 +78,26 @@ discard block |
||
| 78 | 78 | $form->handleRequest($request); |
| 79 | 79 | |
| 80 | 80 | if ($form->isSubmitted() && $form->isValid()) { |
| 81 | - $repository = $this->publishDestinationRepository; |
|
| 82 | - /** @var PublishDestinationInterface $publishDestination */ |
|
| 83 | - $publishDestination = $repository->findOneByTenant($destination->getTenant()); |
|
| 84 | - if (null !== $publishDestination) { |
|
| 81 | + $repository = $this->publishDestinationRepository; |
|
| 82 | + /** @var PublishDestinationInterface $publishDestination */ |
|
| 83 | + $publishDestination = $repository->findOneByTenant($destination->getTenant()); |
|
| 84 | + if (null !== $publishDestination) { |
|
| 85 | 85 | $repository->remove($publishDestination); |
| 86 | - } |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - $currentOrganization->addPublishDestination($destination); |
|
| 89 | - $this->entityManager->flush(); |
|
| 88 | + $currentOrganization->addPublishDestination($destination); |
|
| 89 | + $this->entityManager->flush(); |
|
| 90 | 90 | |
| 91 | - return new SingleResourceResponse($destination, new ResponseContext(200)); |
|
| 91 | + return new SingleResourceResponse($destination, new ResponseContext(200)); |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | return new SingleResourceResponse($form, new ResponseContext(400)); |
| 95 | - } |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * @Route("/api/{version}/organization/destinations/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_publishing_destination_update", requirements={"id"="\d+"}) |
|
| 99 | - */ |
|
| 100 | - public function updateAction(Request $request, $id): SingleResourceResponse { |
|
| 97 | + /** |
|
| 98 | + * @Route("/api/{version}/organization/destinations/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_publishing_destination_update", requirements={"id"="\d+"}) |
|
| 99 | + */ |
|
| 100 | + public function updateAction(Request $request, $id): SingleResourceResponse { |
|
| 101 | 101 | $objectManager = $this->entityManager; |
| 102 | 102 | $publishDestination = $this->findOr404($id); |
| 103 | 103 | |
@@ -110,14 +110,14 @@ discard block |
||
| 110 | 110 | |
| 111 | 111 | $form->handleRequest($request); |
| 112 | 112 | if ($form->isSubmitted() && $form->isValid()) { |
| 113 | - $objectManager->flush(); |
|
| 114 | - $objectManager->refresh($publishDestination); |
|
| 113 | + $objectManager->flush(); |
|
| 114 | + $objectManager->refresh($publishDestination); |
|
| 115 | 115 | |
| 116 | - return new SingleResourceResponse($publishDestination); |
|
| 116 | + return new SingleResourceResponse($publishDestination); |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | return new SingleResourceResponse($form, new ResponseContext(400)); |
| 120 | - } |
|
| 120 | + } |
|
| 121 | 121 | |
| 122 | 122 | private function findOr404(int $id) |
| 123 | 123 | { |
@@ -32,83 +32,83 @@ discard block |
||
| 32 | 32 | |
| 33 | 33 | class RuleController extends FOSRestController { |
| 34 | 34 | |
| 35 | - private FormFactoryInterface $formFactory; |
|
| 36 | - private EntityManagerInterface $entityManager; |
|
| 37 | - private RuleRepositoryInterface $ruleRepository; |
|
| 38 | - private FactoryInterface $ruleFactory; |
|
| 39 | - private EventDispatcherInterface $eventDispatcher; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @param FormFactoryInterface $formFactory |
|
| 43 | - * @param EntityManagerInterface $entityManager |
|
| 44 | - * @param RuleRepositoryInterface $ruleRepository |
|
| 45 | - * @param FactoryInterface $ruleFactory |
|
| 46 | - * @param EventDispatcherInterface $eventDispatcher |
|
| 47 | - */ |
|
| 48 | - public function __construct(FormFactoryInterface $formFactory, EntityManagerInterface $entityManager, |
|
| 49 | - RuleRepositoryInterface $ruleRepository, FactoryInterface $ruleFactory, |
|
| 50 | - EventDispatcherInterface $eventDispatcher) { |
|
| 35 | + private FormFactoryInterface $formFactory; |
|
| 36 | + private EntityManagerInterface $entityManager; |
|
| 37 | + private RuleRepositoryInterface $ruleRepository; |
|
| 38 | + private FactoryInterface $ruleFactory; |
|
| 39 | + private EventDispatcherInterface $eventDispatcher; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @param FormFactoryInterface $formFactory |
|
| 43 | + * @param EntityManagerInterface $entityManager |
|
| 44 | + * @param RuleRepositoryInterface $ruleRepository |
|
| 45 | + * @param FactoryInterface $ruleFactory |
|
| 46 | + * @param EventDispatcherInterface $eventDispatcher |
|
| 47 | + */ |
|
| 48 | + public function __construct(FormFactoryInterface $formFactory, EntityManagerInterface $entityManager, |
|
| 49 | + RuleRepositoryInterface $ruleRepository, FactoryInterface $ruleFactory, |
|
| 50 | + EventDispatcherInterface $eventDispatcher) { |
|
| 51 | 51 | $this->formFactory = $formFactory; |
| 52 | 52 | $this->entityManager = $entityManager; |
| 53 | 53 | $this->ruleRepository = $ruleRepository; |
| 54 | 54 | $this->ruleFactory = $ruleFactory; |
| 55 | 55 | $this->eventDispatcher = $eventDispatcher; |
| 56 | - } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @Route("/api/{version}/rules/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_rule") |
|
| 61 | - */ |
|
| 62 | - public function listAction(Request $request) { |
|
| 59 | + /** |
|
| 60 | + * @Route("/api/{version}/rules/", options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_list_rule") |
|
| 61 | + */ |
|
| 62 | + public function listAction(Request $request) { |
|
| 63 | 63 | $rules = $this->ruleRepository |
| 64 | 64 | ->getPaginatedByCriteria($this->eventDispatcher, new Criteria(), $request->query->all('sorting'), new PaginationData($request)); |
| 65 | 65 | |
| 66 | 66 | if (0 === $rules->count()) { |
| 67 | - throw new NotFoundHttpException('No rules were found.'); |
|
| 67 | + throw new NotFoundHttpException('No rules were found.'); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | return new ResourcesListResponse($rules); |
| 71 | - } |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - /** |
|
| 74 | - * @Route("/api/{version}/rules/{id}", requirements={"id"="\d+"}, options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_get_rule") |
|
| 75 | - */ |
|
| 76 | - public function getAction(int $id) { |
|
| 73 | + /** |
|
| 74 | + * @Route("/api/{version}/rules/{id}", requirements={"id"="\d+"}, options={"expose"=true}, defaults={"version"="v2"}, methods={"GET"}, name="swp_api_core_get_rule") |
|
| 75 | + */ |
|
| 76 | + public function getAction(int $id) { |
|
| 77 | 77 | return new SingleResourceResponse($this->findOr404($id)); |
| 78 | - } |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * @Route("/api/{version}/rules/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_create_rule") |
|
| 82 | - */ |
|
| 83 | - public function createAction(Request $request) { |
|
| 80 | + /** |
|
| 81 | + * @Route("/api/{version}/rules/", options={"expose"=true}, defaults={"version"="v2"}, methods={"POST"}, name="swp_api_core_create_rule") |
|
| 82 | + */ |
|
| 83 | + public function createAction(Request $request) { |
|
| 84 | 84 | $ruleRepository = $this->ruleRepository; |
| 85 | 85 | $rule = $this->ruleFactory->create(); |
| 86 | 86 | $form = $this->formFactory->createNamed('', RuleType::class, $rule); |
| 87 | 87 | $form->handleRequest($request); |
| 88 | 88 | |
| 89 | 89 | if ($form->isSubmitted() && $form->isValid()) { |
| 90 | - $ruleRepository->add($rule); |
|
| 90 | + $ruleRepository->add($rule); |
|
| 91 | 91 | |
| 92 | - return new SingleResourceResponse($rule, new ResponseContext(201)); |
|
| 92 | + return new SingleResourceResponse($rule, new ResponseContext(201)); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | return new SingleResourceResponse($form, new ResponseContext(400)); |
| 96 | - } |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * @Route("/api/{version}/rules/{id}", options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_delete_rule", methods={"DELETE"}, requirements={"id"="\d+"}) |
|
| 100 | - */ |
|
| 101 | - public function deleteAction(int $id) { |
|
| 98 | + /** |
|
| 99 | + * @Route("/api/{version}/rules/{id}", options={"expose"=true}, defaults={"version"="v2"}, name="swp_api_core_delete_rule", methods={"DELETE"}, requirements={"id"="\d+"}) |
|
| 100 | + */ |
|
| 101 | + public function deleteAction(int $id) { |
|
| 102 | 102 | $ruleRepository = $this->ruleRepository; |
| 103 | 103 | $ruleRepository->remove($this->findOr404($id)); |
| 104 | 104 | |
| 105 | 105 | return new SingleResourceResponse(null, new ResponseContext(204)); |
| 106 | - } |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - /** |
|
| 109 | - * @Route("/api/{version}/rules/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_rule", requirements={"id"="\d+"}) |
|
| 110 | - */ |
|
| 111 | - public function updateAction(Request $request, int $id) { |
|
| 108 | + /** |
|
| 109 | + * @Route("/api/{version}/rules/{id}", options={"expose"=true}, defaults={"version"="v2"}, methods={"PATCH"}, name="swp_api_core_update_rule", requirements={"id"="\d+"}) |
|
| 110 | + */ |
|
| 111 | + public function updateAction(Request $request, int $id) { |
|
| 112 | 112 | $rule = $this->findOr404($id); |
| 113 | 113 | $objectManager = $this->entityManager; |
| 114 | 114 | |
@@ -118,21 +118,21 @@ discard block |
||
| 118 | 118 | |
| 119 | 119 | $form->handleRequest($request); |
| 120 | 120 | if ($form->isSubmitted() && $form->isValid()) { |
| 121 | - $objectManager->flush(); |
|
| 122 | - $objectManager->refresh($rule); |
|
| 121 | + $objectManager->flush(); |
|
| 122 | + $objectManager->refresh($rule); |
|
| 123 | 123 | |
| 124 | - return new SingleResourceResponse($rule); |
|
| 124 | + return new SingleResourceResponse($rule); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | return new SingleResourceResponse($form, new ResponseContext(400)); |
| 128 | - } |
|
| 129 | - |
|
| 130 | - private function findOr404(int $id) |
|
| 131 | - { |
|
| 132 | - $rule = $this->ruleRepository->findOneBy(['id' => $id]); |
|
| 133 | - if (null === ($rule)) { |
|
| 134 | - throw new NotFoundHttpException('Rule was not found.'); |
|
| 135 | - } |
|
| 136 | - return $rule; |
|
| 137 | - } |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + private function findOr404(int $id) |
|
| 131 | + { |
|
| 132 | + $rule = $this->ruleRepository->findOneBy(['id' => $id]); |
|
| 133 | + if (null === ($rule)) { |
|
| 134 | + throw new NotFoundHttpException('Rule was not found.'); |
|
| 135 | + } |
|
| 136 | + return $rule; |
|
| 137 | + } |
|
| 138 | 138 | } |