2015-10-07 07:41:38 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2023-02-17 05:13:51 +01:00
|
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
|
|
* SPDX-License-Identifier: MIT
|
2015-10-07 07:41:38 +02:00
|
|
|
*/
|
|
|
|
|
2017-11-19 19:01:31 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2015-10-07 07:41:38 +02:00
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
2018-09-03 12:18:30 +02:00
|
|
|
use Respect\Validation\Helpers\CanValidateUndefined;
|
2015-10-07 07:41:38 +02:00
|
|
|
|
2018-11-25 17:56:04 +01:00
|
|
|
/**
|
|
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
|
|
|
*/
|
2019-02-17 19:59:35 +01:00
|
|
|
final class Optional extends AbstractWrapper
|
2015-10-07 07:41:38 +02:00
|
|
|
{
|
2018-09-03 12:18:30 +02:00
|
|
|
use CanValidateUndefined;
|
2018-01-18 20:28:51 +01:00
|
|
|
|
2019-02-07 21:22:10 +01:00
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2019-02-07 21:22:10 +01:00
|
|
|
*/
|
2018-01-28 17:16:53 +01:00
|
|
|
public function assert($input): void
|
2015-10-07 07:41:38 +02:00
|
|
|
{
|
2018-01-18 20:28:51 +01:00
|
|
|
if ($this->isUndefined($input)) {
|
2018-01-28 17:16:53 +01:00
|
|
|
return;
|
2015-10-07 07:41:38 +02:00
|
|
|
}
|
|
|
|
|
2018-01-28 17:16:53 +01:00
|
|
|
parent::assert($input);
|
2015-10-07 07:41:38 +02:00
|
|
|
}
|
|
|
|
|
2019-02-07 21:22:10 +01:00
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2019-02-07 21:22:10 +01:00
|
|
|
*/
|
2018-01-28 16:14:00 +01:00
|
|
|
public function check($input): void
|
2015-10-07 07:41:38 +02:00
|
|
|
{
|
2018-01-18 20:28:51 +01:00
|
|
|
if ($this->isUndefined($input)) {
|
2018-01-28 16:14:00 +01:00
|
|
|
return;
|
2015-10-07 07:41:38 +02:00
|
|
|
}
|
|
|
|
|
2018-01-28 16:14:00 +01:00
|
|
|
parent::check($input);
|
2015-10-07 07:41:38 +02:00
|
|
|
}
|
|
|
|
|
2019-02-07 21:22:10 +01:00
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2019-02-07 21:22:10 +01:00
|
|
|
*/
|
2018-01-28 15:41:31 +01:00
|
|
|
public function validate($input): bool
|
2015-10-07 07:41:38 +02:00
|
|
|
{
|
2018-01-18 20:28:51 +01:00
|
|
|
if ($this->isUndefined($input)) {
|
2015-10-07 07:41:38 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::validate($input);
|
|
|
|
}
|
|
|
|
}
|