mirror of
https://github.com/Respect/Validation.git
synced 2024-05-29 03:42:25 +02:00
Small fixes on Cpf, Json, Odd, Even and Slug
This commit is contained in:
parent
6d042f7c28
commit
77f237f9a2
50
library/Respect/Validation/Exceptions/JsonException.php
Normal file
50
library/Respect/Validation/Exceptions/JsonException.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace Respect\Validation\Exceptions;
|
||||
|
||||
class JsonException extends ValidationException
|
||||
{
|
||||
|
||||
public static $defaultTemplates = array(
|
||||
self::MODE_DEFAULT => array(
|
||||
self::STANDARD => '{{name}} must be a valid JSON string',
|
||||
),
|
||||
self::MODE_NEGATIVE => array(
|
||||
self::STANDARD => '{{name}} must not be a valid JSON string',
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* LICENSE
|
||||
*
|
||||
* Copyright (c) 2009-2011, Jair Henrique.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of Alexandre Gomes Gaigalas nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
|
@ -15,7 +15,7 @@ class Cpf extends AbstractRule
|
|||
return $this->processNumber($input);
|
||||
}
|
||||
|
||||
private function processNumber($input)
|
||||
protected function processNumber($input)
|
||||
{
|
||||
$multiple = 10;
|
||||
$firstDigit = $secondDigit = 0;
|
||||
|
@ -40,7 +40,7 @@ class Cpf extends AbstractRule
|
|||
return ("{$firstDigit}{$secondDigit}" === $digits);
|
||||
}
|
||||
|
||||
private function isSequenceOfNumber($input)
|
||||
protected function isSequenceOfNumber($input)
|
||||
{
|
||||
for ($i = 0; $i <= 9; $i++)
|
||||
if ($input === str_repeat($i, 11))
|
||||
|
|
|
@ -10,7 +10,7 @@ class Even extends AbstractRule
|
|||
public function validate($input)
|
||||
{
|
||||
$input = (int) $input;
|
||||
return ($input % 2 == 0);
|
||||
return ($input % 2 === 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
46
library/Respect/Validation/Rules/Json.php
Normal file
46
library/Respect/Validation/Rules/Json.php
Normal file
|
@ -0,0 +1,46 @@
|
|||
<?php
|
||||
|
||||
namespace Respect\Validation\Rules;
|
||||
|
||||
class Json extends AbstractRule
|
||||
{
|
||||
|
||||
public function validate($input)
|
||||
{
|
||||
return (bool) (json_decode($input));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* LICENSE
|
||||
*
|
||||
* Copyright (c) 2011, Jair Henrique, Emerson Carvalho
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* * Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* * Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* * Neither the name of Alexandre Gomes Gaigalas nor the names of its
|
||||
* contributors may be used to endorse or promote products derived from this
|
||||
* software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
|
@ -8,7 +8,7 @@ class Odd extends AbstractRule
|
|||
public function validate($input)
|
||||
{
|
||||
$input = (int) $input;
|
||||
return ($input % 2 != 0);
|
||||
return ($input % 2 !== 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -46,6 +46,7 @@ class SlugTest extends \PHPUnit_Framework_TestCase {
|
|||
array('-assim-nao-pode'),
|
||||
array('assim-tambem-nao-'),
|
||||
array('nem--assim'),
|
||||
array('--nem-assim'),
|
||||
array('Nem mesmo Assim'),
|
||||
array('Ou-ate-assim'),
|
||||
array('-Se juntar-tudo-Então-')
|
||||
|
|
Loading…
Reference in a new issue