class RdfNamespace

A namespace registry and manipulation class.

Methods

static array
namespaces()

Return all the namespaces registered

static 
resetNamespaces()

Resets list of namespaces to the one, which is provided by EasyRDF useful for tests, among other things

static string
get(string $prefix)

Return a namespace given its prefix.

static 
set(string $prefix, string $long)

Register a new namespace.

static string
getDefault()

Get the default namespace

static 
setDefault(string $namespace)

Set the default namespace

static 
delete(string $prefix)

Delete an existing namespace.

static 
reset()

Delete the anonymous namespaces and reset the counter to 0

static array
splitUri(string $uri, bool $createNamespace = false)

Try and breakup a URI into a prefix and local part

static string
prefixOfUri(string $uri)

Return the prefix namespace that a URI belongs to.

static string
shorten(string $uri, bool $createNamespace = false)

Shorten a URI by substituting in the namespace prefix.

static string
expand(string $shortUri)

Expand a shortened URI (qname) back into a full URI.

Details

at line 125
static array namespaces()

Return all the namespaces registered

Return Value

array Associative array of all the namespaces.

at line 138
static resetNamespaces()

Resets list of namespaces to the one, which is provided by EasyRDF useful for tests, among other things

at line 151
static string get(string $prefix)

Return a namespace given its prefix.

Parameters

string $prefix The namespace prefix (eg 'foaf')

Return Value

string The namespace URI (eg 'http://xmlns.com/foaf/0.1/')

Exceptions

InvalidArgumentException

at line 184
static set(string $prefix, string $long)

Register a new namespace.

Parameters

string $prefix The namespace prefix (eg 'foaf')
string $long The namespace URI (eg 'http://xmlns.com/foaf/0.1/')

Exceptions

LogicException
InvalidArgumentException

at line 246
static string getDefault()

Get the default namespace

Returns the URI of the default namespace or null if no default namespace is defined.

Return Value

string The URI of the default namespace

at line 264
static setDefault(string $namespace)

Set the default namespace

Set the default namespace to either a URI or the prefix of an already defined namespace.

Example: EasyRdf\RdfNamespace::setDefault('http://schema.org/');

Parameters

string $namespace The URI or prefix of a namespace (eg 'og')

Exceptions

InvalidArgumentException

at line 290
static delete(string $prefix)

Delete an existing namespace.

Parameters

string $prefix The namespace prefix (eg 'foaf')

Exceptions

InvalidArgumentException

at line 308
static reset()

Delete the anonymous namespaces and reset the counter to 0

at line 331
static array splitUri(string $uri, bool $createNamespace = false)

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.

Parameters

string $uri The full URI (eg 'http://xmlns.com/foaf/0.1/name')
bool $createNamespace If true, a new namespace will be created

Return Value

array The split URI (eg 'foaf', 'name') or null

Exceptions

InvalidArgumentException

at line 382
static string prefixOfUri(string $uri)

Return the prefix namespace that a URI belongs to.

Parameters

string $uri A full URI (eg 'http://xmlns.com/foaf/0.1/name')

Return Value

string The prefix namespace that it is a part of(eg 'foaf')

at line 403
static string shorten(string $uri, bool $createNamespace = false)

Shorten a URI by substituting in the namespace prefix.

If $createNamespace is true, and the URI isn't part of an existing namespace, then EasyRdf will attempt to create a new namespace and use that namespace to shorten the URI (for example ns0:term).

If it isn't possible to shorten the URI, then null will be returned.

Parameters

string $uri The full URI (eg 'http://xmlns.com/foaf/0.1/name')
bool $createNamespace If true, a new namespace will be created

Return Value

string The shortened URI (eg 'foaf:name') or null

at line 421
static string expand(string $shortUri)

Expand a shortened URI (qname) back into a full URI.

If it isn't possible to expand the qname, for example if the namespace isn't registered, then the original string will be returned.

Parameters

string $shortUri The short URI (eg 'foaf:name')

Return Value

string The full URI (eg 'http://xmlns.com/foaf/0.1/name')

Exceptions

InvalidArgumentException