public static function loadSource($sourceName, $channelName) { global $logger; self::$sourceDAO = DAOFactory::getSourcesDAO(); $logger->debug("CHECK - Fetch Source Details with source '{$sourceName}' and channel '{$channelName}'"); $isValid = SourceTypes::isValidName($sourceName); if (!$isValid) { throw new MalformedRequestDataException("Source '{$sourceName}' is an invalid source type; " . "Must be one of '" . join(', ', SourceTypes::getConstants()) . "'"); } $sourceObj = self::$sourceDAO->queryBySourceAndChannelName($sourceName, $channelName); if (!isset($sourceObj)) { $logger->debug('CHECK - Fetched Source: ' . $sourceObj); throw new SourceNotFoundException($sourceName, $channelName); } $logger->debug('CHECK - Fetched Source: ' . $sourceObj->toString()); return $sourceObj; }
private function sanitize($data) { if (!isset($data['name'])) { throw new MissingParametersException("Channel 'name' field is missing"); } if (!isset($data['description'])) { throw new MissingParametersException("Channel 'description' field is missing"); } if (empty($data['name'])) { throw new MissingParametersException("Channel 'name' field cannot be empty"); } if (!ctype_alpha($data['name'])) { throw new MalformedRequestDataException("Channel 'name' field must be an alphabetic value"); } $sources = $data['sources']; if (isset($sources) && !is_array($sources)) { throw new MalformedRequestDataException("Channel's 'sources' field must be an array of source-names"); } else { if (isset($sources) && is_array($sources)) { foreach ($sources as $sourceName) { $isValid = SourceTypes::isValidName($sourceName); if (!$isValid) { throw new MalformedRequestDataException("Channel's source '{$sourceName}' is invalid; " . "Source names must be one of '" . join(', ', SourceTypes::getConstants()) . "'"); } } } } }