EasyRdf API Documentation
Class

EasyRdf_Format

class EasyRdf_Format

Class the represents an RDF file format.

For each format, the name, label, URIs and associated MIME Types are stored. A single parser and serialiser can also be registered to each format.

Methods

static array getNames()

Get a list of format names

static array getFormats()

Get a list of all the registered formats

static string getHttpAcceptHeader(array $extraTypes = array())

Generates an HTTP Accept header string

static boolean formatExists(string $name)

Check if a named graph exists

static object getFormat(string $query)

Get a EasyRdf_Format from a name, uri or mime type

static object register(string $name, string $label = null, string $uri = null, string $mimeTypes = array(), string $extensions = array())

Register a new format

static  unregister(string $name)

Remove a format from the registry

static  registerParser(string $name, string $class)

Class method to register a parser class to a format name

static  registerSerialiser(string $name, string $class)

Class method to register a serialiser class to a format name

static object guessFormat(string $data, string $filename = null)

Attempt to guess the document format from some content.

__construct(string $name)

This constructor is for internal use only.

string getName()

Get the name of a format object

string getLabel()

Get the label for a format object

setLabel(string $label)

Set the label for a format object

string getUri()

Get the URI for a format object

setUri(string $uri)

Set the URI for a format object

string getDefaultMimeType()

Get the default registered mime type for a format object

array getMimeTypes()

Get all the registered mime types for a format object

setMimeTypes(array $mimeTypes)

Set the MIME Types for a format object

string getDefaultExtension()

Get the default registered file extension (filename suffix) for a format object

array getExtensions()

Get all the registered file extensions (filename suffix) for a format object

setExtensions(mixed $extensions)

Set the file format extensions (filename suffix) for a format object

setParserClass(string $class)

Set the parser to use for a format

string getParserClass()

Get the name of the class to use to parse the format

object newParser()

Create a new parser to parse this format

setSerialiserClass(string $class)

Set the serialiser to use for a format

string getSerialiserClass()

Get the name of the class to use to serialise the format

object newSerialiser()

Create a new serialiser to parse this format

string __toString()

Magic method to return the name of the format when casted to string

Details

at line 65
static public array getNames()

Get a list of format names

Return Value

array An array of formats name

at line 74
static public array getFormats()

Get a list of all the registered formats

Return Value

array An array of format objects

at line 92
static public string getHttpAcceptHeader(array $extraTypes = array())

Generates an HTTP Accept header string

The string will contain all of the MIME Types that we are able to parse.

It is also possible to specify additional MIME types in the form array('text/plain' => 0.5) where 0.5 is the q value for that type. The types are sorted by q value before constructing the string.

Parameters

array $extraTypes extra MIME types to add

Return Value

string list of supported MIME types

at line 121
static public boolean formatExists(string $name)

Check if a named graph exists

Parameters

string $name the name of the format

Return Value

boolean true if the format exists

at line 132
static public object getFormat(string $query)

Get a EasyRdf_Format from a name, uri or mime type

Parameters

string $query a query string to search for

Return Value

object the first EasyRdf_Format that matches the query

Exceptions

EasyRdf_Exception if no format is found

at line 164
static public object register(string $name, string $label = null, string $uri = null, string $mimeTypes = array(), string $extensions = array())

Register a new format

Parameters

string $name The name of the format (e.g. ntriples)
string $label The label for the format (e.g. N-Triples)
string $uri The URI for the format
string $mimeTypes One or more mime types for the format
string $extensions One or more extensions (file suffix)

Return Value

object The new EasyRdf_Format object

at line 192
static public unregister(string $name)

Remove a format from the registry

Parameters

string $name The name of the format (e.g. ntriples)

at line 202
static public registerParser(string $name, string $class)

Class method to register a parser class to a format name

Parameters

string $name The name of the format (e.g. ntriples)
string $class The name of the class (e.g. EasyRdfParserNtriples)

at line 215
static public registerSerialiser(string $name, string $class)

Class method to register a serialiser class to a format name

Parameters

string $name The name of the format (e.g. ntriples)
string $class The name of the class (e.g. EasyRdfSerialiserNtriples)

at line 233
static public object guessFormat(string $data, string $filename = null)

Attempt to guess the document format from some content.

If $filename is given, then the suffix is first used to guess the format.

If the document format is not recognised, null is returned.

Parameters

string $data The document data
string $filename Optional filename

Return Value

object EasyRdf_Format The format object

at line 279
public __construct(string $name)

This constructor is for internal use only.

To create a new format, use the register method.

Parameters

string $name The name of the format

See also

EasyRdf_Format::register()

at line 289
public string getName()

Get the name of a format object

Return Value

string The name of the format (e.g. rdfxml)

at line 298
public string getLabel()

Get the label for a format object

Return Value

string The format label (e.g. RDF/XML)

at line 307
public setLabel(string $label)

Set the label for a format object

Parameters

string $label The new label for the format

at line 325
public string getUri()

Get the URI for a format object

Return Value

string The format URI

at line 334
public setUri(string $uri)

Set the URI for a format object

Parameters

string $uri The new URI for the format

at line 352
public string getDefaultMimeType()

Get the default registered mime type for a format object

Return Value

string The default mime type as a string.

at line 365
public array getMimeTypes()

Get all the registered mime types for a format object

Return Value

array One or more MIME types in an array with the mime type as the key and q value as the value

at line 374
public setMimeTypes(array $mimeTypes)

Set the MIME Types for a format object

Parameters

array $mimeTypes One or more mime types

at line 390
public string getDefaultExtension()

Get the default registered file extension (filename suffix) for a format object

Return Value

string The default extension as a string.

at line 401
public array getExtensions()

Get all the registered file extensions (filename suffix) for a format object

Return Value

array One or more extensions as an array

at line 410
public setExtensions(mixed $extensions)

Set the file format extensions (filename suffix) for a format object

Parameters

mixed $extensions One or more file extensions

at line 426
public setParserClass(string $class)

Set the parser to use for a format

Parameters

string $class The name of the class

at line 444
public string getParserClass()

Get the name of the class to use to parse the format

Return Value

string The name of the class

at line 453
public object newParser()

Create a new parser to parse this format

Return Value

object The new parser object

at line 468
public setSerialiserClass(string $class)

Set the serialiser to use for a format

Parameters

string $class The name of the class

at line 486
public string getSerialiserClass()

Get the name of the class to use to serialise the format

Return Value

string The name of the class

at line 495
public object newSerialiser()

Create a new serialiser to parse this format

Return Value

object The new serialiser object

at line 510
public string __toString()

Magic method to return the name of the format when casted to string

Return Value

string The name of the format