2010-09-27 23:02:30 +02:00
|
|
|
<?php
|
2015-06-08 16:47:14 +02:00
|
|
|
|
2015-06-08 17:09:25 +02:00
|
|
|
/*
|
|
|
|
* This file is part of Respect/Validation.
|
|
|
|
*
|
|
|
|
* (c) Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
|
|
|
*
|
2019-05-23 16:21:34 +02:00
|
|
|
* For the full copyright and license information, please view the LICENSE file
|
|
|
|
* that was distributed with this source code.
|
2015-06-08 17:09:25 +02:00
|
|
|
*/
|
|
|
|
|
2017-11-19 19:01:31 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2010-09-27 23:02:30 +02:00
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
2018-06-09 01:42:54 +02:00
|
|
|
use function is_null;
|
|
|
|
use function is_scalar;
|
|
|
|
use function preg_match;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Validates whether a string contains no whitespace (spaces, tabs and line breaks).
|
|
|
|
*
|
|
|
|
* @author Alexandre Gomes Gaigalas <alexandre@gaigalas.net>
|
|
|
|
* @author Augusto Pascutti <augusto@phpsp.org.br>
|
|
|
|
* @author Danilo Benevides <danilobenevides01@gmail.com>
|
|
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
|
|
|
*/
|
|
|
|
final class NoWhitespace extends AbstractRule
|
2010-09-27 23:02:30 +02:00
|
|
|
{
|
2019-02-07 20:37:23 +01:00
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2019-02-07 20:37:23 +01:00
|
|
|
*/
|
2018-01-28 15:41:31 +01:00
|
|
|
public function validate($input): bool
|
2010-09-27 23:02:30 +02:00
|
|
|
{
|
2015-05-03 18:55:26 +02:00
|
|
|
if (is_null($input)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-02-09 13:28:08 +01:00
|
|
|
if (is_scalar($input) === false) {
|
2015-05-03 18:55:26 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2017-11-19 19:01:31 +01:00
|
|
|
return !preg_match('#\s#', (string) $input);
|
2010-09-27 23:02:30 +02:00
|
|
|
}
|
2011-03-13 15:50:47 +01:00
|
|
|
}
|