diff --git a/_config.yml b/_config.yml new file mode 100644 index 0000000..42f3951 --- /dev/null +++ b/_config.yml @@ -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. diff --git a/src/Data/Validation.php b/src/Data/Validation.php index a01d1bd..b3e3a0e 100644 --- a/src/Data/Validation.php +++ b/src/Data/Validation.php @@ -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; } @@ -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 { @@ -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( diff --git a/src/StringObjects.php b/src/StringObjects.php index 9119119..81446da 100644 --- a/src/StringObjects.php +++ b/src/StringObjects.php @@ -11,7 +11,7 @@ * @package strobj * @license GPLv2 * @author Uğur Biçer - * @version 2.1.6 + * @version 2.1.7 */ declare(strict_types=1); @@ -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); }