自定义注解
自定义注解类实现
use Astral\Serialize\Contracts\Attribute\InputValueCastInterface;
use Attribute;
#[Attribute(Attribute::TARGET_PROPERTY | Attribute::TARGET_CLASS)]
class CustomerInput implements InputValueCastInterface
{
public function __construct(
public string $prefix = '',
) {
}
public function match(mixed $value, DataCollection $collection, InputValueContext $context): bool
{
// 对所有输入值都生效
return true;
}
public function resolve(mixed $value, DataCollection $collection, InputValueContext $context): mixed
{
// 给输入值添加前缀
return $this->prefix . $value;
}
}输出处理注解类
最后更新于