From: Matthias Schmidt Date: Thu, 25 Jul 2019 16:39:09 +0000 (+0200) Subject: Improve type of IFormDataProcessor::processObjectData() parameter X-Git-Tag: 5.2.0_Alpha_3~9 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=e1d7914dff7941444d9f9a0f44a09b394d081c5a;p=GitHub%2FWoltLab%2FWCF.git Improve type of IFormDataProcessor::processObjectData() parameter See #2988 --- diff --git a/wcfsetup/install/files/lib/system/form/builder/data/FormDataHandler.class.php b/wcfsetup/install/files/lib/system/form/builder/data/FormDataHandler.class.php index 5fd0a23d81..32962e2e1c 100644 --- a/wcfsetup/install/files/lib/system/form/builder/data/FormDataHandler.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/data/FormDataHandler.class.php @@ -57,9 +57,8 @@ class FormDataHandler implements IFormDataHandler { */ public function getObjectData(IFormDocument $document, IStorableObject $object) { $data = $object->getData(); - $objectId = $object->{$object::getDatabaseTableIndexName()}; foreach ($this->processors as $processor) { - $data = $processor->processObjectData($document, $data, $objectId); + $data = $processor->processObjectData($document, $data, $object); if (!is_array($data)) { if ($processor instanceof CustomFormDataProcessor) { diff --git a/wcfsetup/install/files/lib/system/form/builder/data/processor/AbstractFormDataProcessor.class.php b/wcfsetup/install/files/lib/system/form/builder/data/processor/AbstractFormDataProcessor.class.php index 6e24e879b3..7309408cf9 100644 --- a/wcfsetup/install/files/lib/system/form/builder/data/processor/AbstractFormDataProcessor.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/data/processor/AbstractFormDataProcessor.class.php @@ -1,5 +1,6 @@ getName() . "'") . " parameter is expected." ); } + if (!$parameters[1]->isArray()) { throw new \InvalidArgumentException("The form data processor function's second parameter must be an array."); } @@ -93,10 +95,16 @@ class CustomFormDataProcessor extends AbstractFormDataProcessor { ($parameterClass === null ? 'any' : "'" . $parameterClass->getName() . "'") . " parameter is expected." ); } + if (!$parameters[1]->isArray()) { throw new \InvalidArgumentException("The object data processor function's second parameter must be an array."); } + $parameterClass = $parameters[2]->getClass(); + if ($parameterClass === null || $parameterClass->getName() !== IStorableObject::class) { + throw new \InvalidArgumentException("The object data processor function's third parameter must be an instance of '" . IStorableObject::class . "', instead " . ($parameterClass === null ? 'any' : "'" . $parameterClass->getName() . "'") . " parameter is expected."); + } + $this->objectDataProcessor = $objectDataProcessor; } } @@ -130,12 +138,12 @@ class CustomFormDataProcessor extends AbstractFormDataProcessor { /** * @inheritDoc */ - public function processObjectData(IFormDocument $document, array $data, $objectId = null) { + public function processObjectData(IFormDocument $document, array $data, IStorableObject $object) { if ($this->objectDataProcessor === null) { - return parent::processObjectData($document, $data, $objectId); + return parent::processObjectData($document, $data, $object); } - $data = call_user_func($this->objectDataProcessor, $document, $data, $objectId); + $data = call_user_func($this->objectDataProcessor, $document, $data, $object); if (!is_array($data)) { throw new \UnexpectedValueException("Field data processor '{$this->id}' does not return an array."); diff --git a/wcfsetup/install/files/lib/system/form/builder/data/processor/IFormDataProcessor.class.php b/wcfsetup/install/files/lib/system/form/builder/data/processor/IFormDataProcessor.class.php index 21964b2e38..ab75c768e3 100644 --- a/wcfsetup/install/files/lib/system/form/builder/data/processor/IFormDataProcessor.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/data/processor/IFormDataProcessor.class.php @@ -1,5 +1,6 @@