Final Class Yiisoft\Yii\Gii\Validator\TableExistsHandler
| Inheritance | Yiisoft\Yii\Gii\Validator\TableExistsHandler |
|---|---|
| Implements | Yiisoft\Validator\RuleHandlerInterface |
An inline validator that checks if the attribute value refers to an existing class name.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Yii\Gii\Validator\TableExistsHandler | |
| validate() | Yiisoft\Yii\Gii\Validator\TableExistsHandler |
Method Details
| public mixed __construct ( \Yiisoft\Db\Connection\ConnectionInterface $connection ) | ||
| $connection | \Yiisoft\Db\Connection\ConnectionInterface | |
public function __construct(
private readonly ConnectionInterface $connection
) {
}
| public \Yiisoft\Validator\Result validate ( mixed $value, object $rule, \Yiisoft\Validator\ValidationContext $context ) | ||
| $value | mixed | |
| $rule | object | |
| $context | \Yiisoft\Validator\ValidationContext | |
public function validate(mixed $value, object $rule, ValidationContext $context): Result
{
if (!$rule instanceof TableExistsRule) {
throw new UnexpectedRuleException(TableExistsRule::class, $rule);
}
$result = new Result();
if (!is_string($value)) {
$result->addError(sprintf('Value must be a string, %s given.".', gettype($value)));
return $result;
}
try {
$tableSchema = $this->connection->getTableSchema($value);
} catch (\Yiisoft\Db\Exception\Exception $e) {
$result->addError(sprintf('The error occurred during fetching table schema: "%s".', $e));
return $result;
}
if ($tableSchema === null) {
$result->addError(sprintf('Table "%s" does not exist.', $value));
return $result;
}
return $result;
}
Signup or Login in order to comment.