PHPExiftool\RDFParser::Query PHP Method

Query() public method

Returns the first result for a user defined query against the RDF
public Query ( string $query ) : PHPExiftool\Driver\Value\ValueInterface
$query string
return PHPExiftool\Driver\Value\ValueInterface The value
    public function Query($query)
    {
        $QueryParts = explode(':', $query);
        $DomXpath = $this->getDomXpath();
        if (!in_array($QueryParts[0], $this->registeredPrefixes)) {
            return null;
        }
        $nodes = $DomXpath->query('/rdf:RDF/rdf:Description/' . $query);
        if ($nodes instanceof \DOMNodeList && $nodes->length > 0) {
            return $this->readNodeValue($nodes->item(0));
        }
        return null;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * @covers PHPExiftool\RDFParser::Query
  * @covers PHPExiftool\RDFParser::readNodeValue
  */
 public function testQuery()
 {
     $xml = "<?xml version='1.0' encoding='UTF-8'?>\n            <rdf:RDF xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'>\n            <rdf:Description xmlns:NeutronSpace='http://ns.exiftool.ca/NeutronSpace/1.0/'>\n                <NeutronSpace:SpecialRomain>Hello World !</NeutronSpace:SpecialRomain>\n                <NeutronSpace:SpecialRomainbase64 rdf:datatype='http://www.w3.org/2001/XMLSchema#base64Binary'>SGVsbG8gYmFzZTY0ICE=</NeutronSpace:SpecialRomainbase64>\n                <NeutronSpace:Multi>\n                    <rdf:Bag>\n                        <rdf:li>romain</rdf:li>\n                        <rdf:li>neutron</rdf:li>\n                    </rdf:Bag>\n                </NeutronSpace:Multi>\n            </rdf:Description>\n            </rdf:RDF>";
     $this->object->open($xml);
     $metadata_simple = $this->object->Query('NeutronSpace:SpecialRomain');
     $metadata_base64 = $this->object->Query('NeutronSpace:SpecialRomainbase64');
     $metadata_multi = $this->object->Query('NeutronSpace:Multi');
     $null_datas = $this->object->Query('NeutronSpace:NoData');
     $null_datas_2 = $this->object->Query('NamespaceUnknown:NoData');
     $this->assertNull($null_datas);
     $this->assertNull($null_datas_2);
     $this->assertInstanceOf('\\PHPExiftool\\Driver\\Value\\Mono', $metadata_simple);
     $this->assertInstanceOf('\\PHPExiftool\\Driver\\Value\\Binary', $metadata_base64);
     $this->assertInstanceOf('\\PHPExiftool\\Driver\\Value\\Multi', $metadata_multi);
     $this->assertEquals('Hello World !', $metadata_simple->asString());
     $this->assertEquals('Hello base64 !', $metadata_base64->asString());
     $this->assertEquals(array('romain', 'neutron'), $metadata_multi->asArray());
 }
All Usage Examples Of PHPExiftool\RDFParser::Query