1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of Cecil. |
5
|
|
|
* |
6
|
|
|
* (c) Arnaud Ligny <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace Cecil\Step\Pages; |
15
|
|
|
|
16
|
|
|
use Cecil\Generator\GeneratorManager; |
17
|
|
|
use Cecil\Step\AbstractStep; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Generate pages step. |
21
|
|
|
* |
22
|
|
|
* This step is responsible for generating pages based on the configured generators. |
23
|
|
|
* It initializes the generator manager with the generators defined in the configuration |
24
|
|
|
* and processes them to create the pages. The generated pages are then set in the builder. |
25
|
|
|
*/ |
26
|
|
|
class Generate extends AbstractStep |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* {@inheritdoc} |
30
|
|
|
*/ |
31
|
|
|
public function getName(): string |
32
|
|
|
{ |
33
|
|
|
return 'Generating pages'; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* {@inheritdoc} |
38
|
|
|
*/ |
39
|
|
|
public function init(array $options): void |
40
|
|
|
{ |
41
|
|
|
if (\count((array) $this->config->get('pages.generators')) > 0) { |
42
|
|
|
$this->canProcess = true; |
43
|
|
|
} |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
|
|
public function process(): void |
50
|
|
|
{ |
51
|
|
|
$generatorManager = new GeneratorManager($this->builder); |
52
|
|
|
$generators = (array) $this->config->get('pages.generators'); |
53
|
|
|
array_walk($generators, function ($generator, $priority) use ($generatorManager) { |
54
|
|
|
if (!class_exists($generator)) { |
55
|
|
|
$message = \sprintf('Unable to load generator "%s" (priority: %s).', $generator, $priority); |
56
|
|
|
$this->builder->getLogger()->error($message); |
57
|
|
|
|
58
|
|
|
return; |
59
|
|
|
} |
60
|
|
|
$generatorManager->addGenerator(new $generator($this->builder), $priority); |
61
|
|
|
}); |
62
|
|
|
$pages = $generatorManager->process(); |
63
|
|
|
$this->builder->setPages($pages); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|