-
-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
proposal: refactoring of options configuration
Signed-off-by: codisart <[email protected]>
- Loading branch information
Showing
6 changed files
with
112 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
|
||
namespace Laminas\Validator; | ||
|
||
class ValidatorOptionsObject | ||
{ | ||
private $keys; | ||
|
||
public function __construct(array $keys) | ||
{ | ||
$this->shouldHaveOnlyStringValues($keys); | ||
$this->keys = $keys; | ||
} | ||
|
||
private function shouldHaveOnlyStringValues(array $keys) : void | ||
{ | ||
foreach ($keys as $key) { | ||
if (! is_string($key)) { | ||
throw new \InvalidArgumentException('The values of $keys should be only strings'); | ||
} | ||
} | ||
} | ||
|
||
public function argumentsAsArray(array $args) : array | ||
{ | ||
$keys = $this->keys; | ||
$result = []; | ||
foreach ($args as $arg) { | ||
$result[array_shift($keys)] = $arg; | ||
} | ||
return $result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Laminas\Validator; | ||
|
||
trait ValidatorOptionsTrait | ||
{ | ||
public function argumentsAsArray(array $keys, array $args) : array | ||
{ | ||
$this->shouldHaveOnlyStringValues($keys); | ||
$result = []; | ||
foreach ($args as $arg) { | ||
$result[array_shift($keys)] = $arg; | ||
} | ||
return $result; | ||
} | ||
|
||
private function shouldHaveOnlyStringValues(array $keys) : void | ||
{ | ||
foreach ($keys as $key) { | ||
if (! is_string($key)) { | ||
throw new \InvalidArgumentException('The values of $keys should be only strings'); | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters