summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-01-11 21:36:00 -0500
committerFrederic Guillot <fred@kanboard.net>2016-01-11 21:36:00 -0500
commit20b9c3d0302625a97fa53eaf299bab2dca3f4970 (patch)
treed8a47a96d31db2cd80a59d1da7489a522c538b4a
parentb50f53ab3aac1311c80e2c1db98bf263f0c81984 (diff)
Move swimlane validator methods
-rw-r--r--app/Controller/Swimlane.php6
-rw-r--r--app/Core/Base.php1
-rw-r--r--app/Model/Swimlane.php84
-rw-r--r--app/ServiceProvider/ClassProvider.php1
-rw-r--r--app/Validator/SwimlaneValidator.php96
-rw-r--r--app/Validator/TaskLinkValidator.php2
6 files changed, 102 insertions, 88 deletions
diff --git a/app/Controller/Swimlane.php b/app/Controller/Swimlane.php
index 5229621c..66410888 100644
--- a/app/Controller/Swimlane.php
+++ b/app/Controller/Swimlane.php
@@ -60,7 +60,7 @@ class Swimlane extends Base
{
$project = $this->getProject();
$values = $this->request->getValues();
- list($valid, $errors) = $this->swimlane->validateCreation($values);
+ list($valid, $errors) = $this->swimlaneValidator->validateCreation($values);
if ($valid) {
if ($this->swimlane->create($values)) {
@@ -84,7 +84,7 @@ class Swimlane extends Base
$project = $this->getProject();
$values = $this->request->getValues() + array('show_default_swimlane' => 0);
- list($valid, ) = $this->swimlane->validateDefaultModification($values);
+ list($valid, ) = $this->swimlaneValidator->validateDefaultModification($values);
if ($valid) {
if ($this->swimlane->updateDefault($values)) {
@@ -126,7 +126,7 @@ class Swimlane extends Base
$project = $this->getProject();
$values = $this->request->getValues();
- list($valid, $errors) = $this->swimlane->validateModification($values);
+ list($valid, $errors) = $this->swimlaneValidator->validateModification($values);
if ($valid) {
if ($this->swimlane->update($values)) {
diff --git a/app/Core/Base.php b/app/Core/Base.php
index 5a726ffa..522e5e05 100644
--- a/app/Core/Base.php
+++ b/app/Core/Base.php
@@ -113,6 +113,7 @@ use Pimple\Container;
* @property \Kanboard\Model\UserMetadata $userMetadata
* @property \Kanboard\Model\Webhook $webhook
* @property \Kanboard\Validator\PasswordResetValidator $passwordResetValidator
+ * @property \Kanboard\Validator\SwimlaneValidator $swimlaneValidator
* @property \Kanboard\Validator\TaskLinkValidator $taskLinkValidator
* @property \Kanboard\Validator\TaskValidator $taskValidator
* @property \Kanboard\Validator\UserValidator $userValidator
diff --git a/app/Model/Swimlane.php b/app/Model/Swimlane.php
index df44985a..e5124e8e 100644
--- a/app/Model/Swimlane.php
+++ b/app/Model/Swimlane.php
@@ -2,9 +2,6 @@
namespace Kanboard\Model;
-use SimpleValidator\Validator;
-use SimpleValidator\Validators;
-
/**
* Swimlanes
*
@@ -470,85 +467,4 @@ class Swimlane extends Base
return true;
}
-
- /**
- * Validate creation
- *
- * @access public
- * @param array $values Form values
- * @return array $valid, $errors [0] = Success or not, [1] = List of errors
- */
- public function validateCreation(array $values)
- {
- $rules = array(
- new Validators\Required('project_id', t('The project id is required')),
- new Validators\Required('name', t('The name is required')),
- );
-
- $v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
-
- return array(
- $v->execute(),
- $v->getErrors()
- );
- }
-
- /**
- * Validate modification
- *
- * @access public
- * @param array $values Form values
- * @return array $valid, $errors [0] = Success or not, [1] = List of errors
- */
- public function validateModification(array $values)
- {
- $rules = array(
- new Validators\Required('id', t('The id is required')),
- new Validators\Required('name', t('The name is required')),
- );
-
- $v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
-
- return array(
- $v->execute(),
- $v->getErrors()
- );
- }
-
- /**
- * Validate default swimlane modification
- *
- * @access public
- * @param array $values Form values
- * @return array $valid, $errors [0] = Success or not, [1] = List of errors
- */
- public function validateDefaultModification(array $values)
- {
- $rules = array(
- new Validators\Required('id', t('The id is required')),
- new Validators\Required('default_swimlane', t('The name is required')),
- );
-
- $v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
-
- return array(
- $v->execute(),
- $v->getErrors()
- );
- }
-
- /**
- * Common validation rules
- *
- * @access private
- * @return array
- */
- private function commonValidationRules()
- {
- return array(
- new Validators\Integer('id', t('The id must be an integer')),
- new Validators\Integer('project_id', t('The project id must be an integer')),
- new Validators\MaxLength('name', t('The maximum length is %d characters', 50), 50)
- );
- }
}
diff --git a/app/ServiceProvider/ClassProvider.php b/app/ServiceProvider/ClassProvider.php
index 80017bb0..89430509 100644
--- a/app/ServiceProvider/ClassProvider.php
+++ b/app/ServiceProvider/ClassProvider.php
@@ -86,6 +86,7 @@ class ClassProvider implements ServiceProviderInterface
),
'Validator' => array(
'PasswordResetValidator',
+ 'SwimlaneValidator',
'TaskValidator',
'TaskLinkValidator',
'UserValidator',
diff --git a/app/Validator/SwimlaneValidator.php b/app/Validator/SwimlaneValidator.php
new file mode 100644
index 00000000..4cc780f9
--- /dev/null
+++ b/app/Validator/SwimlaneValidator.php
@@ -0,0 +1,96 @@
+<?php
+
+namespace Kanboard\Validator;
+
+use SimpleValidator\Validator;
+use SimpleValidator\Validators;
+
+/**
+ * Swimlane Validator
+ *
+ * @package validator
+ * @author Frederic Guillot
+ */
+class SwimlaneValidator extends Base
+{
+ /**
+ * Validate creation
+ *
+ * @access public
+ * @param array $values Form values
+ * @return array $valid, $errors [0] = Success or not, [1] = List of errors
+ */
+ public function validateCreation(array $values)
+ {
+ $rules = array(
+ new Validators\Required('project_id', t('The project id is required')),
+ new Validators\Required('name', t('The name is required')),
+ );
+
+ $v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
+
+ return array(
+ $v->execute(),
+ $v->getErrors()
+ );
+ }
+
+ /**
+ * Validate modification
+ *
+ * @access public
+ * @param array $values Form values
+ * @return array $valid, $errors [0] = Success or not, [1] = List of errors
+ */
+ public function validateModification(array $values)
+ {
+ $rules = array(
+ new Validators\Required('id', t('The id is required')),
+ new Validators\Required('name', t('The name is required')),
+ );
+
+ $v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
+
+ return array(
+ $v->execute(),
+ $v->getErrors()
+ );
+ }
+
+ /**
+ * Validate default swimlane modification
+ *
+ * @access public
+ * @param array $values Form values
+ * @return array $valid, $errors [0] = Success or not, [1] = List of errors
+ */
+ public function validateDefaultModification(array $values)
+ {
+ $rules = array(
+ new Validators\Required('id', t('The id is required')),
+ new Validators\Required('default_swimlane', t('The name is required')),
+ );
+
+ $v = new Validator($values, array_merge($rules, $this->commonValidationRules()));
+
+ return array(
+ $v->execute(),
+ $v->getErrors()
+ );
+ }
+
+ /**
+ * Common validation rules
+ *
+ * @access private
+ * @return array
+ */
+ private function commonValidationRules()
+ {
+ return array(
+ new Validators\Integer('id', t('The id must be an integer')),
+ new Validators\Integer('project_id', t('The project id must be an integer')),
+ new Validators\MaxLength('name', t('The maximum length is %d characters', 50), 50)
+ );
+ }
+}
diff --git a/app/Validator/TaskLinkValidator.php b/app/Validator/TaskLinkValidator.php
index 021eb0b6..c88c2b16 100644
--- a/app/Validator/TaskLinkValidator.php
+++ b/app/Validator/TaskLinkValidator.php
@@ -7,7 +7,7 @@ use SimpleValidator\Validators;
use Kanboard\Model\Task;
/**
- * TaskLink Validator
+ * Task Link Validator
*
* @package validator
* @author Frederic Guillot