1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
|
4
|
|
|
namespace Nexendrie\Rss\Bridges\NetteDI; |
5
|
|
|
|
6
|
|
|
use Nette\DI\CompilerExtension; |
7
|
|
|
use Nexendrie\Rss\Generator; |
8
|
|
|
use Nette\Schema\Expect; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* RssExtension for Nette DI Container |
12
|
|
|
* |
13
|
|
|
* @author Jakub Konečný |
14
|
|
|
*/ |
15
|
1 |
|
final class RssExtension extends CompilerExtension { |
16
|
|
|
protected function setProperty(\Nette\DI\ServiceDefinition &$generator, \stdClass $config, string $property): void { |
17
|
1 |
|
if($config->$property !== "") { |
18
|
1 |
|
$generator->addSetup('$service->' . $property . " = ?", [$config->$property]); |
19
|
|
|
} |
20
|
1 |
|
} |
21
|
|
|
|
22
|
|
|
public function getConfigSchema(): \Nette\Schema\Schema { |
23
|
1 |
|
return Expect::structure([ |
24
|
1 |
|
"shortenDescription" => Expect::int(150), |
25
|
1 |
|
"dateTimeFormat" => Expect::string(""), |
26
|
1 |
|
"template" => Expect::string(""), |
27
|
|
|
]); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @throws \Nette\Utils\AssertionException |
32
|
|
|
*/ |
33
|
|
|
public function loadConfiguration(): void { |
34
|
|
|
/** @var \stdClass $config */ |
35
|
1 |
|
$config = $this->getConfig(); |
36
|
1 |
|
$builder = $this->getContainerBuilder(); |
37
|
1 |
|
$generator = $builder->addDefinition($this->prefix("generator")) |
38
|
1 |
|
->setType(Generator::class) |
39
|
1 |
|
->addSetup('$service->shortenDescription = ?', [$config->shortenDescription]); |
40
|
1 |
|
$this->setProperty($generator, $config, "dateTimeFormat"); |
41
|
1 |
|
$this->setProperty($generator, $config, "template"); |
42
|
1 |
|
} |
43
|
|
|
} |
44
|
|
|
?> |