Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Request::get with explicit input sources #773

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/Controller/Admin/Asset/AssetController.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,9 @@
$cv = [];
$asset = Asset::getById((int) $allParams['node']);

$filter = $request->get('filter');
$filter = $request->query->getString('filter');
$limit = (int)$allParams['limit'];
if (!is_null($filter)) {

Check failure on line 261 in src/Controller/Admin/Asset/AssetController.php

View workflow job for this annotation

GitHub Actions / static-analysis (8.3, highest, 11.x-dev as 11.99.9, true) / Static analysis with phpstan

Call to function is_null() with string will always evaluate to false.

Check failure on line 261 in src/Controller/Admin/Asset/AssetController.php

View workflow job for this annotation

GitHub Actions / static-analysis (8.3, highest, false) / Static analysis with phpstan

Call to function is_null() with string will always evaluate to false.
if (substr($filter, -1) != '*') {
$filter .= '*';
}
Expand All @@ -284,7 +284,7 @@
$childrenList->addConditionParam('parentId = ?', [$asset->getId()]);
$childrenList->filterAccessibleByUser($this->getAdminUser(), $asset);

if (!is_null($filter)) {

Check failure on line 287 in src/Controller/Admin/Asset/AssetController.php

View workflow job for this annotation

GitHub Actions / static-analysis (8.3, highest, 11.x-dev as 11.99.9, true) / Static analysis with phpstan

Call to function is_null() with non-falsy-string will always evaluate to false.

Check failure on line 287 in src/Controller/Admin/Asset/AssetController.php

View workflow job for this annotation

GitHub Actions / static-analysis (8.3, highest, false) / Static analysis with phpstan

Call to function is_null() with non-falsy-string will always evaluate to false.
$childrenList->addConditionParam('CAST(assets.filename AS CHAR CHARACTER SET utf8) COLLATE utf8_general_ci LIKE ?', [$filter]);
}

Expand Down Expand Up @@ -326,10 +326,10 @@
'offset' => $offset,
'limit' => $limit,
'total' => $asset->getChildAmount($this->getAdminUser()),
'overflow' => !is_null($filter) && ($filteredTotalCount > $limit),

Check failure on line 329 in src/Controller/Admin/Asset/AssetController.php

View workflow job for this annotation

GitHub Actions / static-analysis (8.3, highest, 11.x-dev as 11.99.9, true) / Static analysis with phpstan

Call to function is_null() with non-falsy-string will always evaluate to false.

Check failure on line 329 in src/Controller/Admin/Asset/AssetController.php

View workflow job for this annotation

GitHub Actions / static-analysis (8.3, highest, false) / Static analysis with phpstan

Call to function is_null() with non-falsy-string will always evaluate to false.
'nodes' => $assets,
'filter' => $request->get('filter') ? $request->get('filter') : '',
'inSearch' => (int)$request->get('inSearch'),
'filter' => $request->query->getString('filter'),
'inSearch' => $request->query->getInt('inSearch'),
]);
} else {
return $this->adminJson($assets);
Expand Down Expand Up @@ -399,10 +399,10 @@
*/
public function existsAction(Request $request): JsonResponse
{
$parentAsset = \Pimcore\Model\Asset::getById((int)$request->get('parentId'));
$parentAsset = \Pimcore\Model\Asset::getById($request->query->getInt('parentId'));

return new JsonResponse([
'exists' => Asset\Service::pathExists($parentAsset->getRealFullPath().'/'.$request->get('filename')),
'exists' => Asset\Service::pathExists($parentAsset->getRealFullPath().'/'.$request->query->getString('filename')),
]);
}

Expand Down Expand Up @@ -628,7 +628,7 @@
public function addFolderAction(Request $request): JsonResponse
{
$success = false;
$parentAsset = Asset::getById((int)$request->get('parentId'));
$parentAsset = Asset::getById($request->request->getInt('parentId'));
$equalAsset = Asset::getByPath($parentAsset->getRealFullPath() . '/' . $request->get('name'));

if ($parentAsset->isAllowed('create')) {
Expand Down Expand Up @@ -926,7 +926,7 @@
*/
public function showVersionAction(Request $request, Environment $twig): Response
{
$id = (int)$request->get('id');
$id = $request->query->getInt('id');
$version = Model\Version::getById($id);
$asset = $version?->loadData();
if (!$asset) {
Expand Down Expand Up @@ -1128,7 +1128,7 @@
*/
public function getAssetAction(Request $request): StreamedResponse
{
$image = Asset::getById((int)$request->get('id'));
$image = Asset::getById($request->query->getInt('id'));

if (!$image) {
throw $this->createNotFoundException('Asset not found');
Expand Down Expand Up @@ -1161,7 +1161,7 @@
public function getImageThumbnailAction(Request $request): BinaryFileResponse|JsonResponse|StreamedResponse
{
$fileinfo = $request->get('fileinfo');
$image = Asset\Image::getById((int)$request->get('id'));
$image = Asset\Image::getById($request->query->getInt('id'));

if (!$image) {
throw $this->createNotFoundException('Asset not found');
Expand Down Expand Up @@ -1251,8 +1251,8 @@
{
$folder = null;

if ($request->get('id')) {
$folder = Asset\Folder::getById((int)$request->get('id'));
if ($request->query->has('id')) {
$folder = Asset\Folder::getById($request->query->getInt('id'));
if ($folder instanceof Asset\Folder) {
if (!$folder->isAllowed('view')) {
throw $this->createAccessDeniedException('not allowed to view thumbnail');
Expand Down Expand Up @@ -1286,9 +1286,9 @@
$video = null;

if ($request->get('id')) {
$video = Asset\Video::getById((int)$request->get('id'));
} elseif ($request->get('path')) {
$video = Asset\Video::getByPath($request->get('path'));
$video = Asset\Video::getById($request->query->getInt('id'));
} elseif ($request->query->has('path')) {
$video = Asset\Video::getByPath($request->query->getString('path'));
}

if (!$video) {
Expand Down Expand Up @@ -1358,7 +1358,7 @@
*/
public function getDocumentThumbnailAction(Request $request): BinaryFileResponse|StreamedResponse
{
$document = Asset\Document::getById((int)$request->get('id'));
$document = Asset\Document::getById($request->query->getInt('id'));

if (!$document) {
throw $this->createNotFoundException('could not load document asset');
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/Admin/Asset/AssetHelperController.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function getSharedGridColumnConfigs(User $user, string $classId, string $
*/
public function gridDeleteColumnConfigAction(Request $request): JsonResponse
{
$gridConfigId = (int) $request->get('gridConfigId');
$gridConfigId = $request->request->getInt('gridConfigId');
$gridConfig = GridConfig::getById($gridConfigId);
$success = false;
if ($gridConfig) {
Expand Down
8 changes: 4 additions & 4 deletions src/Controller/Admin/DataObject/ClassController.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function getTreeAction(Request $request): JsonResponse
$classes = $classesList->load();

// filter classes
if ($request->get('createAllowed')) {
if ($request->query->getBoolean('createAllowed')) {
$tmpClasses = [];
foreach ($classes as $class) {
if ($this->getAdminUser()->isAllowed($class->getId(), 'class')) {
Expand All @@ -111,8 +111,8 @@ public function getTreeAction(Request $request): JsonResponse
$classes = $tmpClasses;
}

$withId = $request->get('withId');
$useTitle = $request->get('useTitle');
$withId = $request->query->has('withId');
$useTitle = $request->query->has('useTitle');
$getClassConfig = function ($class) use ($defaultIcon, $withId, $useTitle) {
$text = $class->getName();
if ($useTitle) {
Expand Down Expand Up @@ -180,7 +180,7 @@ public function getTreeAction(Request $request): JsonResponse
array_multisort($types, SORT_ASC, array_keys($groups), SORT_ASC, $groups);
}

if (!$request->get('grouped')) {
if (!$request->query->getInt('grouped')) {
// list output
foreach ($groups as $groupName => $groupData) {
foreach ($groupData['classes'] as $class) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ public function deleteRelationAction(Request $request): JsonResponse
{
$this->checkPermission('classificationstore');

$keyId = (int) $request->get('keyId');
$groupId = (int) $request->get('groupId');
$keyId = $request->request->getInt('keyId');
$groupId = $request->request->getInt('groupId');

$config = new Classificationstore\KeyGroupRelation();
$config->setKeyId($keyId);
Expand Down
22 changes: 11 additions & 11 deletions src/Controller/Admin/DataObject/DataObjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@
public function treeGetChildrenByIdAction(Request $request, EventDispatcherInterface $eventDispatcher): JsonResponse
{
$allParams = array_merge($request->request->all(), $request->query->all());
$filter = $request->get('filter');
$object = DataObject::getById((int) $request->get('node'));
$filter = $request->query->getString('filter');
$object = DataObject::getById($request->query->getInt('node'));
$objectTypes = [DataObject::OBJECT_TYPE_OBJECT, DataObject::OBJECT_TYPE_FOLDER];
$objects = [];
$cv = [];
Expand All @@ -104,13 +104,13 @@
}

if ($object->hasChildren($objectTypes)) {
$offset = (int)$request->get('start');
$limit = (int)$request->get('limit', 100000000);
if ($view = $request->get('view', '')) {
$cv = $this->elementService->getCustomViewById($request->get('view'));
$offset = $request->query->getInt('start');
$limit = $request->query->getInt('limit', 100000000);
if ($view = $request->query->getString('view')) {
$cv = $this->elementService->getCustomViewById($view);
}

if (!is_null($filter)) {

Check failure on line 113 in src/Controller/Admin/DataObject/DataObjectController.php

View workflow job for this annotation

GitHub Actions / static-analysis (8.3, highest, 11.x-dev as 11.99.9, true) / Static analysis with phpstan

Call to function is_null() with string will always evaluate to false.

Check failure on line 113 in src/Controller/Admin/DataObject/DataObjectController.php

View workflow job for this annotation

GitHub Actions / static-analysis (8.3, highest, false) / Static analysis with phpstan

Call to function is_null() with string will always evaluate to false.
if (substr($filter, -1) != '*') {
$filter .= '*';
}
Expand Down Expand Up @@ -178,11 +178,11 @@
'offset' => $offset,
'limit' => $limit,
'total' => $total,
'overflow' => !is_null($filter) && ($filteredTotalCount > $limit),

Check failure on line 181 in src/Controller/Admin/DataObject/DataObjectController.php

View workflow job for this annotation

GitHub Actions / static-analysis (8.3, highest, 11.x-dev as 11.99.9, true) / Static analysis with phpstan

Call to function is_null() with string will always evaluate to false.

Check failure on line 181 in src/Controller/Admin/DataObject/DataObjectController.php

View workflow job for this annotation

GitHub Actions / static-analysis (8.3, highest, false) / Static analysis with phpstan

Call to function is_null() with string will always evaluate to false.
'nodes' => $objects,
'fromPaging' => (int)$request->get('fromPaging'),
'filter' => $request->get('filter') ? $request->get('filter') : '',
'inSearch' => (int)$request->get('inSearch'),
'fromPaging' => $request->query->getInt('fromPaging'),
'filter' => $request->query->getString('filter'),
'inSearch' => $request->query->getInt('inSearch'),
]);
}

Expand Down Expand Up @@ -756,7 +756,7 @@
*/
public function getFolderAction(Request $request, EventDispatcherInterface $eventDispatcher): JsonResponse
{
$objectId = (int)$request->get('id');
$objectId = $request->query->getInt('id');
$object = DataObject::getById($objectId);

if (!$object) {
Expand Down Expand Up @@ -1595,7 +1595,7 @@
{
DataObject::setDoNotRestoreKeyAndPath(true);

$id = (int)$request->get('id');
$id = $request->query->getInt('id');
$version = Model\Version::getById($id);
$object = $version?->loadData();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ class DataObjectHelperController extends AdminAbstractController
*/
public function loadObjectDataAction(Request $request): JsonResponse
{
$object = DataObject::getById((int) $request->get('id'));
$object = DataObject::getById($request->query->getInt('id'));
$result = [];
if ($object) {
$result['success'] = true;
Expand Down
18 changes: 9 additions & 9 deletions src/Controller/Admin/Document/DocumentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
*/
public function getDataByIdAction(Request $request, EventDispatcherInterface $eventDispatcher): JsonResponse
{
$document = Document::getById((int) $request->get('id'));
$document = Document::getById($request->query->get('id'));

if (!$document) {
throw $this->createNotFoundException('Document not found');
Expand Down Expand Up @@ -141,11 +141,11 @@
{
$allParams = array_merge($request->request->all(), $request->query->all());

$filter = $request->get('filter');
$filter = $request->query->getString('filter');
$limit = (int)($allParams['limit'] ?? 100000000);
$offset = (int)($allParams['start'] ?? 0);

if (!is_null($filter)) {

Check failure on line 148 in src/Controller/Admin/Document/DocumentController.php

View workflow job for this annotation

GitHub Actions / static-analysis (8.3, highest, 11.x-dev as 11.99.9, true) / Static analysis with phpstan

Call to function is_null() with string will always evaluate to false.

Check failure on line 148 in src/Controller/Admin/Document/DocumentController.php

View workflow job for this annotation

GitHub Actions / static-analysis (8.3, highest, false) / Static analysis with phpstan

Call to function is_null() with string will always evaluate to false.
if (substr($filter, -1) != '*') {
$filter .= '*';
}
Expand Down Expand Up @@ -186,7 +186,7 @@
$condition .= ' AND IF(' . $anyAllowedRowOrChildren . ',1,IF(' . $inheritedPermission . ', ' . $isDisallowedCurrentRow . ' = 0, 0)) = 1';
}

if ($filter) {

Check failure on line 189 in src/Controller/Admin/Document/DocumentController.php

View workflow job for this annotation

GitHub Actions / static-analysis (8.3, highest, 11.x-dev as 11.99.9, true) / Static analysis with phpstan

If condition is always true.

Check failure on line 189 in src/Controller/Admin/Document/DocumentController.php

View workflow job for this annotation

GitHub Actions / static-analysis (8.3, highest, false) / Static analysis with phpstan

If condition is always true.
$condition = '(' . $condition . ')' . ' AND CAST(documents.key AS CHAR CHARACTER SET utf8) COLLATE utf8_general_ci LIKE ' . $db->quote($filter);
}

Expand Down Expand Up @@ -233,8 +233,8 @@
'limit' => $limit,
'total' => $document->getChildAmount($this->getAdminUser()),
'nodes' => $documents,
'filter' => $request->get('filter') ? $request->get('filter') : '',
'inSearch' => (int)$request->get('inSearch'),
'filter' => $request->query->getString('filter'),
'inSearch' => $request->query->getInt('inSearch'),
]);
} else {
return $this->adminJson($documents);
Expand All @@ -250,7 +250,7 @@
$errorMessage = '';

// check for permission
$parentDocument = Document::getById((int)$request->get('parentId'));
$parentDocument = Document::getById($request->request->getInt('parentId'));
$document = null;
if ($parentDocument->isAllowed('create')) {
$intendedPath = $parentDocument->getRealFullPath() . '/' . $request->get('key');
Expand Down Expand Up @@ -442,7 +442,7 @@
$data = ['success' => false];
$allowUpdate = true;

$document = Document::getById((int) $request->get('id'));
$document = Document::getById($request->request->getInt('id'));

$oldPath = $document->getDao()->getCurrentFullPath();
$oldDocument = Document::getById($document->getId(), ['force' => true]);
Expand All @@ -464,7 +464,7 @@

if ($document->isAllowed('settings')) {
// if the position is changed the path must be changed || also from the children
if ($parentId = $request->get('parentId')) {
if ($parentId = $request->request->getInt('parentId')) {
$parentDocument = Document::getById((int) $parentId);

//check if parent is changed
Expand Down Expand Up @@ -512,8 +512,8 @@
try {
$document->save();

if ($request->get('index') !== null) {
$this->updateIndexesOfDocumentSiblings($document, $request->get('index'));
if ($request->request->has('index')) {
$this->updateIndexesOfDocumentSiblings($document, $request->request->getInt('index'));
}

$data = [
Expand Down
16 changes: 8 additions & 8 deletions src/Controller/Admin/Document/DocumentControllerBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ protected function preSendDataActions(array &$data, Model\Document $document, ?V
protected function addPropertiesToDocument(Request $request, Model\Document $document): void
{
// properties
if ($request->get('properties')) {
if ($request->request->has('properties')) {
$properties = [];
// assign inherited properties
foreach ($document->getProperties() as $p) {
Expand All @@ -119,7 +119,7 @@ protected function addPropertiesToDocument(Request $request, Model\Document $doc
}
}

$propertiesData = $this->decodeJson($request->get('properties'));
$propertiesData = $this->decodeJson($request->request->getString('properties'));

if (is_array($propertiesData)) {
foreach ($propertiesData as $propertyName => $propertyData) {
Expand Down Expand Up @@ -155,9 +155,9 @@ protected function addPropertiesToDocument(Request $request, Model\Document $doc
protected function addSettingsToDocument(Request $request, Model\Document $document): void
{
// settings
if ($request->get('settings')) {
if ($request->request->has('settings')) {
if ($document->isAllowed('settings')) {
$settings = $this->decodeJson($request->get('settings'));
$settings = $this->decodeJson($request->request->getString('settings'));

if (array_key_exists('prettyUrl', $settings)) {
$settings['prettyUrl'] = htmlspecialchars($settings['prettyUrl']);
Expand Down Expand Up @@ -210,7 +210,7 @@ protected function addTranslationsData(Model\Document $document, array &$data):
*/
public function saveToSessionAction(Request $request): JsonResponse
{
if ($documentId = (int) $request->get('id')) {
if ($documentId = $request->request->getInt('id')) {
if (!$document = Model\Document\Service::getElementFromSession('document', $documentId, $request->getSession()->getId())) {
$document = Model\Document\PageSnippet::getById($documentId);
if (!$document) {
Expand Down Expand Up @@ -263,7 +263,7 @@ protected function getFromSession(Model\Document $doc, SessionInterface $session
*/
public function removeFromSessionAction(Request $request): JsonResponse
{
Model\Document\Service::removeElementFromSession('document', $request->get('id'), $request->getSession()->getId());
Model\Document\Service::removeElementFromSession('document', $request->request->getInt('id'), $request->getSession()->getId());

return $this->adminJson(['success' => true]);
}
Expand Down Expand Up @@ -313,7 +313,7 @@ protected function getLatestVersion(Model\Document\PageSnippet $document, ?Versi
*/
public function changeMainDocumentAction(Request $request): JsonResponse
{
$doc = Model\Document\PageSnippet::getById((int) $request->get('id'));
$doc = Model\Document\PageSnippet::getById($request->request->getInt('id'));
if ($doc instanceof Model\Document\PageSnippet) {
$doc->setEditables([]);
$doc->setContentMainDocumentId($request->get('contentMainDocumentPath'), true);
Expand Down Expand Up @@ -372,7 +372,7 @@ protected function saveDocument(Model\Document $document, Request $request, bool
$document->setModificationDate(time());
$document->setUserModification($this->getAdminUser()->getId());

$task = strtolower($task ?? $request->get('task'));
$task = strtolower($task ?? $request->query->getString('task'));
$version = null;
switch ($task) {
case $task === self::TASK_PUBLISH && $document->isAllowed($task):
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Admin/Document/EmailController.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class EmailController extends DocumentControllerBase
*/
public function getDataByIdAction(Request $request): JsonResponse
{
$email = Document\Email::getById((int)$request->get('id'));
$email = Document\Email::getById($request->query->getInt('id'));

if (!$email) {
throw $this->createNotFoundException('Email not found');
Expand Down Expand Up @@ -77,7 +77,7 @@ public function getDataByIdAction(Request $request): JsonResponse
*/
public function saveAction(Request $request): JsonResponse
{
$page = Document\Email::getById((int) $request->get('id'));
$page = Document\Email::getById($request->request->getInt('id'));
if (!$page) {
throw $this->createNotFoundException('Email not found');
}
Expand Down
4 changes: 2 additions & 2 deletions src/Controller/Admin/Document/FolderController.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class FolderController extends DocumentControllerBase
*/
public function getDataByIdAction(Request $request): JsonResponse
{
$folder = Document\Folder::getById((int)$request->get('id'));
$folder = Document\Folder::getById($request->query->getInt('id'));
if (!$folder) {
throw $this->createNotFoundException('Folder not found');
}
Expand All @@ -60,7 +60,7 @@ public function getDataByIdAction(Request $request): JsonResponse
*/
public function saveAction(Request $request): JsonResponse
{
$folder = Document\Folder::getById((int) $request->get('id'));
$folder = Document\Folder::getById($request->request->getInt('id'));
if (!$folder) {
throw $this->createNotFoundException('Folder not found');
}
Expand Down
Loading
Loading