|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* This file is part of the trefoil application. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Miguel Angel Gabriel <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
|
|
11
|
|
|
namespace Trefoil\Providers; |
|
12
|
|
|
|
|
13
|
|
|
use Easybook\Publishers\HtmlChunkedPublisher; |
|
14
|
|
|
use Pimple\Container; |
|
15
|
|
|
use Pimple\ServiceProviderInterface; |
|
16
|
|
|
use Trefoil\Publishers\Epub2Publisher; |
|
17
|
|
|
use Trefoil\Publishers\HtmlPublisher; |
|
18
|
|
|
use Trefoil\Publishers\MobiPublisher; |
|
19
|
|
|
use Trefoil\Publishers\PdfPrinceXmlPublisher; |
|
20
|
|
|
use Trefoil\Publishers\PdfPublisher; |
|
21
|
|
|
use Trefoil\Publishers\PdfWkhtmltopdfPublisher; |
|
22
|
|
|
|
|
23
|
|
|
class PublisherServiceProvider implements ServiceProviderInterface |
|
24
|
|
|
{ |
|
25
|
34 |
|
public function register(Container $app) |
|
26
|
|
|
{ |
|
27
|
1 |
|
$app['publisher'] = |
|
28
|
34 |
|
function (Container $app) { |
|
29
|
34 |
|
$outputFormat = $app->edition('format'); |
|
30
|
|
|
|
|
31
|
34 |
|
switch (strtolower($outputFormat)) { |
|
32
|
34 |
|
case 'pdf': |
|
33
|
|
|
$pdfEngine = $app->edition('pdf_engine'); |
|
34
|
|
|
|
|
35
|
|
|
switch (strtolower($pdfEngine)) { |
|
36
|
|
|
case 'wkhtmltopdf': |
|
37
|
|
|
$publisher = new PdfWkhtmltopdfPublisher($app); |
|
38
|
|
|
break; |
|
39
|
|
|
|
|
40
|
|
|
// PrinceXML is the default |
|
41
|
|
|
case 'princexml': |
|
42
|
|
|
case '': |
|
43
|
|
|
case null: |
|
44
|
|
|
$publisher = new PdfPrinceXmlPublisher($app); |
|
45
|
|
|
break; |
|
46
|
|
|
|
|
47
|
|
|
default: |
|
48
|
|
|
throw new \RuntimeException( |
|
49
|
|
|
sprintf( |
|
50
|
|
|
'Unknown "%s" pdf_engine for "%s" edition (allowed: "PrinceXML" (default), "wkhtmltopdf")', |
|
51
|
|
|
$pdfEngine, |
|
52
|
|
|
$app['publishing.edition'] |
|
53
|
|
|
) |
|
54
|
|
|
); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
break; |
|
58
|
|
|
|
|
59
|
34 |
|
case 'html': |
|
60
|
|
|
$publisher = new HtmlPublisher($app); |
|
61
|
|
|
break; |
|
62
|
|
|
|
|
63
|
34 |
|
case 'html_chunked': |
|
64
|
|
|
$publisher = new HtmlChunkedPublisher($app); |
|
65
|
|
|
break; |
|
66
|
|
|
|
|
67
|
34 |
|
case 'epub': |
|
68
|
31 |
|
$publisher = new Epub2Publisher($app); |
|
69
|
31 |
|
break; |
|
70
|
|
|
|
|
71
|
3 |
|
case 'mobi': |
|
72
|
3 |
|
$publisher = new MobiPublisher($app); |
|
73
|
3 |
|
break; |
|
74
|
|
|
|
|
75
|
|
|
default: |
|
76
|
|
|
throw new \RuntimeException( |
|
77
|
|
|
sprintf( |
|
78
|
|
|
'Unknown "%s" format for "%s" edition (allowed: "pdf", "html", "html_chunked", "epub", "mobi")', |
|
79
|
|
|
$outputFormat, |
|
80
|
|
|
$app['publishing.edition'] |
|
81
|
|
|
) |
|
82
|
|
|
); |
|
83
|
34 |
|
} |
|
84
|
|
|
|
|
85
|
34 |
|
if (true !== $publisher->checkIfThisPublisherIsSupported()) { |
|
86
|
|
|
throw new \RuntimeException( |
|
87
|
|
|
sprintf( |
|
88
|
|
|
"Your system doesn't support publishing books with the '%s' format\n" |
|
89
|
|
|
. "Check the easybook documentation to know the dependencies required by this format.", |
|
90
|
|
|
$outputFormat |
|
91
|
|
|
) |
|
92
|
|
|
); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
34 |
|
return $publisher; |
|
96
|
|
|
}; |
|
97
|
1 |
|
} |
|
98
|
|
|
} |
|
99
|
|
|
|