respect-validation/library/Rules/Optional.php

57 lines
967 B
PHP
Raw Normal View History

2015-10-07 07:41:38 +02:00
<?php
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
2015-10-07 07:41:38 +02:00
*/
declare(strict_types=1);
2015-10-07 07:41:38 +02:00
namespace Respect\Validation\Rules;
use Respect\Validation\Helpers\CanValidateUndefined;
2015-10-07 07:41:38 +02:00
/**
* @author Henrique Moody <henriquemoody@gmail.com>
*/
final class Optional extends AbstractWrapper
2015-10-07 07:41:38 +02:00
{
use CanValidateUndefined;
/**
* {@inheritDoc}
*/
public function assert($input): void
2015-10-07 07:41:38 +02:00
{
if ($this->isUndefined($input)) {
return;
2015-10-07 07:41:38 +02:00
}
parent::assert($input);
2015-10-07 07:41:38 +02:00
}
/**
* {@inheritDoc}
*/
public function check($input): void
2015-10-07 07:41:38 +02:00
{
if ($this->isUndefined($input)) {
return;
2015-10-07 07:41:38 +02:00
}
parent::check($input);
2015-10-07 07:41:38 +02:00
}
/**
* {@inheritDoc}
*/
public function validate($input): bool
2015-10-07 07:41:38 +02:00
{
if ($this->isUndefined($input)) {
2015-10-07 07:41:38 +02:00
return true;
}
return parent::validate($input);
}
}