]> BookStack Code Mirror - bookstack/blob - app/Http/Controllers/BookExportController.php
Apply fixes from StyleCI
[bookstack] / app / Http / Controllers / BookExportController.php
1 <?php
2
3 namespace BookStack\Http\Controllers;
4
5 use BookStack\Entities\Repos\BookRepo;
6 use BookStack\Entities\Tools\ExportFormatter;
7 use Throwable;
8
9 class BookExportController extends Controller
10 {
11     protected $bookRepo;
12     protected $exportFormatter;
13
14     /**
15      * BookExportController constructor.
16      */
17     public function __construct(BookRepo $bookRepo, ExportFormatter $exportFormatter)
18     {
19         $this->bookRepo = $bookRepo;
20         $this->exportFormatter = $exportFormatter;
21     }
22
23     /**
24      * Export a book as a PDF file.
25      *
26      * @throws Throwable
27      */
28     public function pdf(string $bookSlug)
29     {
30         $book = $this->bookRepo->getBySlug($bookSlug);
31         $pdfContent = $this->exportFormatter->bookToPdf($book);
32
33         return $this->downloadResponse($pdfContent, $bookSlug . '.pdf');
34     }
35
36     /**
37      * Export a book as a contained HTML file.
38      *
39      * @throws Throwable
40      */
41     public function html(string $bookSlug)
42     {
43         $book = $this->bookRepo->getBySlug($bookSlug);
44         $htmlContent = $this->exportFormatter->bookToContainedHtml($book);
45
46         return $this->downloadResponse($htmlContent, $bookSlug . '.html');
47     }
48
49     /**
50      * Export a book as a plain text file.
51      */
52     public function plainText(string $bookSlug)
53     {
54         $book = $this->bookRepo->getBySlug($bookSlug);
55         $textContent = $this->exportFormatter->bookToPlainText($book);
56
57         return $this->downloadResponse($textContent, $bookSlug . '.txt');
58     }
59
60     /**
61      * Export a book as a markdown file.
62      */
63     public function markdown(string $bookSlug)
64     {
65         $book = $this->bookRepo->getBySlug($bookSlug);
66         $textContent = $this->exportFormatter->bookToMarkdown($book);
67
68         return $this->downloadResponse($textContent, $bookSlug . '.md');
69     }
70 }