diff options
Diffstat (limited to 'vendor/SimpleValidator')
19 files changed, 0 insertions, 861 deletions
diff --git a/vendor/SimpleValidator/Base.php b/vendor/SimpleValidator/Base.php deleted file mode 100644 index 45c01a6e..00000000 --- a/vendor/SimpleValidator/Base.php +++ /dev/null @@ -1,44 +0,0 @@ -<?php - -/* - * This file is part of Simple Validator. - * - * (c) Frédéric Guillot <contact@fredericguillot.com> - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace SimpleValidator; - -/** - * @author Frédéric Guillot <contact@fredericguillot.com> - */ -abstract class Base -{ - protected $field = ''; - protected $error_message = ''; - protected $data = array(); - - - abstract public function execute(array $data); - - - public function __construct($field, $error_message) - { - $this->field = $field; - $this->error_message = $error_message; - } - - - public function getErrorMessage() - { - return $this->error_message; - } - - - public function getField() - { - return $this->field; - } -}
\ No newline at end of file diff --git a/vendor/SimpleValidator/Validator.php b/vendor/SimpleValidator/Validator.php deleted file mode 100644 index 8bb4d620..00000000 --- a/vendor/SimpleValidator/Validator.php +++ /dev/null @@ -1,67 +0,0 @@ -<?php - -/* - * This file is part of Simple Validator. - * - * (c) Frédéric Guillot <contact@fredericguillot.com> - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace SimpleValidator; - -/** - * @author Frédéric Guillot <contact@fredericguillot.com> - */ -class Validator -{ - private $data = array(); - private $errors = array(); - private $validators = array(); - - - public function __construct(array $data, array $validators) - { - $this->data = $data; - $this->validators = $validators; - } - - - public function execute() - { - $result = true; - - foreach ($this->validators as $validator) { - - if (! $validator->execute($this->data)) { - - $this->addError( - $validator->getField(), - $validator->getErrorMessage() - ); - - $result = false; - } - } - - return $result; - } - - - public function addError($field, $message) - { - if (! isset($this->errors[$field])) { - - $this->errors[$field] = array(); - } - - $this->errors[$field][] = $message; - } - - - public function getErrors() - { - return $this->errors; - } -}
\ No newline at end of file diff --git a/vendor/SimpleValidator/Validators/Alpha.php b/vendor/SimpleValidator/Validators/Alpha.php deleted file mode 100644 index b00b819b..00000000 --- a/vendor/SimpleValidator/Validators/Alpha.php +++ /dev/null @@ -1,33 +0,0 @@ -<?php - -/* - * This file is part of Simple Validator. - * - * (c) Frédéric Guillot <contact@fredericguillot.com> - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace SimpleValidator\Validators; - -use SimpleValidator\Base; - -/** - * @author Frédéric Guillot <contact@fredericguillot.com> - */ -class Alpha extends Base -{ - public function execute(array $data) - { - if (isset($data[$this->field]) && $data[$this->field] !== '') { - - if (! ctype_alpha($data[$this->field])) { - - return false; - } - } - - return true; - } -}
\ No newline at end of file diff --git a/vendor/SimpleValidator/Validators/AlphaNumeric.php b/vendor/SimpleValidator/Validators/AlphaNumeric.php deleted file mode 100644 index e1762d67..00000000 --- a/vendor/SimpleValidator/Validators/AlphaNumeric.php +++ /dev/null @@ -1,33 +0,0 @@ -<?php - -/* - * This file is part of Simple Validator. - * - * (c) Frédéric Guillot <contact@fredericguillot.com> - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace SimpleValidator\Validators; - -use SimpleValidator\Base; - -/** - * @author Frédéric Guillot <contact@fredericguillot.com> - */ -class AlphaNumeric extends Base -{ - public function execute(array $data) - { - if (isset($data[$this->field]) && $data[$this->field] !== '') { - - if (! ctype_alnum($data[$this->field])) { - - return false; - } - } - - return true; - } -}
\ No newline at end of file diff --git a/vendor/SimpleValidator/Validators/Date.php b/vendor/SimpleValidator/Validators/Date.php deleted file mode 100644 index 54c949b0..00000000 --- a/vendor/SimpleValidator/Validators/Date.php +++ /dev/null @@ -1,48 +0,0 @@ -<?php - -namespace SimpleValidator\Validators; - -use SimpleValidator\Base; -use \DateTime; - -class Date extends Base -{ - private $formats = array(); - - public function __construct($field, $error_message, array $formats) - { - parent::__construct($field, $error_message); - $this->formats = $formats; - } - - public function execute(array $data) - { - if (isset($data[$this->field]) && $data[$this->field] !== '') { - - foreach ($this->formats as $format) { - if ($this->isValidDate($data[$this->field], $format) === true) { - return true; - } - } - - return false; - } - - return true; - } - - public function isValidDate($value, $format) - { - $date = DateTime::createFromFormat($format, $value); - - if ($date !== false) { - $errors = DateTime::getLastErrors(); - if ($errors['error_count'] === 0 && $errors['warning_count'] === 0) { - $timestamp = $date->getTimestamp(); - return $timestamp > 0 ? true : false; - } - } - - return false; - } -} diff --git a/vendor/SimpleValidator/Validators/Email.php b/vendor/SimpleValidator/Validators/Email.php deleted file mode 100644 index e4e3d5d6..00000000 --- a/vendor/SimpleValidator/Validators/Email.php +++ /dev/null @@ -1,81 +0,0 @@ -<?php - -/* - * This file is part of Simple Validator. - * - * (c) Frédéric Guillot <contact@fredericguillot.com> - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace SimpleValidator\Validators; - -use SimpleValidator\Base; - -/** - * @author Frédéric Guillot <contact@fredericguillot.com> - */ -class Email extends Base -{ - public function execute(array $data) - { - if (isset($data[$this->field]) && $data[$this->field] !== '') { - - // I use the same validation method as Firefox - // http://hg.mozilla.org/mozilla-central/file/cf5da681d577/content/html/content/src/nsHTMLInputElement.cpp#l3967 - - $value = $data[$this->field]; - $length = strlen($value); - - // If the email address begins with a '@' or ends with a '.', - // we know it's invalid. - if ($value[0] === '@' || $value[$length - 1] === '.') { - - return false; - } - - // Check the username - for ($i = 0; $i < $length && $value[$i] !== '@'; ++$i) { - - $c = $value[$i]; - - if (! (ctype_alnum($c) || $c === '.' || $c === '!' || $c === '#' || $c === '$' || - $c === '%' || $c === '&' || $c === '\'' || $c === '*' || $c === '+' || - $c === '-' || $c === '/' || $c === '=' || $c === '?' || $c === '^' || - $c === '_' || $c === '`' || $c === '{' || $c === '|' || $c === '}' || - $c === '~')) { - - return false; - } - } - - // There is no domain name (or it's one-character long), - // that's not a valid email address. - if (++$i >= $length) return false; - if (($i + 1) === $length) return false; - - // The domain name can't begin with a dot. - if ($value[$i] === '.') return false; - - // Parsing the domain name. - for (; $i < $length; ++$i) { - - $c = $value[$i]; - - if ($c === '.') { - - // A dot can't follow a dot. - if ($value[$i - 1] === '.') return false; - } - elseif (! (ctype_alnum($c) || $c === '-')) { - - // The domain characters have to be in this list to be valid. - return false; - } - } - } - - return true; - } -}
\ No newline at end of file diff --git a/vendor/SimpleValidator/Validators/Equals.php b/vendor/SimpleValidator/Validators/Equals.php deleted file mode 100644 index 91f34e4b..00000000 --- a/vendor/SimpleValidator/Validators/Equals.php +++ /dev/null @@ -1,43 +0,0 @@ -<?php - -/* - * This file is part of Simple Validator. - * - * (c) Frédéric Guillot <contact@fredericguillot.com> - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace SimpleValidator\Validators; - -use SimpleValidator\Base; - -/** - * @author Frédéric Guillot <contact@fredericguillot.com> - */ -class Equals extends Base -{ - private $field2; - - - public function __construct($field1, $field2, $error_message) - { - parent::__construct($field1, $error_message); - - $this->field2 = $field2; - } - - - public function execute(array $data) - { - if (isset($data[$this->field]) && $data[$this->field] !== '') { - - if (! isset($data[$this->field2])) return false; - - return $data[$this->field] === $data[$this->field2]; - } - - return true; - } -}
\ No newline at end of file diff --git a/vendor/SimpleValidator/Validators/GreaterThan.php b/vendor/SimpleValidator/Validators/GreaterThan.php deleted file mode 100644 index e038cb61..00000000 --- a/vendor/SimpleValidator/Validators/GreaterThan.php +++ /dev/null @@ -1,36 +0,0 @@ -<?php - -/* - * This file is part of Simple Validator. - * - * (c) Frédéric Guillot - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace SimpleValidator\Validators; - -use SimpleValidator\Base; - -class GreaterThan extends Base -{ - private $min; - - - public function __construct($field, $error_message, $min) - { - parent::__construct($field, $error_message); - $this->min = $min; - } - - - public function execute(array $data) - { - if (isset($data[$this->field]) && $data[$this->field] !== '') { - return $data[$this->field] > $this->min; - } - - return true; - } -}
\ No newline at end of file diff --git a/vendor/SimpleValidator/Validators/Integer.php b/vendor/SimpleValidator/Validators/Integer.php deleted file mode 100644 index 150558a3..00000000 --- a/vendor/SimpleValidator/Validators/Integer.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php - -/* - * This file is part of Simple Validator. - * - * (c) Frédéric Guillot <contact@fredericguillot.com> - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace SimpleValidator\Validators; - -use SimpleValidator\Base; - -/** - * @author Frédéric Guillot <contact@fredericguillot.com> - */ -class Integer extends Base -{ - public function execute(array $data) - { - if (isset($data[$this->field]) && $data[$this->field] !== '') { - - if (is_string($data[$this->field])) { - - if ($data[$this->field][0] === '-') { - - return ctype_digit(substr($data[$this->field], 1)); - } - - return ctype_digit($data[$this->field]); - } - else { - - return is_int($data[$this->field]); - } - } - - return true; - } -}
\ No newline at end of file diff --git a/vendor/SimpleValidator/Validators/Ip.php b/vendor/SimpleValidator/Validators/Ip.php deleted file mode 100644 index 48afe569..00000000 --- a/vendor/SimpleValidator/Validators/Ip.php +++ /dev/null @@ -1,33 +0,0 @@ -<?php - -/* - * This file is part of Simple Validator. - * - * (c) Frédéric Guillot <contact@fredericguillot.com> - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace SimpleValidator\Validators; - -use SimpleValidator\Base; - -/** - * @author Frédéric Guillot <contact@fredericguillot.com> - */ -class Ip extends Base -{ - public function execute(array $data) - { - if (isset($data[$this->field]) && $data[$this->field] !== '') { - - if (! filter_var($data[$this->field], FILTER_VALIDATE_IP)) { - - return false; - } - } - - return true; - } -}
\ No newline at end of file diff --git a/vendor/SimpleValidator/Validators/Length.php b/vendor/SimpleValidator/Validators/Length.php deleted file mode 100644 index 36e50b37..00000000 --- a/vendor/SimpleValidator/Validators/Length.php +++ /dev/null @@ -1,48 +0,0 @@ -<?php - -/* - * This file is part of Simple Validator. - * - * (c) Frédéric Guillot <contact@fredericguillot.com> - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace SimpleValidator\Validators; - -use SimpleValidator\Base; - -/** - * @author Frédéric Guillot <contact@fredericguillot.com> - */ -class Length extends Base -{ - private $min; - private $max; - - - public function __construct($field, $error_message, $min, $max) - { - parent::__construct($field, $error_message); - - $this->min = $min; - $this->max = $max; - } - - - public function execute(array $data) - { - if (isset($data[$this->field]) && $data[$this->field] !== '') { - - $length = mb_strlen($data[$this->field], 'UTF-8'); - - if ($length < $this->min || $length > $this->max) { - - return false; - } - } - - return true; - } -}
\ No newline at end of file diff --git a/vendor/SimpleValidator/Validators/MacAddress.php b/vendor/SimpleValidator/Validators/MacAddress.php deleted file mode 100644 index d9348417..00000000 --- a/vendor/SimpleValidator/Validators/MacAddress.php +++ /dev/null @@ -1,37 +0,0 @@ -<?php - -/* - * This file is part of Simple Validator. - * - * (c) Frédéric Guillot <contact@fredericguillot.com> - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace SimpleValidator\Validators; - -use SimpleValidator\Base; - -/** - * @author Frédéric Guillot <contact@fredericguillot.com> - */ -class MacAddress extends Base -{ - public function execute(array $data) - { - if (isset($data[$this->field]) && $data[$this->field] !== '') { - - $groups = explode(':', $data[$this->field]); - - if (count($groups) !== 6) return false; - - foreach ($groups as $group) { - - if (! ctype_xdigit($group)) return false; - } - } - - return true; - } -}
\ No newline at end of file diff --git a/vendor/SimpleValidator/Validators/MaxLength.php b/vendor/SimpleValidator/Validators/MaxLength.php deleted file mode 100644 index d8e032b0..00000000 --- a/vendor/SimpleValidator/Validators/MaxLength.php +++ /dev/null @@ -1,46 +0,0 @@ -<?php - -/* - * This file is part of Simple Validator. - * - * (c) Frédéric Guillot <contact@fredericguillot.com> - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace SimpleValidator\Validators; - -use SimpleValidator\Base; - -/** - * @author Frédéric Guillot <contact@fredericguillot.com> - */ -class MaxLength extends Base -{ - private $max; - - - public function __construct($field, $error_message, $max) - { - parent::__construct($field, $error_message); - - $this->max = $max; - } - - - public function execute(array $data) - { - if (isset($data[$this->field]) && $data[$this->field] !== '') { - - $length = mb_strlen($data[$this->field], 'UTF-8'); - - if ($length > $this->max) { - - return false; - } - } - - return true; - } -}
\ No newline at end of file diff --git a/vendor/SimpleValidator/Validators/MinLength.php b/vendor/SimpleValidator/Validators/MinLength.php deleted file mode 100644 index 4b7f7d24..00000000 --- a/vendor/SimpleValidator/Validators/MinLength.php +++ /dev/null @@ -1,46 +0,0 @@ -<?php - -/* - * This file is part of Simple Validator. - * - * (c) Frédéric Guillot <contact@fredericguillot.com> - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace SimpleValidator\Validators; - -use SimpleValidator\Base; - -/** - * @author Frédéric Guillot <contact@fredericguillot.com> - */ -class MinLength extends Base -{ - private $min; - - - public function __construct($field, $error_message, $min) - { - parent::__construct($field, $error_message); - - $this->min = $min; - } - - - public function execute(array $data) - { - if (isset($data[$this->field]) && $data[$this->field] !== '') { - - $length = mb_strlen($data[$this->field], 'UTF-8'); - - if ($length < $this->min) { - - return false; - } - } - - return true; - } -}
\ No newline at end of file diff --git a/vendor/SimpleValidator/Validators/Numeric.php b/vendor/SimpleValidator/Validators/Numeric.php deleted file mode 100644 index a958df1a..00000000 --- a/vendor/SimpleValidator/Validators/Numeric.php +++ /dev/null @@ -1,33 +0,0 @@ -<?php - -/* - * This file is part of Simple Validator. - * - * (c) Frédéric Guillot <contact@fredericguillot.com> - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace SimpleValidator\Validators; - -use SimpleValidator\Base; - -/** - * @author Frédéric Guillot <contact@fredericguillot.com> - */ -class Numeric extends Base -{ - public function execute(array $data) - { - if (isset($data[$this->field]) && $data[$this->field] !== '') { - - if (! is_numeric($data[$this->field])) { - - return false; - } - } - - return true; - } -}
\ No newline at end of file diff --git a/vendor/SimpleValidator/Validators/Range.php b/vendor/SimpleValidator/Validators/Range.php deleted file mode 100644 index 1d71b926..00000000 --- a/vendor/SimpleValidator/Validators/Range.php +++ /dev/null @@ -1,51 +0,0 @@ -<?php - -/* - * This file is part of Simple Validator. - * - * (c) Frédéric Guillot <contact@fredericguillot.com> - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace SimpleValidator\Validators; - -use SimpleValidator\Base; - -/** - * @author Frédéric Guillot <contact@fredericguillot.com> - */ -class Range extends Base -{ - private $min; - private $max; - - - public function __construct($field, $error_message, $min, $max) - { - parent::__construct($field, $error_message); - - $this->min = $min; - $this->max = $max; - } - - - public function execute(array $data) - { - if (isset($data[$this->field]) && $data[$this->field] !== '') { - - if (! is_numeric($data[$this->field])) { - - return false; - } - - if ($data[$this->field] < $this->min || $data[$this->field] > $this->max) { - - return false; - } - } - - return true; - } -}
\ No newline at end of file diff --git a/vendor/SimpleValidator/Validators/Required.php b/vendor/SimpleValidator/Validators/Required.php deleted file mode 100644 index e7ef2714..00000000 --- a/vendor/SimpleValidator/Validators/Required.php +++ /dev/null @@ -1,30 +0,0 @@ -<?php - -/* - * This file is part of Simple Validator. - * - * (c) Frédéric Guillot <contact@fredericguillot.com> - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace SimpleValidator\Validators; - -use SimpleValidator\Base; - -/** - * @author Frédéric Guillot <contact@fredericguillot.com> - */ -class Required extends Base -{ - public function execute(array $data) - { - if (! isset($data[$this->field]) || $data[$this->field] === '') { - - return false; - } - - return true; - } -}
\ No newline at end of file diff --git a/vendor/SimpleValidator/Validators/Unique.php b/vendor/SimpleValidator/Validators/Unique.php deleted file mode 100644 index c20dbe11..00000000 --- a/vendor/SimpleValidator/Validators/Unique.php +++ /dev/null @@ -1,78 +0,0 @@ -<?php - -/* - * This file is part of Simple Validator. - * - * (c) Frédéric Guillot <contact@fredericguillot.com> - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace SimpleValidator\Validators; - -use SimpleValidator\Base; - -/** - * @author Frédéric Guillot <contact@fredericguillot.com> - */ -class Unique extends Base -{ - private $pdo; - private $primary_key; - private $table; - - - public function __construct($field, $error_message, \PDO $pdo, $table, $primary_key = 'id') - { - parent::__construct($field, $error_message); - - $this->pdo = $pdo; - $this->primary_key = $primary_key; - $this->table = $table; - } - - - public function execute(array $data) - { - if (isset($data[$this->field]) && $data[$this->field] !== '') { - - if (! isset($data[$this->primary_key])) { - - $rq = $this->pdo->prepare('SELECT COUNT(*) FROM '.$this->table.' WHERE '.$this->field.'=?'); - - $rq->execute(array( - $data[$this->field] - )); - - $result = $rq->fetch(\PDO::FETCH_NUM); - - if (isset($result[0]) && $result[0] === '1') { - - return false; - } - } - else { - - $rq = $this->pdo->prepare( - 'SELECT COUNT(*) FROM '.$this->table.' - WHERE '.$this->field.'=? AND '.$this->primary_key.' != ?' - ); - - $rq->execute(array( - $data[$this->field], - $data[$this->primary_key] - )); - - $result = $rq->fetch(\PDO::FETCH_NUM); - - if (isset($result[0]) && $result[0] === '1') { - - return false; - } - } - } - - return true; - } -}
\ No newline at end of file diff --git a/vendor/SimpleValidator/Validators/Version.php b/vendor/SimpleValidator/Validators/Version.php deleted file mode 100644 index 273a28a5..00000000 --- a/vendor/SimpleValidator/Validators/Version.php +++ /dev/null @@ -1,32 +0,0 @@ -<?php - -/* - * This file is part of Simple Validator. - * - * (c) Frédéric Guillot <contact@fredericguillot.com> - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace SimpleValidator\Validators; - -use SimpleValidator\Base; - -/** - * @author Frédéric Guillot <contact@fredericguillot.com> - * @link http://semver.org/ - */ -class Version extends Base -{ - public function execute(array $data) - { - if (isset($data[$this->field]) && $data[$this->field] !== '') { - - $pattern = '/^[0-9]+\.[0-9]+\.[0-9]+([+-][^+-][0-9A-Za-z-.]*)?$/'; - return (bool) preg_match($pattern, $data[$this->field]); - } - - return true; - } -}
\ No newline at end of file |