protected function validate()
    {
        // If attributes are set, validate them.
        if (!empty($this->attributes)) {
            // It's possible that there are no rules for the attributes available.
            // If so, skip attribute validation.
            if (sizeof($this->getAttributeRules()) > 0) {
                $validate_attributes = new Validator($this->attributes);
                $validate_attributes->rules($this->getAttributeRules());

                // Validation failed to succeeed, show errors
                if (!$validate_attributes->validate()) {
                    echo 'Some attributes failed to pass the validator:';
                    foreach ($validate_attributes->errors() as $failed_attr) {
                        echo ' '. $failed_attr[0];
                    }
                    return false;
                }
            }
        }

        // If a value is set, validate it.
        if (array_key_exists('value', $this)) {
            // It's possible that there is no value rule set.
            // If so, skip value validation.
            if (sizeof($this->getValueRule()) > 0) {
                $validate_value = new Validator(['value' => $this->value]);
                $validate_value->rules($this->getValueRule());

                // Validation failed to succeeed, show errors
                if (!$validate_value->validate()) {
                    echo "The 'value' failed to pass the validator:";
                    foreach ($validate_value->errors() as $message) {
                        if (is_array($message)) {
                            $message = implode(',', $message);
                        }
                        echo ' '. strtolower($message);
                    }
                    return false;
                }
            }
        }

        return true;
    }