Skip to content

Commit 9365995

Browse files
committed
Add BaseValidator class
1 parent be66990 commit 9365995

File tree

2 files changed

+35
-15
lines changed

2 files changed

+35
-15
lines changed

src/BaseValidator.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of Aplus Framework Validation Library.
4+
*
5+
* (c) Natan Felles <natanfelles@gmail.com>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace Framework\Validation;
11+
12+
use Framework\Helpers\ArraySimple;
13+
14+
/**
15+
* Class BaseValidator.
16+
*
17+
* @package validation
18+
*/
19+
abstract class BaseValidator
20+
{
21+
/**
22+
* Get field value from data.
23+
*
24+
* @param string $field
25+
* @param array<string,mixed> $data
26+
*
27+
* @return string|null
28+
*/
29+
protected static function getData(string $field, array $data) : ?string
30+
{
31+
$data = ArraySimple::value($field, $data);
32+
return \is_scalar($data) ? (string) $data : null;
33+
}
34+
}

src/Validator.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,8 @@
1818
*
1919
* @package validation
2020
*/
21-
class Validator
21+
class Validator extends BaseValidator
2222
{
23-
/**
24-
* Get field value from data.
25-
*
26-
* @param string $field
27-
* @param array<string,mixed> $data
28-
*
29-
* @return string|null
30-
*/
31-
protected static function getData(string $field, array $data) : ?string
32-
{
33-
$data = ArraySimple::value($field, $data);
34-
return \is_scalar($data) ? (string) $data : null;
35-
}
36-
3723
/**
3824
* Validates alphabetic characters.
3925
*

0 commit comments

Comments
 (0)