2022-12-24 22:10:40 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2024-01-31 22:15:08 +08:00
|
|
|
* Copyright (c) Alexandre Gomes Gaigalas <alganet@gmail.com>
|
|
|
|
* SPDX-License-Identifier: MIT
|
2022-12-24 22:10:40 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace Respect\Validation\Exceptions;
|
|
|
|
|
|
|
|
use function count;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @author Henrique Moody <henriquemoody@gmail.com>
|
|
|
|
*/
|
|
|
|
final class KeySetException extends GroupedValidationException implements NonOmissibleException
|
|
|
|
{
|
|
|
|
public const STRUCTURE = 'structure';
|
2024-01-31 22:15:08 +08:00
|
|
|
public const STRUCTURE_EXTRA = 'structure_extra';
|
2022-12-24 22:10:40 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
protected $defaultTemplates = [
|
|
|
|
self::MODE_DEFAULT => [
|
|
|
|
self::NONE => '所有必需的规则都必须传递给 {{name}}',
|
|
|
|
self::SOME => '这些规则必须传递给 {{name}}',
|
|
|
|
self::STRUCTURE => '必须有键 {{keys}}',
|
2024-01-31 22:15:08 +08:00
|
|
|
|
|
|
|
self::STRUCTURE_EXTRA => '不能有键 {{keys}}',
|
2022-12-24 22:10:40 +08:00
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritDoc}
|
|
|
|
*/
|
|
|
|
protected function chooseTemplate(): string
|
|
|
|
{
|
2024-01-31 22:15:08 +08:00
|
|
|
if (count($this->getParam('extraKeys'))) {
|
|
|
|
return self::STRUCTURE_EXTRA;
|
|
|
|
}
|
|
|
|
|
2022-12-24 22:10:40 +08:00
|
|
|
if (count($this->getChildren()) === 0) {
|
|
|
|
return self::STRUCTURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::chooseTemplate();
|
|
|
|
}
|
|
|
|
}
|