From 867ffcc84541d4a5bc6f7c0720ae4f9bc08f6c2e Mon Sep 17 00:00:00 2001 From: Lonnie Ezell Date: Sun, 26 Nov 2017 23:07:27 -0600 Subject: [PATCH] [ci skip] Methods to retrieve validation info --- system/Model.php | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/system/Model.php b/system/Model.php index ab38b20a1e..c0d6038602 100644 --- a/system/Model.php +++ b/system/Model.php @@ -1153,6 +1153,43 @@ class Model //-------------------------------------------------------------------- + /** + * Returns the model's defined validation rules so that they + * can be used elsewhere, if needed. + * + * @return array + */ + public function getValidationRules(array $options=[]) + { + $rules = $this->validationRules; + + if (isset($options['except'])) + { + $rules = array_diff_key($rules, array_flip($options['except'])); + } + elseif (isset($options['only'])) + { + $rules = array_intersect_key($rules, array_flip($options['only'])); + } + + return $rules; + } + + //-------------------------------------------------------------------- + + /** + * Returns the model's define validation messages so they + * can be used elsewhere, if needed. + * + * @return array + */ + public function getValidationMessages() + { + return $this->validationMessages; + } + + //-------------------------------------------------------------------- + /** * A simple event trigger for Model Events that allows additional * data manipulation within the model. Specifically intended for