From ac24567c41bba5d45e9ca6b89b51151af2f74427 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maur=C3=ADcio=20Meneghini=20Fauth?= Date: Sat, 10 Dec 2022 16:24:56 -0300 Subject: [PATCH] Extract method to get TCPDF producer MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Wraps TCPDF_STATIC::getTCPDFProducer() calls with a private method and adds an empty private property that can be used to change the producer line. The private property can be changed with the reflection API. Both method and property are declared as private to avoid BC breaks. The idea is to help with testing PDF generation, by using a predictable producer line. Signed-off-by: MaurĂ­cio Meneghini Fauth --- tcpdf.php | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/tcpdf.php b/tcpdf.php index aa052829..96e39ffc 100644 --- a/tcpdf.php +++ b/tcpdf.php @@ -514,6 +514,13 @@ class TCPDF { */ protected $creator = ''; + /** + * Document producer. + * @private + * @var string + */ + private $_TCPDFProducer = ''; + /** * Starting page number. * @protected @@ -9569,7 +9576,7 @@ protected function _putinfo() { // restore previous isunicode value $this->isunicode = $prev_isunicode; // default producer - $out .= ' /Producer '.$this->_textstring(TCPDF_STATIC::getTCPDFProducer(), $oid); + $out .= ' /Producer '.$this->_textstring($this->_getTCPDFProducer(), $oid); // The date and time the document was created, in human-readable form $out .= ' /CreationDate '.$this->_datestring(0, $this->doc_creation_timestamp); // The date and time the document was most recently modified, in human-readable form @@ -9664,7 +9671,7 @@ protected function _putXMP() { $xmp .= "\t\t".''."\n"; $xmp .= "\t\t".''."\n"; $xmp .= "\t\t\t".''.TCPDF_STATIC::_escapeXML($this->keywords).''."\n"; - $xmp .= "\t\t\t".''.TCPDF_STATIC::_escapeXML(TCPDF_STATIC::getTCPDFProducer()).''."\n"; + $xmp .= "\t\t\t".''.TCPDF_STATIC::_escapeXML($this->_getTCPDFProducer()).''."\n"; $xmp .= "\t\t".''."\n"; $xmp .= "\t\t".''."\n"; $uuid = 'uuid:'.substr($this->file_id, 0, 8).'-'.substr($this->file_id, 8, 4).'-'.substr($this->file_id, 12, 4).'-'.substr($this->file_id, 16, 4).'-'.substr($this->file_id, 20, 12); @@ -24734,6 +24741,20 @@ protected function fileExists($file) return TCPDF_STATIC::file_exists($file); } + /** + * Return the current TCPDF producer. + * @return string TCPDF producer string + * @private + */ + private function _getTCPDFProducer() + { + if (!TCPDF_STATIC::empty_string($this->_TCPDFProducer)) { + return $this->_TCPDFProducer; + } + + return TCPDF_STATIC::getTCPDFProducer(); + } + } // END OF TCPDF CLASS //============================================================+