/** * Tries to find a valid id in an uri, both item as package uris. The id * is returned urldecoded. * * @param string $uri Item or package uri * * @return string Urldecoded id */ public static function getIdFromUri($uri) { /* * Works for package and item uris * http://publicapi:5050/packages/tag%3Ademodata.org%2C0012%3Aninjs_XYZ123 * http://publicapi:5050/items/tag%3Ademodata.org%2C0003%3Aninjs_XYZ123 */ $uriPath = parse_url($uri, PHP_URL_PATH); $objectId = str_replace(ContentApiSdk::getAvailableEndpoints(), '', $uriPath); // Remove possible slashes and spaces, since we're working with urls $objectId = trim($objectId, '/ '); $objectId = urldecode($objectId); return $objectId; }
/** * Check if the supplied endpoint is supported by the SDK. * * @param string $endpoint Endpoint url (/ will be automatically prepended) * * @return bool */ private function isValidEndpoint($endpoint) { return !in_array(sprintf('/%s', ltrim($endpoint, '/')), ContentApiSdk::getAvailableEndpoints()); }