PHP code example of twinkle / dto-validation

1. Go to this page and download the library: Download twinkle/dto-validation library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

twinkle / dto-validation example snippets



$container = new \Twinkle\DI\Container([
    'Validate:Required' => \twinkle\dto\validation\annotation\Required::class,
    'Validate:Type' => \twinkle\dto\validation\annotation\Type::class,
    'Validate:Enum' => \twinkle\dto\validation\annotation\Enum::class,
]);
\Twinkle\DI\Tools::setContainer($container);



/**
 * @Validate # 是否需要较验
 * @var integer # 声明类型
 * @var integer autoConvert=integer # 声明类型,并且尝试自动转换
 * @Required() # 必须字段
 * @Required(default=1) # 字段必须,在字段为null的情况下设置默认值
 * @Enum(1,2,3) # 字段值必须为1,2,3中的一个
 */