From: Matthias Schmidt Date: Thu, 11 Apr 2019 16:22:45 +0000 (+0200) Subject: Throw exception when getting form data before reading values X-Git-Tag: 5.2.0_Alpha_1~156 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=0bc60718c884bd123c9d0f48f71cfed7248e2559;p=GitHub%2FWoltLab%2FWCF.git Throw exception when getting form data before reading values Close #2889 --- diff --git a/wcfsetup/install/files/lib/system/form/builder/FormDocument.class.php b/wcfsetup/install/files/lib/system/form/builder/FormDocument.class.php index 9116846ef5..302b00248c 100644 --- a/wcfsetup/install/files/lib/system/form/builder/FormDocument.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/FormDocument.class.php @@ -63,6 +63,12 @@ class FormDocument implements IFormDocument { */ protected $dataHandler; + /** + * indicates if the form data has been read via `readData()` + * @var boolean + */ + protected $didReadValues = false; + /** * encoding type of this form * @var null| @@ -249,6 +255,13 @@ class FormDocument implements IFormDocument { ); } + /** + * @inheritDoc + */ + public function didReadValues() { + return $this->didReadValues; + } + /** * @inheritDoc */ @@ -321,6 +334,10 @@ class FormDocument implements IFormDocument { * @inheritDoc */ public function getData() { + if (!$this->didReadValues()) { + throw new \BadMethodCallException("Getting data is only possible after calling 'readValues()'."); + } + return $this->getDataHandler()->getData($this); } @@ -573,6 +590,8 @@ class FormDocument implements IFormDocument { $this->requestData = $_POST; } + $this->didReadValues = true; + return $this->traitReadValues(); } diff --git a/wcfsetup/install/files/lib/system/form/builder/IFormDocument.class.php b/wcfsetup/install/files/lib/system/form/builder/IFormDocument.class.php index 0a9df5b0c1..df0cb38ba9 100644 --- a/wcfsetup/install/files/lib/system/form/builder/IFormDocument.class.php +++ b/wcfsetup/install/files/lib/system/form/builder/IFormDocument.class.php @@ -76,6 +76,13 @@ interface IFormDocument extends IFormParentNode { */ public function build(); + /** + * Returns `true` if the form data has been read via `readData()` and `false` otherwise. + * + * @return boolean + */ + public function didReadValues(); + /** * Sets the error message of this form using the given language item and returns this * document. If `null` is passed, the error message is unset. @@ -133,6 +140,8 @@ interface IFormDocument extends IFormParentNode { * of a database object action. * * @return array data passed to database object action + * + * @throws \BadMethodCallException if the method is called before `readValues()` is called */ public function getData();