Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add decorator infrastructure for plugins #1519

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/Dompdf.php
Expand Up @@ -67,7 +67,7 @@
*
* @package dompdf
*/
class Dompdf
class Dompdf implements DompdfInterface
{
/**
* Version string for dompdf
Expand Down Expand Up @@ -1484,6 +1484,14 @@ public function getFontMetrics()
return $this->fontMetrics;
}

/**
* @return FontMetrics
*/
public function copy()
{
return new static($this->getOptions());
}

/**
* PHP5 overloaded getter
* Along with {@link Dompdf::__set()} __get() provides access to all
Expand Down
46 changes: 46 additions & 0 deletions src/DompdfDecorator.php
@@ -0,0 +1,46 @@
<?php
/**
* @package dompdf
* @link http://dompdf.github.com/
* @author Benj Carson <benjcarson@digitaljunkies.ca>
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
namespace Dompdf;

abstract class DompdfDecorator implements DompdfInterface
{
/**
* @var DompdfInterface
*/
protected $pdf;

public function __construct( DompdfInterface $pdf ) {
$this->pdf = $pdf;
}

public function getOptions() {
return $this->pdf->getOptions();
}

public function getDom() {
return $this->pdf->getDom();
}

public function render() {
$this->pdf->render();
}

public function output( $options = null ) {
return $this->pdf->output($options);
}

public function loadHtml( $html, $encoding = 'UTF-8' ) {
$this->pdf->loadHtml($html, $encoding);
}

public function copy() {
$this->pdf = $this->pdf->copy();
return $this;
}

}
44 changes: 44 additions & 0 deletions src/DompdfInterface.php
@@ -0,0 +1,44 @@
<?php
/**
* @package dompdf
* @link http://dompdf.github.com/
* @author Benj Carson <benjcarson@digitaljunkies.ca>
* @license http://www.gnu.org/copyleft/lesser.html GNU Lesser General Public License
*/
namespace Dompdf;

use DOMDocument;

interface DompdfInterface
{
/**
* @return Options
*/
public function getOptions();

/**
* @return DOMDocument
*/
public function getDom();

/**
* @return void
*/
public function render();

/**
* @return string
*/
public function output( $options = null );

/**
* @return void
*/
public function loadHtml( $str, $encoding = 'UTF-8' );

/**
* @return DompdfInterface
*/
public function copy();

}