Skip to content

Commit

Permalink
log tagname to classname
Browse files Browse the repository at this point in the history
  • Loading branch information
jygaulier committed Mar 23, 2023
1 parent 6bbecc9 commit 4e42676
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
22 changes: 16 additions & 6 deletions lib/PHPExiftool/Driver/TagGroupFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PHPExiftool\Exception\TagUnknown;
use PHPExiftool\InformationDumper;
use PHPExiftool\Tool\Command\ClassesBuilder;
use Psr\Log\LoggerInterface;

/**
* Metadata Object for mapping a TagGroup to a value
Expand All @@ -27,16 +28,21 @@ class TagGroupFactory
/**
* Build a TagGroup object based on his id
*
* @param string $tagname
* @param string $tagname
* @param LoggerInterface|null $logger
* @return TagGroupInterface
* @throws TagUnknown
*/
public static function getFromRDFTagname(string $tagname): TagGroupInterface
public static function getFromRDFTagname(string $tagname, ?LoggerInterface $logger = null): TagGroupInterface
{
$classname = static::classnameFromRDFTagname($tagname);
$classname = static::classnameFromRDFTagname($tagname, $logger);

if($logger) {
$logger->debug(sprintf("classnameFromRDFTagname(\"%s\") ==> \"%s\"", $tagname, $classname));
}

if ( ! class_exists($classname)) {
throw new TagUnknown(sprintf('Unknown tag %s', $tagname));
throw new TagUnknown(sprintf("Unknown tag \"%s\" (class \"%s\" not found)", $tagname, $classname));
}

return new $classname;
Expand All @@ -47,11 +53,15 @@ public static function hasFromRDFTagname(string $tagname): bool
return class_exists(static::classnameFromRDFTagname($tagname));
}

protected static function classnameFromRDFTagname(string $RdfName): string
protected static function classnameFromRDFTagname(string $RdfName, ?LoggerInterface $logger = null): string
{
$id = str_replace('/rdf:RDF/rdf:Description/', '', $RdfName);
$FQClassname = InformationDumper::tagGroupIdToFQClassname($id);

if($logger) {
$logger->debug(sprintf("tag id(\"%s\") ==> \"%s\" ; tagGroupIdToFQClassname(\"%s\") ==> \"%s\" ", $RdfName, $id, $id, $FQClassname));
}

return '\\PHPExiftool\\Driver\\TagGroup\\' . InformationDumper::tagGroupIdToFQClassname($id);
}

}
4 changes: 2 additions & 2 deletions lib/PHPExiftool/RDFParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public function ParseMetadatas(): MetadataBag
$this->logger->debug(sprintf(" -> found node \"%s\" line %d -> tagname = \"%s\"", $node->nodeName, $node->getLineNo(), $tagname));

try {
$tagGroup = TagGroupFactory::getFromRDFTagname($tagname);
$tagGroup = TagGroupFactory::getFromRDFTagname($tagname, $this->logger);
$this->logger->debug(sprintf(" -> tagGroup class = \"%s\"", get_class($tagGroup)));
assert(get_class($tagGroup) === "PHPExiftool\\Driver\\TagGroupInterface");
}
Expand Down Expand Up @@ -275,7 +275,7 @@ protected function readNodeValue(DOMElement $node, ?TagGroupInterface $tagGroup
$nodeName = $this->normalize($node->nodeName);

if (is_null($tagGroup) && TagGroupFactory::hasFromRDFTagname($nodeName)) {
$tagGroup = TagGroupFactory::getFromRDFTagname($nodeName);
$tagGroup = TagGroupFactory::getFromRDFTagname($nodeName, $this->logger);
}

if ($node->getElementsByTagNameNS(self::RDF_NAMESPACE, 'Bag')->length > 0) {
Expand Down

0 comments on commit 4e42676

Please sign in to comment.