Skip to content

Commit

Permalink
feat: allow any type of processor classes (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
Cruiser13 committed Dec 21, 2023
1 parent 70b7474 commit 8fd0e3e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
2 changes: 2 additions & 0 deletions doc/01_Doc_Types_and_Available_Processors.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ This bundle introduces 2 new document types:
| [PDF Reactor](https://www.pdfreactor.com/) | A REST/SOAP solution, please visit the official website for further information |

> For details on how to install and configure these processors, please see [Additional Tools Installation](https://pimcore.com/docs/platform/Pimcore/Installation_and_Upgrade/System_Setup_and_Hosting/Additional_Tools_Installation) page in the Core.
You can also add your own Processors as long as they extend the abstract Pimcore\Bundle\WebToPrintBundle\Processor class. Set the full class name in the web2print settings, for example "App\Web2Print\Processor\WkHtmlToPdf".
2 changes: 1 addition & 1 deletion public/js/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ pimcore.bundle.web2print.settings = Class.create({
fieldLabel: t("web2print_tool"),
xtype: "combo",
width: 600,
editable: false,
editable: true,
name: "generalTool",
value: this.getValue("generalTool"),
store: [
Expand Down
25 changes: 19 additions & 6 deletions src/Processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,25 @@ public static function getInstance(): PdfReactor|Gotenberg|Chromium|Processor
{
$config = Config::getWeb2PrintConfig();

return match ($config['generalTool']) {
'pdfreactor' => new PdfReactor(),
'chromium' => new Chromium(),
'gotenberg' => new Gotenberg(),
default => throw new \Exception('Invalid Configuration - ' . $config['generalTool'])
};
if($config['generalTool'] == 'pdfreactor'){
return new PdfReactor();
}
elseif($config['generalTool'] == 'chromium'){
return new Chromium();
}
elseif($config['generalTool'] == 'gotenberg'){
return new Gotenberg();
}
else{
if(class_exists($config['generalTool'])){
$generalToolClass = new $config['generalTool']();
if($generalToolClass instanceof Processor){
return $generalToolClass;
}
}
}

throw new \Exception('Invalid Configuration - ' . $config['generalTool']);
}

/**
Expand Down

0 comments on commit 8fd0e3e

Please sign in to comment.