Skip to content

Commit

Permalink
Merge pull request #124 from pimcore/request-explicit-sources
Browse files Browse the repository at this point in the history
Replace Request::get with explicit input sources
  • Loading branch information
mcop1 authored Aug 27, 2024
2 parents 2325315 + 0fa0a7e commit 985400e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 29 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
46 changes: 22 additions & 24 deletions src/Controller/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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]);
Expand All @@ -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());
Expand All @@ -213,19 +213,17 @@ 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'));
} else {
$class = ClassDefinition::getByName($request->get('class_id'));
if ($request->query->has('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->getString('class_id') . ' not found.');
}

$config = OutputDefinition::getByObjectIdClassIdChannel($request->get('objectId'), $class->getId(), $request->get('channel'));
$config = OutputDefinition::getByObjectIdClassIdChannel($request->query->getInt('objectId'), $class->getId(), $request->query->getString('channel'));
}

if ($config) {
Expand All @@ -237,9 +235,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->getString('channel'));
$config->setClassId($class->getId());
$config->setObjectId($request->get('objectId'));
$config->setObjectId($request->query->getInt('objectId'));
$config->save();

return $this->jsonResponse(['success' => true, 'outputConfig' => $config]);
Expand Down Expand Up @@ -314,8 +312,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);

Expand Down Expand Up @@ -403,8 +401,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->getString('class_id'));
$def = $this->getFieldDefinition($request->query->getString('key'), $objectClass);

return $this->jsonResponse(['success' => true, 'fieldDefinition' => $def]);
} catch (\Exception $e) {
Expand All @@ -423,21 +421,21 @@ 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());
$newConfig->setObjectId($object->getId());
$config = $newConfig;
}

$configJson = $request->get('config');
$configJson = $request->request->getString('config');
$config->setConfiguration($configJson);

$event = new SaveConfigEvent($config);
Expand Down Expand Up @@ -469,8 +467,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->has('class_id')) {
$classList->setCondition('id = ?', $request->request->getString('class_id'));
} elseif (!empty($this->defaultGridClasses)) {
$allowedClassIds = [];
foreach ($this->defaultGridClasses as $allowedClass) {
Expand Down
6 changes: 3 additions & 3 deletions src/Controller/ClassController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 985400e

Please sign in to comment.