xref: /plugin/dw2pdf/src/CollectorFactory.php (revision 4c5691130dbf9035b960f10f5b3cb4b319a026d8)
1<?php
2
3namespace dokuwiki\plugin\dw2pdf\src;
4
5class CollectorFactory
6{
7    /**
8     * Returns the appropriate collector for the given export event
9     *
10     * @param string $event The name of the export event
11     * @param Config $config Combined plugin and request configuration
12     * @param int|null $rev A specific revision to export
13     * @param int|null $at A specific dateat timestamp to export
14     * @throws ExportException If a book export is requested without a selection
15     * @throws \InvalidArgumentException If the event is not recognized
16     * @return AbstractCollector
17     */
18    public static function create(string $event, Config $config, ?int $rev, ?int $at)
19    {
20        switch ($event) {
21            case 'export_pdf':
22                return new PageCollector($config, $rev, $at);
23            case 'export_pdfns':
24                return new NamespaceCollector($config, $rev, $at); // $at would make sense but is not supported yet
25            case 'export_pdfbook':
26                if ($config->hasLiveSelection()) {
27                    return new BookCreatorLiveSelectionCollector($config, $rev, $at);
28                } elseif ($config->hasSavedSelection()) {
29                    return new BookCreatorSavedSelectionCollector($config, $rev, $at);
30                }
31                throw new ExportException('empty'); // book export without a selection
32            default:
33                throw new \InvalidArgumentException('Invalid export configuration');
34        }
35    }
36}
37