From 5886765e374ec08ae4cae5b273c0bb9c19fce288 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 28 Oct 2015 22:27:24 +0100 Subject: [PATCH] CustomVariableNumber: new type for ints and floats --- .../CustomVariable/CustomVariableNumber.php | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 library/Director/CustomVariable/CustomVariableNumber.php diff --git a/library/Director/CustomVariable/CustomVariableNumber.php b/library/Director/CustomVariable/CustomVariableNumber.php new file mode 100644 index 00000000..763db9be --- /dev/null +++ b/library/Director/CustomVariable/CustomVariableNumber.php @@ -0,0 +1,42 @@ +getValue() === $this->getValue(); + } + + public function getDbFormat() + { + return 'json'; + } + + public function getValue() + { + return $this->value; + } + + public function setValue($value) + { + if (! is_int($value) && ! is_float($value)) { + throw new ProgrammingError( + 'Expected a number, got %s', + var_export($value, 1) + ); + } + + $this->value = $value; + + return $this; + } + + public function toConfigString() + { + return (string) $this->value; + } +}