Try and breakup a URI into a prefix and local part
If $createNamespace is true, and the URI isn't part of an existing namespace, then EasyRdf will attempt to create a new namespace and return the name of the new prefix (for example 'ns0', 'term').
If it isn't possible to split the URI, then null will be returned.
string $uri The full URI (eg 'http://xmlns.com/foaf/0.1/name'):
bool $createNamespace If true, a new namespace will be created:
array The split URI (eg 'foaf', 'name') or null
public static function splitUri($uri, $createNamespace = false) {
if ($uri === null or $uri === '') {
throw new InvalidArgumentException("\$uri cannot be null or empty");
}
if (is_object($uri) and $uri instanceof EasyRdf_Resource) {
$uri = $uri
->getUri();
}
elseif (!is_string($uri)) {
throw new InvalidArgumentException("\$uri should be a string or EasyRdf_Resource");
}
foreach (self::$namespaces as $prefix => $long) {
if (substr($uri, 0, strlen($long)) == $long) {
return array(
$prefix,
substr($uri, strlen($long)),
);
}
}
if ($createNamespace) {
// Try and create a new namespace
# FIXME: check the valid characters for an XML element name
if (preg_match("/^(.+?)([\\w\\-]+)\$/", $uri, $matches)) {
$prefix = "ns" . self::$anonymousNamespaceCount++;
self::set($prefix, $matches[1]);
return array(
$prefix,
$matches[2],
);
}
}
return null;
}