class 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 string
formatAcceptHeader(array $accepted_types)

Convert array of types to Accept header value

static boolean
formatExists(string $name)

Check if a named graph exists

static Format
getFormat(string $query)

Get a EasyRdf\Format from a name, uri or mime type

static Format
register(string $name, string $label = null, string $uri = null, array|string $mimeTypes = array(), 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 Format
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

string|null
setLabel(string $label)

Set the label for a format object

string
getUri()

Get the URI for a format object

string|null
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(string|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 66
static array getNames()

Get a list of format names

Return Value

array An array of formats name

at line 75
static array getFormats()

Get a list of all the registered formats

Return Value

array An array of format objects

at line 94
static 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 111
static string formatAcceptHeader(array $accepted_types)

Convert array of types to Accept header value

Parameters

array $accepted_types

Return Value

string

at line 136
static 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 149
static Format 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

Format the first object that matches the query

Exceptions

InvalidArgumentException
Exception if no format is found

at line 183
static Format register(string $name, string $label = null, string $uri = null, array|string $mimeTypes = array(), 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
array|string $mimeTypes One or more mime types for the format
array|string $extensions One or more extensions (file suffix)

Return Value

Format New Format object

Exceptions

InvalidArgumentException

at line 211
static unregister(string $name)

Remove a format from the registry

Parameters

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

at line 221
static 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. EasyRdf\Parser\Ntriples)

at line 234
static 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. EasyRdf\Serialiser\Ntriples)

at line 253
static Format 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

Format New format object

at line 301
__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

Format::register

at line 311
string getName()

Get the name of a format object

Return Value

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

at line 320
string getLabel()

Get the label for a format object

Return Value

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

at line 332
string|null setLabel(string $label)

Set the label for a format object

Parameters

string $label The new label for the format

Return Value

string|null

Exceptions

InvalidArgumentException

at line 350
string getUri()

Get the URI for a format object

Return Value

string The format URI

at line 362
string|null setUri(string $uri)

Set the URI for a format object

Parameters

string $uri The new URI for the format

Return Value

string|null

Exceptions

InvalidArgumentException

at line 380
string getDefaultMimeType()

Get the default registered mime type for a format object

Return Value

string The default mime type as a string.

at line 393
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 402
setMimeTypes(string|array $mimeTypes)

Set the MIME Types for a format object

Parameters

string|array $mimeTypes One or more mime types

at line 418
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 429
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 438
setExtensions(mixed $extensions)

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

Parameters

mixed $extensions One or more file extensions

at line 456
setParserClass(string $class)

Set the parser to use for a format

Parameters

string $class The name of the class

Exceptions

InvalidArgumentException

at line 474
string getParserClass()

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

Return Value

string The name of the class

at line 484
object newParser()

Create a new parser to parse this format

Return Value

object The new parser object

Exceptions

Exception

at line 501
setSerialiserClass(string $class)

Set the serialiser to use for a format

Parameters

string $class The name of the class

Exceptions

InvalidArgumentException

at line 519
string getSerialiserClass()

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

Return Value

string The name of the class

at line 529
object newSerialiser()

Create a new serialiser to parse this format

Return Value

object The new serialiser object

Exceptions

Exception

at line 544
string __toString()

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

Return Value

string The name of the format