XMPReader
Reader for XMP data containing properties relevant to images
Loading...
Searching...
No Matches
Wikimedia\XMPReader\Reader Class Reference

Class for reading xmp data containing properties relevant to images, and spitting out an array that FormatMetadata accepts. More...

+ Inheritance diagram for Wikimedia\XMPReader\Reader:
+ Collaboration diagram for Wikimedia\XMPReader\Reader:

Public Member Functions

 __construct (LoggerInterface $logger=null, $filename='unknown')
 Primary job is to initialize the XMLParser.
 
 getResults ()
 Get the result array.
 
 parse ( $content, $allOfIt=true)
 Main function to parse XMP.
 
 parseExtended ( $content)
 Entry point for XMPExtended blocks in jpeg files.
 
 char ( $parser, $data)
 Character data handler Called whenever character data is found in the xmp document.
 
 endElement ( $parser, $elm)
 Handler for hitting a closing element.
 
 startElement ( $parser, $elm, $attribs)
 Hits an opening element.
 

Static Public Member Functions

static isSupported ()
 Check if this instance supports using this class.
 

Public Attributes

const MODE_SIMPLE = 10
 
const MODE_STRUCT = 11
 
const MODE_SEQ = 12
 
const MODE_BAG = 13
 
const MODE_LANG = 14
 
const MODE_ALT = 15
 
const MODE_BAGSTRUCT = 16
 

Protected Attributes

array $items
 

Detailed Description

Class for reading xmp data containing properties relevant to images, and spitting out an array that FormatMetadata accepts.

Note, this is not meant to recognize every possible thing you can encode in XMP. It should recognize all the properties we want. For example, it doesn't have support for structures with multiple nesting levels, as none of the properties we're supporting use that feature. If it comes across properties it doesn't recognize, it should ignore them.

The public methods one would call in this class are

  • parse( $content ) Reads in xmp content. Can potentially be called multiple times with partial data each time.
  • parseExtended( $content ) Reads XMPExtended blocks (jpeg files only).
  • getResults Outputs a results array.

Note XMP kind of looks like rdf. They are not the same thing - XMP is encoded as a specific subset of rdf. This class can read XMP. It cannot read rdf.

Constructor & Destructor Documentation

◆ __construct()

Wikimedia\XMPReader\Reader::__construct ( LoggerInterface $logger = null,
$filename = 'unknown' )

Primary job is to initialize the XMLParser.

Parameters
LoggerInterface | null$loggerLogger instance if available
string$filename

Member Function Documentation

◆ char()

Wikimedia\XMPReader\Reader::char ( $parser,
$data )

Character data handler Called whenever character data is found in the xmp document.

does nothing if we're in MODE_IGNORE or if the data is whitespace throws an error if we're not in MODE_SIMPLE (as we're not allowed to have character data in the other modes).

As an example, this happens when we encounter XMP like: <exif:DigitalZoomRatio>0/10</exif:DigitalZoomRatio> and are processing the 0/10 bit.

Parameters
resource$parserXMLParser reference to the xml parser
string$dataCharacter data
Exceptions
RuntimeExceptionOn invalid data

◆ endElement()

Wikimedia\XMPReader\Reader::endElement ( $parser,
$elm )

Handler for hitting a closing element.

generally just calls a helper function depending on what mode we're in.

Ignores the outer wrapping elements that are optional in xmp and have no meaning.

Parameters
resource$parser
string$elmNamespace . ' ' . element name
Exceptions
RuntimeException

◆ getResults()

Wikimedia\XMPReader\Reader::getResults ( )

Get the result array.

Do some post-processing before returning the array, and transform any metadata that is special-cased.

Returns
array Array of results as an array of arrays suitable for FormatMetadata::getFormattedData().

◆ isSupported()

static Wikimedia\XMPReader\Reader::isSupported ( )
static

Check if this instance supports using this class.

Returns
bool

◆ parse()

string Buffer of XML to Wikimedia\XMPReader\Reader::parse ( $content,
$allOfIt = true )

Main function to parse XMP.

Use getResults to get results.

Also catches any errors during processing, writes them to debug log, blanks result array and returns false.

Parameters
string$contentXMP data
bool$allOfItIf this is all the data (true), or if it's split up (false). Default true
Exceptions
RuntimeException
Returns
bool Success.

◆ parseExtended()

Wikimedia\XMPReader\Reader::parseExtended ( $content)

Entry point for XMPExtended blocks in jpeg files.

Todo
In serious need of testing
See also
http://www.adobe.ge/devnet/xmp/pdfs/XMPSpecificationPart3.pdf XMP spec part 3 page 20
Parameters
string$contentXMPExtended block minus the namespace signature
Returns
bool If it succeeded.

◆ startElement()

Wikimedia\XMPReader\Reader::startElement ( $parser,
$elm,
$attribs )

Hits an opening element.

Generally just calls a helper based on what MODE we're in. Also does some initial set up for the wrapper element

Parameters
resource$parser
string$elmNamespace "<space>" element
array$attribsAttribute name => value
Exceptions
RuntimeException

The documentation for this class was generated from the following file: