|
1
|
|
|
<?php |
|
2
|
|
|
namespace Bookdown\Bookdown\Process\Rendering; |
|
3
|
|
|
|
|
4
|
|
|
use Psr\Log\LoggerInterface; |
|
5
|
|
|
use Aura\Html\HelperLocatorFactory; |
|
6
|
|
|
use Aura\View\View; |
|
7
|
|
|
use Aura\View\ViewFactory; |
|
8
|
|
|
use Bookdown\Bookdown\Config\RootConfig; |
|
9
|
|
|
use Bookdown\Bookdown\Exception; |
|
10
|
|
|
use Bookdown\Bookdown\Fsio; |
|
11
|
|
|
use Bookdown\Bookdown\Process\ProcessBuilderInterface; |
|
12
|
|
|
|
|
13
|
|
|
class RenderingProcessBuilder implements ProcessBuilderInterface |
|
14
|
|
|
{ |
|
15
|
3 |
|
public function newInstance(RootConfig $config, LoggerInterface $logger, Fsio $fsio) |
|
16
|
|
|
{ |
|
17
|
3 |
|
return new RenderingProcess( |
|
18
|
3 |
|
$logger, |
|
19
|
3 |
|
$fsio, |
|
20
|
3 |
|
$this->newView($config) |
|
21
|
3 |
|
); |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
3 |
|
protected function newView(RootConfig $config) |
|
25
|
|
|
{ |
|
26
|
3 |
|
$helpersFactory = new HelperLocatorFactory(); |
|
27
|
3 |
|
$helpers = $helpersFactory->newInstance(); |
|
28
|
|
|
|
|
29
|
3 |
|
$viewFactory = new ViewFactory(); |
|
30
|
3 |
|
$view = $viewFactory->newInstance($helpers); |
|
31
|
|
|
|
|
32
|
3 |
|
$this->setTemplate($view, $config); |
|
33
|
|
|
|
|
34
|
3 |
|
return $view; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
3 |
|
protected function setTemplate(View $view, RootConfig $config) |
|
38
|
|
|
{ |
|
39
|
3 |
|
$template = $config->getTemplate(); |
|
40
|
3 |
|
if (! $template) { |
|
41
|
3 |
|
$template = dirname(dirname(dirname(__DIR__))) . '/templates/main.php'; |
|
42
|
3 |
|
} |
|
43
|
|
|
|
|
44
|
3 |
|
if (! file_exists($template) && ! is_readable($template)) { |
|
45
|
|
|
throw new Exception("Cannot find template '$template'."); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
3 |
|
$registry = $view->getViewRegistry(); |
|
49
|
3 |
|
$registry->set('__BOOKDOWN__', $template); |
|
50
|
|
|
|
|
51
|
3 |
|
$view->setView('__BOOKDOWN__'); |
|
52
|
3 |
|
} |
|
53
|
|
|
} |
|
54
|
|
|
|