Skip to content

Commit a5b89b4

Browse files
committed
add method getInstance()
1 parent 7987c22 commit a5b89b4

31 files changed

+89
-0
lines changed

src/Validator.php

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ public function __construct(?string $cnkey) {
99
$this->cnkey = $cnkey ?? '';
1010
$this->validate_function = new \SplQueue();
1111
}
12+
public static function getInstance(...$params): static {
13+
return new static(...$params);
14+
}
1215
/**
1316
* 设置为非必须项
1417
*/

src/Validator/AnyString.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Swango\HttpServer\Validator;
3+
/**
4+
* @method static getInstance(?string $cnkey, int $min_length = 0, int $max_length = 4096)
5+
*/
36
class AnyString extends \Swango\HttpServer\Validator {
47
private int $min_length, $max_length;
58
public function __construct(?string $cnkey, int $min_length = 0, int $max_length = 4096) {

src/Validator/Anything.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Swango\HttpServer\Validator;
3+
/**
4+
* @method static getInstance(?string $key, &$value)
5+
*/
36
class Anything extends \Swango\HttpServer\Validator {
47
protected function check(?string $key, &$value): void {}
58
public function getCnMsg(): string {

src/Validator/BackedEnum.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Swango\HttpServer\Validator;
3+
/**
4+
* @method static getInstance($cnkey, string $enum_class, ?array $valid_array = null)
5+
*/
36
class BackedEnum extends \Swango\HttpServer\Validator {
47
public function __construct($cnkey, protected string $enum_class, protected ?array $valid_array = null) {
58
parent::__construct($cnkey);

src/Validator/BankCard.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Swango\HttpServer\Validator;
3+
/**
4+
* @method static getInstance()
5+
*/
36
class BankCard extends Varchar {
47
public function __construct() {
58
parent::__construct('银行卡号', 15, 19);

src/Validator/Boolean.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Swango\HttpServer\Validator;
3+
/**
4+
* @method static getInstance(?string $cnkey)
5+
*/
36
class Boolean extends \Swango\HttpServer\Validator {
47
public function getCnMsg(): string {
58
if (isset($this->cnmsg))

src/Validator/COI.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Swango\HttpServer\Validator;
3+
/**
4+
* @method static getInstance()
5+
*/
36
class COI extends Varchar {
47
public function __construct() {
58
parent::__construct('身份证号', 18, 18);

src/Validator/Date.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Swango\HttpServer\Validator;
3+
/**
4+
* @method static getInstance(string $cnkey, bool $not_futrue = true)
5+
*/
36
class Date extends Ob {
47
private $not_futrue;
58
public function __construct(string $cnkey, bool $not_futrue = true) {

src/Validator/DateString.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Swango\HttpServer\Validator;
3+
/**
4+
* @method static getInstance(string $key)
5+
*/
36
class DateString extends Varchar {
47
public function __construct(string $key) {
58
parent::__construct($key, 8, 10);

src/Validator/Double.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Swango\HttpServer\Validator;
3+
/**
4+
* @method static getInstance(?string $cnkey, ?int $decimal = null, float $min = 0.0, float $max = 2147483647.0)
5+
*/
36
class Double extends \Swango\HttpServer\Validator {
47
private ?int $decimal;
58
private float $min, $max;

src/Validator/Email.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Swango\HttpServer\Validator;
3+
/**
4+
* @method static getInstance(?string $cnkey)
5+
*/
36
class Email extends \Swango\HttpServer\Validator {
47
public function getCnMsg(): string {
58
if (isset($this->cnmsg))

src/Validator/Enum.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Swango\HttpServer\Validator;
3+
/**
4+
* @method static getInstance($cnkey, array $enum)
5+
*/
36
class Enum extends \Swango\HttpServer\Validator {
47
private array $enum;
58
private bool $all_string;

src/Validator/FixedArray.php

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
/**
55
* 用于检测每项含义都相同的数组
6+
* @method static getInstance($cnkey, int $min_length = 0, int $max_length = 4096)
67
*/
78
class FixedArray extends \Swango\HttpServer\Validator {
89
private \Swango\HttpServer\Validator $content_validator;

src/Validator/HanZi.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Swango\HttpServer\Validator;
3+
/**
4+
* @method static getInstance($cnkey, $min_length = 0, $max_length = 4096)
5+
*/
36
class HanZi extends Varchar {
47
public function __construct($cnkey, $min_length = 0, $max_length = 4096) {
58
parent::__construct($cnkey, $min_length, $max_length, false);

src/Validator/Hex.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Swango\HttpServer\Validator;
3+
/**
4+
* @method static getInstance($cnkey, $min_length = 0, $max_length = 4096)
5+
*/
36
class Hex extends \Swango\HttpServer\Validator {
47
private $min_length, $max_length;
58
public function __construct($cnkey, $min_length = 0, $max_length = 4096) {

src/Validator/Integer.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Swango\HttpServer\Validator;
3+
/**
4+
* @method static getInstance(?string $cnkey, int $min = 0, int $max = 2147483647)
5+
*/
36
class Integer extends \Swango\HttpServer\Validator {
47
protected int $min, $max;
58
public function __construct(?string $cnkey, int $min = 0, int $max = 2147483647) {

src/Validator/Ip.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Swango\HttpServer\Validator;
3+
/**
4+
* @method static getInstance(?string $cnkey)
5+
*/
36
class Ip extends \Swango\HttpServer\Validator {
47
private $min_length, $max_length;
58
public function getCnMsg(): string {

src/Validator/Latitude.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Swango\HttpServer\Validator;
3+
/**
4+
* @method static getInstance()
5+
*/
36
class Latitude extends Double {
47
public function __construct() {
58
parent::__construct('纬度', null, - 90, 90);

src/Validator/Longitude.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Swango\HttpServer\Validator;
3+
/**
4+
* @method static getInstance()
5+
*/
36
class Longitude extends Double {
47
public function __construct() {
58
parent::__construct('经度', null, - 180, 180);

src/Validator/NumberChar.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Swango\HttpServer\Validator;
3+
/**
4+
* @method static getInstance($cnkey, $length)
5+
*/
36
class NumberChar extends \Swango\HttpServer\Validator {
47
private $lenght;
58
public function __construct($cnkey, $length) {

src/Validator/Ob.php

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
/**
44
* 用于检验
55
* 对象 或 每项含义不同的数组
6+
* @method static getInstance(?string $cnkey)
67
*/
78
class Ob extends \Swango\HttpServer\Validator {
89
private bool $set_null_when_empty = false;

src/Validator/Phone.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Swango\HttpServer\Validator;
3+
/**
4+
* @method static getInstance(?string $key = null)
5+
*/
36
class Phone extends Integer {
47
public function __construct(?string $key = null) {
58
parent::__construct($key ?? '手机号', 13000000000, 19999999999);

src/Validator/Sha1.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Swango\HttpServer\Validator;
3+
/**
4+
* @method static getInstance($cnkey, $min_length = 0, $max_length = 4096)
5+
*/
36
class Sha1 extends \Swango\HttpServer\Validator {
47
public function __construct($cnkey, $min_length = 0, $max_length = 4096) {
58
parent::__construct($cnkey);

src/Validator/Timestamp.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Swango\HttpServer\Validator;
3+
/**
4+
* @method static getInstance($cnkey, $from = null, $to = null)
5+
*/
36
class Timestamp extends Integer {
47
public function __construct($cnkey, $from = null, $to = null) {
58
if (! isset($from))

src/Validator/TimestampMs.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Swango\HttpServer\Validator;
3+
/**
4+
* @method static getInstance($cnkey, $from = null, $to = null)
5+
*/
36
class TimestampMs extends Integer {
47
public function __construct($cnkey, $from = null, $to = null) {
58
if (! isset($from))

src/Validator/UUIdValidator.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Swango\HttpServer\Validator;
3+
/**
4+
* @method static getInstance(string $cnkey = 'uuid')
5+
*/
36
class UUIdValidator extends \Swango\HttpServer\Validator\AnyString {
47
public function __construct(string $cnkey = 'uuid') {
58
parent::__construct($cnkey, 36, 36);

src/Validator/Url.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Swango\HttpServer\Validator;
3+
/**
4+
* @method static getInstance(?string $key = null)
5+
*/
36
class Url extends Anything {
47
public function __construct(?string $key = null) {
58
parent::__construct($key ?? '链接');

src/Validator/Varchar.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Swango\HttpServer\Validator;
3+
/**
4+
* @method static getInstance(?string $cnkey, int $min_length = 0, int $max_length = 4096, bool $more_strict = false)
5+
*/
36
class Varchar extends \Swango\HttpServer\Validator {
47
private int $min_length, $max_length;
58
private bool $more_strict;

src/Validator/WordAndNum.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Swango\HttpServer\Validator;
3+
/**
4+
* @method static getInstance(?string $cnkey, int $min_length = 0, int $max_length = 4096)
5+
*/
36
class WordAndNum extends \Swango\HttpServer\Validator {
47
private int $min_length, $max_length;
58
public function __construct(?string $cnkey, int $min_length = 0, int $max_length = 4096) {

src/Validator/WordNumAndUnderline.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Swango\HttpServer\Validator;
3+
/**
4+
* @method static getInstance($cnkey, $min_length = 0, $max_length = 4096)
5+
*/
36
class WordNumAndUnderline extends \Swango\HttpServer\Validator {
47
private $min_length, $max_length;
58
public function __construct($cnkey, $min_length = 0, $max_length = 4096) {

src/Validator/ZoneCode.php

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22
namespace Swango\HttpServer\Validator;
3+
/**
4+
* @method static getInstance()
5+
*/
36
class ZoneCode extends Integer {
47
public function __construct() {
58
parent::__construct('地区码', 1000, 9032);

0 commit comments

Comments
 (0)