Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- abstract class AbstractValidator
- {
- private $_args;
- protected const ALLOWED_VALUES = [];
- public function __construct(array $args)
- {
- $this->_args = $args;
- }
- public function isValid(): bool
- {
- foreach ($this->_args as $value)
- if (!in_array(static::ALLOWED_VALUES, $value))
- return false;
- return true;
- }
- }
- class NamesValidator extends AbstractValidator
- {
- protected const ALLOWED_VALUES = [
- 'Mark', 'Bill', 'Dan'
- ];
- }
- class InvalidNamesValidator extends AbstractValidator
- {
- protected const ALLOWED_VALUES = 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement