Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/uuur86/strobj
Browse files Browse the repository at this point in the history
  • Loading branch information
uuur86 committed May 27, 2023
2 parents 52a8f3f + 0e04718 commit 030fbdf
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 12 deletions.
3 changes: 3 additions & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
theme: jekyll-theme-minimal
title: PHP String Objects - StrObj
description: StrObj is a php micro-library providing a fluent code interface for object manipulation using string parameters.
37 changes: 27 additions & 10 deletions src/Data/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,21 @@ public function setRules(array $rules): void
*
* @return bool
*/
public function isValid(string $path): bool
public function isValid(string $path = ''): bool
{
if (!isset($this->validationStatus[$path])) {
$this->validate();
}

if ($path === '' || $path === '*') {
foreach ($this->validationStatus as $status) {
if (!$status) {
return false;
}
}
return true;
}

return $this->validationStatus[$path] ?? true;
}

Expand All @@ -165,8 +174,10 @@ public function setValidationStatus(string $path, $value, string $pattern, bool
/**
* Sets the status to the all parent paths.
*
* @param DataPath $path
* @param bool $status
* @param string $path
* @param mixed $value
* @param string $pattern
* @param bool $status
*/
public function addValidationStatus(string $path, $value, string $pattern, bool $required): void
{
Expand All @@ -177,15 +188,21 @@ public function addValidationStatus(string $path, $value, string $pattern, bool
if ($path->valid()) {
$parent_branches = $path->getBranches();

$relative_path = $path->findPaths(
$path_txt,
$value,
function ($path_sub, $val) use (&$status, $required, $pattern) {
if (!$this->setValidationStatus($path_sub, $val, $pattern, $required)) {
$status = false;
if (is_array($value)) {
$relative_path = $path->findPaths(
$path_txt,
$value,
function ($path_sub, $val) use (&$status, $required, $pattern) {
if (!$this->setValidationStatus($path_sub, $val, $pattern, $required)) {
$status = false;
}
}
);
} else {
if (!$this->setValidationStatus($path_txt, $value, $pattern, $required)) {
$status = false;
}
);
}

if (count($parent_branches) > 0) {
$parent_branches = array_combine(
Expand Down
4 changes: 2 additions & 2 deletions src/StringObjects.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @package strobj
* @license GPLv2
* @author Uğur Biçer <[email protected]>
* @version 2.1.6
* @version 2.1.7
*/

declare(strict_types=1);
Expand Down Expand Up @@ -184,7 +184,7 @@ public function toArray(): array
*
* @return bool
*/
public function isValid(string $path): bool
public function isValid(string $path = ''): bool
{
return $this->validation->isValid($path);
}
Expand Down

0 comments on commit 030fbdf

Please sign in to comment.