respect-validation/library/Rules/AbstractWrapper.php

69 lines
1.2 KiB
PHP
Raw Normal View History

2015-01-17 18:00:54 +01:00
<?php
2015-06-08 16:47:14 +02:00
/*
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
* SPDX-License-Identifier: MIT
*/
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
/**
* Abstract class to help on creating rules that wrap rules.
*
* @author Alasdair North <alasdair@runway.io>
* @author Henrique Moody <henriquemoody@gmail.com>
*/
2015-01-17 18:00:54 +01:00
abstract class AbstractWrapper extends AbstractRule
{
/**
* @var Validatable
*/
private $validatable;
2015-01-17 18:00:54 +01:00
/**
* Initializes the rule.
*/
public function __construct(Validatable $validatable)
2015-01-17 18:00:54 +01:00
{
$this->validatable = $validatable;
2015-01-17 18:00:54 +01:00
}
/**
* {@inheritDoc}
*/
public function assert($input): void
2015-01-17 18:00:54 +01:00
{
$this->validatable->assert($input);
2015-01-17 18:00:54 +01:00
}
/**
* {@inheritDoc}
*/
public function check($input): void
2015-01-17 18:00:54 +01:00
{
$this->validatable->check($input);
2015-01-17 18:00:54 +01:00
}
/**
* {@inheritDoc}
*/
public function validate($input): bool
2015-01-17 18:00:54 +01:00
{
return $this->validatable->validate($input);
2015-01-17 18:00:54 +01:00
}
/**
* {@inheritDoc}
*/
public function setName(string $name): Validatable
{
$this->validatable->setName($name);
return parent::setName($name);
}
2015-01-17 18:00:54 +01:00
}