Skip to content

Commit

Permalink
Add BaseValidator class
Browse files Browse the repository at this point in the history
  • Loading branch information
natanfelles committed Aug 24, 2024
1 parent be66990 commit 9365995
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 15 deletions.
34 changes: 34 additions & 0 deletions src/BaseValidator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php declare(strict_types=1);
/*
* This file is part of Aplus Framework Validation Library.
*
* (c) Natan Felles <[email protected]>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Framework\Validation;

use Framework\Helpers\ArraySimple;

/**
* Class BaseValidator.
*
* @package validation
*/
abstract class BaseValidator
{
/**
* Get field value from data.
*
* @param string $field
* @param array<string,mixed> $data
*
* @return string|null
*/
protected static function getData(string $field, array $data) : ?string
{
$data = ArraySimple::value($field, $data);
return \is_scalar($data) ? (string) $data : null;
}
}
16 changes: 1 addition & 15 deletions src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,8 @@
*
* @package validation
*/
class Validator
class Validator extends BaseValidator
{
/**
* Get field value from data.
*
* @param string $field
* @param array<string,mixed> $data
*
* @return string|null
*/
protected static function getData(string $field, array $data) : ?string
{
$data = ArraySimple::value($field, $data);
return \is_scalar($data) ? (string) $data : null;
}

/**
* Validates alphabetic characters.
*
Expand Down

0 comments on commit 9365995

Please sign in to comment.