phplibrary/src/Validator/Rule/AbstractRule.php

57 lines
1.1 KiB
PHP

<?php
namespace ctiso\Validator\Rule;
use ctiso\Collection;
abstract class AbstractRule
{
public string $field;
protected ?string $errorMsg;
/** @var object */
protected $ctx;
public function __construct(string $field, ?string $errorMsg = null)
{
$this->field = $field;
$this->errorMsg = $errorMsg;
}
public function setName(string $field): self
{
$this->field = $field;
return $this;
}
public function setErrorMsg(?string $errorMsg): self
{
$this->errorMsg = $errorMsg;
return $this;
}
public function getErrorMsg(): string
{
return $this->errorMsg;
}
/**
* @param Collection $container
* @param bool|null $status
* @return bool
*/
public function isValid(Collection $container, $status = null): bool
{
return true;
}
function skipEmpty(): bool {
return true;
}
/**
* @param object $ctx
*/
public function setContext($ctx): void
{
$this->ctx = $ctx;
}
}