From 31bac961e11477626a2c6f30966457ad281a53e4 Mon Sep 17 00:00:00 2001 From: JiaJia Ji Date: Mon, 26 Aug 2024 16:28:17 +0200 Subject: [PATCH 1/2] explicit sources --- composer.json | 4 +-- src/Controller/AdminController.php | 46 +++++++++++++++--------------- src/Controller/ClassController.php | 6 ++-- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/composer.json b/composer.json index b58f83d..0fe0d24 100644 --- a/composer.json +++ b/composer.json @@ -3,12 +3,12 @@ "license": "GPL-3.0+", "type": "pimcore-bundle", "require": { - "pimcore/pimcore": "^11.0", + "pimcore/pimcore": "^11.2", "symfony/config": "^6.2", "symfony/dependency-injection": "^6.2", "symfony/event-dispatcher": "^6.2", "symfony/event-dispatcher-contracts": "^3.0", - "symfony/http-foundation": "^6.2", + "symfony/http-foundation": "^6.3", "symfony/http-kernel": "^6.2", "symfony/routing": "^6.2", "symfony/templating": "^6.2" diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index 57a0fe6..885a1c8 100644 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -72,7 +72,7 @@ public static function getSubscribedServices(): array */ public function initializeAction(Request $request, EventDispatcherInterface $eventDispatcher) { - $objectId = $request->get('id'); + $objectId = $request->query->getInt('id'); $object = AbstractObject::getById($objectId); if (!$object) { @@ -104,7 +104,7 @@ public function getOutputConfigsAction(Request $request) Service::initChannelsForRootobject(); $channels = Service::getChannels(); - $objectId = $request->get('object_id'); + $objectId = $request->request->getInt('object_id'); $object = AbstractObject::getById($objectId); $classList = $this->getFilteredClassDefinitionList($request); @@ -166,7 +166,7 @@ private function getOutputDefinitionForObjectAndChannel($object, $classId, $chan public function resetOutputConfigAction(Request $request) { try { - $config = OutputDefinition::getById($request->get('config_id')); + $config = OutputDefinition::getById($request->query->getInt('config_id')); $config->delete(); return $this->jsonResponse(['success' => true]); @@ -187,7 +187,7 @@ public function resetOutputConfigAction(Request $request) public function getOutputConfigAction(Request $request) { try { - $config = OutputDefinition::getById($request->get('config_id')); + $config = OutputDefinition::getById($request->query->getInt('config_id')); $objectClass = ClassDefinition::getById($config->getClassId()); $configuration = json_decode($config->getConfiguration()); @@ -213,19 +213,19 @@ public function getOutputConfigAction(Request $request) public function getOrCreateOutputConfigAction(Request $request) { try { - $config = OutputDefinition::getById($request->get('config_id')); + $config = OutputDefinition::getById($request->query->getInt('config_id')); $class = null; if (!$config) { - if (is_numeric($request->get('class_id'))) { - $class = ClassDefinition::getById($request->get('class_id')); + if (is_numeric($request->query->get('class_id'))) { + $class = ClassDefinition::getById($request->query->getInt('class_id')); } else { - $class = ClassDefinition::getByName($request->get('class_id')); + $class = ClassDefinition::getByName($request->query->getString('class_id')); } if (!$class) { - throw new \Exception('Class ' . $request->get('class_id') . ' not found.'); + throw new \Exception('Class ' . $request->query->get('class_id') . ' not found.'); } - $config = OutputDefinition::getByObjectIdClassIdChannel($request->get('objectId'), $class->getId(), $request->get('channel')); + $config = OutputDefinition::getByObjectIdClassIdChannel($request->query->get('objectId'), $class->getId(), $request->query->get('channel')); } if ($config) { @@ -237,9 +237,9 @@ public function getOrCreateOutputConfigAction(Request $request) return $this->jsonResponse(['success' => true, 'outputConfig' => $config]); } else { $config = new OutputDefinition(); - $config->setChannel($request->get('channel')); + $config->setChannel($request->query->get('channel')); $config->setClassId($class->getId()); - $config->setObjectId($request->get('objectId')); + $config->setObjectId($request->query->get('objectId')); $config->save(); return $this->jsonResponse(['success' => true, 'outputConfig' => $config]); @@ -314,8 +314,8 @@ private function sortAttributes(array &$attributes) */ public function getAttributeLabelsAction(Request $request) { - $configration = json_decode($request->get('configuration')); - $class = ClassDefinition::getById($request->get('classId')); + $configration = json_decode($request->request->getString('configuration')); + $class = ClassDefinition::getById($request->request->getString('classId')); $configration = $this->doGetAttributeLabels($configration, $class); @@ -403,8 +403,8 @@ private function getFieldDefinition($attributeName, $objectClass) public function getFieldDefinitionAction(Request $request) { try { - $objectClass = ClassDefinition::getById($request->get('class_id')); - $def = $this->getFieldDefinition($request->get('key'), $objectClass); + $objectClass = ClassDefinition::getById($request->query->get('class_id')); + $def = $this->getFieldDefinition($request->query->get('key'), $objectClass); return $this->jsonResponse(['success' => true, 'fieldDefinition' => $def]); } catch (\Exception $e) { @@ -423,13 +423,13 @@ public function getFieldDefinitionAction(Request $request) public function saveOutputConfigAction(Request $request, EventDispatcherInterface $eventDispatcher) { try { - $config = OutputDefinition::getById($request->get('config_id')); + $config = OutputDefinition::getById($request->request->getInt('config_id')); - $object = AbstractObject::getById($request->get('object_id')); + $object = AbstractObject::getById($request->request->getInt('object_id')); if (empty($object)) { - throw new \Exception('Data Object with ID' . $request->get('object_id') . ' not found.'); + throw new \Exception('Data Object with ID' . $request->request->getInt('object_id') . ' not found.'); } - if ($config->getObjectId() != $request->get('object_id')) { + if ($config->getObjectId() != $request->request->getInt('object_id')) { $newConfig = new OutputDefinition(); $newConfig->setChannel($config->getChannel()); $newConfig->setClassId($config->getClassId()); @@ -437,7 +437,7 @@ public function saveOutputConfigAction(Request $request, EventDispatcherInterfac $config = $newConfig; } - $configJson = $request->get('config'); + $configJson = $request->request->getString('config'); $config->setConfiguration($configJson); $event = new SaveConfigEvent($config); @@ -469,8 +469,8 @@ private function getFilteredClassDefinitionList(Request $request): ClassDefiniti { $classList = new ClassDefinition\Listing(); - if ($request->get('class_id')) { - $classList->setCondition('id = ?', $request->get('class_id')); + if ($request->request->getString('class_id')) { + $classList->setCondition('id = ?', $request->request->getString('class_id')); } elseif (!empty($this->defaultGridClasses)) { $allowedClassIds = []; foreach ($this->defaultGridClasses as $allowedClass) { diff --git a/src/Controller/ClassController.php b/src/Controller/ClassController.php index ec4a299..fe7dbf7 100644 --- a/src/Controller/ClassController.php +++ b/src/Controller/ClassController.php @@ -50,9 +50,9 @@ class ClassController extends UserAwareController */ public function getClassDefinitionForColumnConfigAction(Request $request) { - $classId = $request->get('id'); + $classId = $request->query->getString('id'); $class = DataObject\ClassDefinition::getById($classId); - $objectId = intval($request->get('oid')); + $objectId = $request->query->getInt('oid'); $filteredDefinitions = DataObject\Service::getCustomLayoutDefinitionForGridColumnConfig($class, $objectId); @@ -124,7 +124,7 @@ private function considerClassificationStoreForColumnConfig(Request $request, ?D $enrichment = false; if ($displayMode == ColumnConfigDisplayMode::DATA_OBJECT || $displayMode == ColumnConfigDisplayMode::RELEVANT) { - $targetObjectId = $request->get('target_oid'); + $targetObjectId = $request->query->getInt('target_oid'); if ($targetObject = DataObject\Concrete::getById($targetObjectId)) { $class->setFieldDefinitions($fieldDefinitions); From 0fa0a7e7d7d88fe48c261c092150035d77180514 Mon Sep 17 00:00:00 2001 From: JiaJia Ji Date: Mon, 26 Aug 2024 16:36:12 +0200 Subject: [PATCH 2/2] replace with has, further narrowing --- src/Controller/AdminController.php | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/src/Controller/AdminController.php b/src/Controller/AdminController.php index 885a1c8..120182e 100644 --- a/src/Controller/AdminController.php +++ b/src/Controller/AdminController.php @@ -216,16 +216,14 @@ public function getOrCreateOutputConfigAction(Request $request) $config = OutputDefinition::getById($request->query->getInt('config_id')); $class = null; if (!$config) { - if (is_numeric($request->query->get('class_id'))) { - $class = ClassDefinition::getById($request->query->getInt('class_id')); - } else { + if ($request->query->has('class_id')) { $class = ClassDefinition::getByName($request->query->getString('class_id')); } if (!$class) { - throw new \Exception('Class ' . $request->query->get('class_id') . ' not found.'); + throw new \Exception('Class ' . $request->query->getString('class_id') . ' not found.'); } - $config = OutputDefinition::getByObjectIdClassIdChannel($request->query->get('objectId'), $class->getId(), $request->query->get('channel')); + $config = OutputDefinition::getByObjectIdClassIdChannel($request->query->getInt('objectId'), $class->getId(), $request->query->getString('channel')); } if ($config) { @@ -237,9 +235,9 @@ public function getOrCreateOutputConfigAction(Request $request) return $this->jsonResponse(['success' => true, 'outputConfig' => $config]); } else { $config = new OutputDefinition(); - $config->setChannel($request->query->get('channel')); + $config->setChannel($request->query->getString('channel')); $config->setClassId($class->getId()); - $config->setObjectId($request->query->get('objectId')); + $config->setObjectId($request->query->getInt('objectId')); $config->save(); return $this->jsonResponse(['success' => true, 'outputConfig' => $config]); @@ -403,8 +401,8 @@ private function getFieldDefinition($attributeName, $objectClass) public function getFieldDefinitionAction(Request $request) { try { - $objectClass = ClassDefinition::getById($request->query->get('class_id')); - $def = $this->getFieldDefinition($request->query->get('key'), $objectClass); + $objectClass = ClassDefinition::getById($request->query->getString('class_id')); + $def = $this->getFieldDefinition($request->query->getString('key'), $objectClass); return $this->jsonResponse(['success' => true, 'fieldDefinition' => $def]); } catch (\Exception $e) { @@ -469,7 +467,7 @@ private function getFilteredClassDefinitionList(Request $request): ClassDefiniti { $classList = new ClassDefinition\Listing(); - if ($request->request->getString('class_id')) { + if ($request->request->has('class_id')) { $classList->setCondition('id = ?', $request->request->getString('class_id')); } elseif (!empty($this->defaultGridClasses)) { $allowedClassIds = [];