xref: /plugin/dw2pdf/src/CollectorFactory.php (revision 4c5691130dbf9035b960f10f5b3cb4b319a026d8)
12bef96e6SAndreas Gohr<?php
22bef96e6SAndreas Gohr
32bef96e6SAndreas Gohrnamespace dokuwiki\plugin\dw2pdf\src;
42bef96e6SAndreas Gohr
52bef96e6SAndreas Gohrclass CollectorFactory
62bef96e6SAndreas Gohr{
72bef96e6SAndreas Gohr    /**
82bef96e6SAndreas Gohr     * Returns the appropriate collector for the given export event
92bef96e6SAndreas Gohr     *
102bef96e6SAndreas Gohr     * @param string $event The name of the export event
11decfd8d6SAndreas Gohr     * @param Config $config Combined plugin and request configuration
122bef96e6SAndreas Gohr     * @param int|null $rev A specific revision to export
132bef96e6SAndreas Gohr     * @param int|null $at A specific dateat timestamp to export
14*4c569113SAndreas Gohr     * @throws ExportException If a book export is requested without a selection
152bef96e6SAndreas Gohr     * @throws \InvalidArgumentException If the event is not recognized
162bef96e6SAndreas Gohr     * @return AbstractCollector
172bef96e6SAndreas Gohr     */
185340eaffSAndreas Gohr    public static function create(string $event, Config $config, ?int $rev, ?int $at)
192bef96e6SAndreas Gohr    {
202bef96e6SAndreas Gohr        switch ($event) {
21f77f381aSAndreas Gohr            case 'export_pdf':
22decfd8d6SAndreas Gohr                return new PageCollector($config, $rev, $at);
232bef96e6SAndreas Gohr            case 'export_pdfns':
24decfd8d6SAndreas Gohr                return new NamespaceCollector($config, $rev, $at); // $at would make sense but is not supported yet
252bef96e6SAndreas Gohr            case 'export_pdfbook':
26decfd8d6SAndreas Gohr                if ($config->hasLiveSelection()) {
27decfd8d6SAndreas Gohr                    return new BookCreatorLiveSelectionCollector($config, $rev, $at);
28decfd8d6SAndreas Gohr                } elseif ($config->hasSavedSelection()) {
29decfd8d6SAndreas Gohr                    return new BookCreatorSavedSelectionCollector($config, $rev, $at);
302bef96e6SAndreas Gohr                }
31*4c569113SAndreas Gohr                throw new ExportException('empty'); // book export without a selection
322bef96e6SAndreas Gohr            default:
332bef96e6SAndreas Gohr                throw new \InvalidArgumentException('Invalid export configuration');
342bef96e6SAndreas Gohr        }
352bef96e6SAndreas Gohr    }
362bef96e6SAndreas Gohr}
37