/** * Sets the value of an option * * @param string $optionName The name of the option * @param mixed $optionValue The option value * * @return mixed True if the option was set normally, otherwise a string error message. */ public final function set($optionName, $optionValue) { $eventDispatcherService = tubepress_impl_patterns_sl_ServiceLocator::getEventDispatcher(); $optionValidatorService = tubepress_impl_patterns_sl_ServiceLocator::getOptionValidator(); /** First run it through the filters. */ /** Run it through the filters. */ $event = new tubepress_spi_event_EventBase($optionValue, array('optionName' => $optionName)); $eventDispatcherService->dispatch(tubepress_api_const_event_EventNames::OPTIONS_NVP_PREVALIDATIONSET, $event); $filteredValue = $event->getSubject(); if ($optionValidatorService->isValid($optionName, $filteredValue)) { if ($this->_logger->isHandling(ehough_epilog_Logger::DEBUG)) { $this->_logger->debug(sprintf('Accepted valid value: %s = %s', $optionName, $this->_normalizeForStringOutput($filteredValue))); } $this->_customOptions[$optionName] = $filteredValue; return true; } $problemMessage = $optionValidatorService->getProblemMessage($optionName, $filteredValue); if ($this->_logger->isHandling(ehough_epilog_Logger::DEBUG)) { $this->_logger->warn(sprintf('Ignoring invalid value for "%s" (%s)', $optionName, $problemMessage)); } return $problemMessage; }
/** * @param $optionName * @param $optionValue * * @return bool True if the option is OK for storage, otherwise a string error message. */ private function _validateOneForStorage($optionName, $optionValue) { $optionValidatorService = tubepress_impl_patterns_sl_ServiceLocator::getOptionValidator(); $shouldLog = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG); /** OK, let's see if it's valid. */ if ($optionValidatorService->isValid($optionName, $optionValue)) { if ($shouldLog) { $this->_logger->info(sprintf("Accepted valid value: '%s' = '%s'", $optionName, $optionValue)); } return true; } $problemMessage = $optionValidatorService->getProblemMessage($optionName, $optionValue); if ($shouldLog) { $this->_logger->info(sprintf("Ignoring invalid value: '%s' = '%s'", $optionName, $optionValue)); } return $problemMessage; }