2015-01-17 18:00:54 +01:00
|
|
|
<?php
|
2015-06-08 16:47:14 +02:00
|
|
|
|
2015-06-08 17:09:25 +02:00
|
|
|
/*
|
2023-02-17 05:13:51 +01:00
|
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
|
|
* SPDX-License-Identifier: MIT
|
2015-06-08 17:09:25 +02:00
|
|
|
*/
|
|
|
|
|
2017-11-19 19:01:31 +01:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2015-01-17 18:00:54 +01:00
|
|
|
namespace Respect\Validation\Rules;
|
|
|
|
|
2015-10-18 03:44:47 +02:00
|
|
|
use Respect\Validation\Validatable;
|
2015-01-17 18:00:54 +01:00
|
|
|
|
2018-01-28 13:14:15 +01:00
|
|
|
/**
|
|
|
|
* Abstract class to help on creating rules that wrap rules.
|
|
|
|
*
|
2018-11-25 17:20:02 +01:00
|
|
|
* @author Alasdair North <alasdair@runway.io>
|
2018-01-28 13:14:15 +01:00
|
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
|
|
|
*/
|
2015-01-17 18:00:54 +01:00
|
|
|
abstract class AbstractWrapper extends AbstractRule
|
|
|
|
{
|
2018-01-28 13:14:15 +01:00
|
|
|
/**
|
|
|
|
* @var Validatable
|
|
|
|
*/
|
|
|
|
private $validatable;
|
2015-01-17 18:00:54 +01:00
|
|
|
|
2018-01-28 13:14:15 +01:00
|
|
|
/**
|
|
|
|
* Initializes the rule.
|
|
|
|
*/
|
|
|
|
public function __construct(Validatable $validatable)
|
2015-01-17 18:00:54 +01:00
|
|
|
{
|
2018-01-28 13:14:15 +01:00
|
|
|
$this->validatable = $validatable;
|
2015-01-17 18:00:54 +01:00
|
|
|
}
|
|
|
|
|
2018-01-28 13:14:15 +01:00
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2018-01-28 13:14:15 +01:00
|
|
|
*/
|
2018-01-28 17:16:53 +01:00
|
|
|
public function assert($input): void
|
2015-01-17 18:00:54 +01:00
|
|
|
{
|
2018-01-28 17:16:53 +01:00
|
|
|
$this->validatable->assert($input);
|
2015-01-17 18:00:54 +01:00
|
|
|
}
|
|
|
|
|
2018-01-28 13:14:15 +01:00
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2018-01-28 13:14:15 +01:00
|
|
|
*/
|
2018-01-28 16:14:00 +01:00
|
|
|
public function check($input): void
|
2015-01-17 18:00:54 +01:00
|
|
|
{
|
2018-01-28 16:14:00 +01:00
|
|
|
$this->validatable->check($input);
|
2015-01-17 18:00:54 +01:00
|
|
|
}
|
|
|
|
|
2018-01-28 13:14:15 +01:00
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2018-01-28 13:14:15 +01:00
|
|
|
*/
|
2018-01-28 15:41:31 +01:00
|
|
|
public function validate($input): bool
|
2015-01-17 18:00:54 +01:00
|
|
|
{
|
2018-01-28 13:14:15 +01:00
|
|
|
return $this->validatable->validate($input);
|
2015-01-17 18:00:54 +01:00
|
|
|
}
|
2016-02-26 16:03:18 +01:00
|
|
|
|
2018-01-28 13:14:15 +01:00
|
|
|
/**
|
2019-04-05 14:33:00 +02:00
|
|
|
* {@inheritDoc}
|
2018-01-28 13:14:15 +01:00
|
|
|
*/
|
2018-05-24 08:07:55 +02:00
|
|
|
public function setName(string $name): Validatable
|
2016-02-26 16:03:18 +01:00
|
|
|
{
|
2018-01-28 13:14:15 +01:00
|
|
|
$this->validatable->setName($name);
|
2016-03-05 01:42:27 +01:00
|
|
|
|
2016-02-26 16:03:18 +01:00
|
|
|
return parent::setName($name);
|
|
|
|
}
|
2015-01-17 18:00:54 +01:00
|
|
|
}
|