. * */ function_exists('tubepress_load_classes') || require(dirname(__FILE__) . '/../../../../tubepress_classloader.php'); tubepress_load_classes(array('org_tubepress_options_validation_InputValidationService', 'org_tubepress_options_category_Display', 'org_tubepress_message_MessageService')); /** * Default implementation of org_tubepress_options_validation_InputValidationService */ class org_tubepress_options_validation_SimpleInputValidationService implements org_tubepress_options_validation_InputValidationService { private $_messageService; /** * @see org_tubepress_options_validation_InputValidationService::validate($optionName, $candidate) */ public function validate($optionName, $candidate) { switch ($optionName) { case org_tubepress_options_category_Display::THUMB_HEIGHT: $this-> _integerValidation(org_tubepress_options_category_Display::THUMB_HEIGHT, $candidate, 1, 90); break; case org_tubepress_options_category_Display::THUMB_WIDTH: $this-> _integerValidation(org_tubepress_options_category_Display::THUMB_WIDTH, $candidate, 1, 120); break; case org_tubepress_options_category_Display::RESULTS_PER_PAGE: $this-> _integerValidation(org_tubepress_options_category_Display::RESULTS_PER_PAGE, $candidate, 1, 50); break; } } /** * Validates text values * * @param string $name The name of the option being updated * @param unknown_type $candidate The new value for this option * * @return void */ private function _textValidation($name, $candidate) { if (!is_string($candidate)) { throw new Exception(sprintf($this->_messageService->_("validation-text"), $name, $candidate)); } } /** * Validates integral values * * @param string $name The name of the option being updated * @param unknown_type $candidate The new value for this option * @param int $min The minimum (inclusive) value this option * can take * @param int $max The maximum (inclusive) value this option * can take * * @return void */ private function _integerValidation($name, $candidate, $min, $max) { if (intval($candidate) == 0) { throw new Exception(sprintf($this->_messageService->_("validation-int-type"), $name, $candidate)); } if ($candidate < $min || $candidate > $max) { throw new Exception(sprintf($this->_messageService->_("validation-int-range"), $name, $min, $max, $candidate)); } } /** * @see org_tubepress_options_validation_InputValidationService::setMessageService($messageService) */ public function setMessageService(org_tubepress_message_MessageService $messageService) { $this->_messageService = $messageService; } }