pdfparser
pdfparser copied to clipboard
Why return an object ElementMissing instead of throwing an ElementMissingException?
I am debugging an "Missing encoding data for: """ and I noticed something that maybe is wrong...
Should Header->get($name) return an object of ElementMissing instead of throwing something like ElementMissingException?
/**
* @param string $name
*
* @return Element|PDFObject
*/
public function get($name)
{
if (\array_key_exists($name, $this->elements)) {
return $this->resolveXRef($name);
}
return new ElementMissing();
}
An Exception would halt the parsing process completely (or would have to be caught and handled by other methods), meaning that no content could be parsed from corrupted/invalid files at all. ElementMissing() will provide the information that something's not quite right while still allowing for the rest of the content to be parsed.
Are you running into Missing encoding data for: "" as a direct result of encountering an ElementMissing()? If that is the case, a check should be implemented for that case instead of throwing the EncodingNotFoundException.
Maybe it would be better to introduce some modes? For example in "quiet" mode it should ignore all errors, missing elements e.t.c. But in "strict" mode it will thown exception on every error. So "strict" mode could be used to check if pdf-file is fully сompatible with this project.
Or implement mode mask to have bits to ignore one types of errors but throw an error for others.
Injecting PSR-3 Logger Interface can help to understend what really happens during parsing pdf-file.
Sounds like a good idea, so +1 from me, but I don't have the time right now to contribute anything to it, unfortunately.