summaryrefslogtreecommitdiff
path: root/src/Http/Validation/Rules/StringInputLength.php
diff options
context:
space:
mode:
authormsquare <msquare@notrademark.de>2019-10-13 13:43:08 +0200
committermsquare <msquare@notrademark.de>2019-10-13 13:43:08 +0200
commitc0e97bfe753013b115345b00cbfd9858799a6ac9 (patch)
tree7e98447e4c7d874ec27e26801771086843f3efc3 /src/Http/Validation/Rules/StringInputLength.php
parent285f5509dd948c2359c861eec364a677e8ce4910 (diff)
parent7a2427e70296ef652f76fe2e2edc47d2e0f70f5a (diff)
Password recovery rebuild, correctly translated Mails and some minor fixes #658
Diffstat (limited to 'src/Http/Validation/Rules/StringInputLength.php')
-rw-r--r--src/Http/Validation/Rules/StringInputLength.php44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/Http/Validation/Rules/StringInputLength.php b/src/Http/Validation/Rules/StringInputLength.php
new file mode 100644
index 00000000..7b5c248b
--- /dev/null
+++ b/src/Http/Validation/Rules/StringInputLength.php
@@ -0,0 +1,44 @@
+<?php
+
+namespace Engelsystem\Http\Validation\Rules;
+
+use DateTime;
+use Illuminate\Support\Str;
+use Throwable;
+
+trait StringInputLength
+{
+ /**
+ * Use the input length of a string
+ *
+ * @param mixed $input
+ * @return bool
+ */
+ public function validate($input): bool
+ {
+ if (
+ is_string($input)
+ && !is_numeric($input)
+ && !$this->isDateTime($input)
+ ) {
+ $input = Str::length($input);
+ }
+
+ return parent::validate($input);
+ }
+
+ /**
+ * @param mixed $input
+ * @return bool
+ */
+ protected function isDateTime($input): bool
+ {
+ try {
+ new DateTime($input);
+ } catch (Throwable $e) {
+ return false;
+ }
+
+ return true;
+ }
+}