|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace MyBuilder\Bundle\CronosBundle\DependencyInjection; |
|
4
|
|
|
|
|
5
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
6
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
|
7
|
|
|
use Symfony\Component\HttpKernel\Kernel; |
|
8
|
|
|
|
|
9
|
|
|
class Configuration implements ConfigurationInterface |
|
10
|
|
|
{ |
|
11
|
|
|
public function getConfigTreeBuilder(): TreeBuilder |
|
12
|
|
|
{ |
|
13
|
|
|
if (method_exists(TreeBuilder::class, 'getRootNode')) { |
|
14
|
|
|
// Symfony 4 |
|
15
|
|
|
$treeBuilder = new TreeBuilder('my_builder_cronos'); |
|
16
|
|
|
$rootNode = $treeBuilder->getRootNode(); |
|
17
|
|
|
} else { |
|
18
|
|
|
// Symfony 3 |
|
19
|
|
|
$treeBuilder = new TreeBuilder(); |
|
|
|
|
|
|
20
|
|
|
$rootNode = $treeBuilder->root('my_builder_cronos'); |
|
|
|
|
|
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
if (method_exists(Kernel::class, 'getProjectDir')) { |
|
24
|
|
|
// `kernel.project_dir` available since Symfony 3.3 |
|
25
|
|
|
$pathToConsole = '%kernel.project_dir%/bin/console'; |
|
26
|
|
|
} else { |
|
27
|
|
|
// `kernel.root_dir` dropped in Symfony 5 |
|
28
|
|
|
$pathToConsole = '%kernel.root_dir%/../bin/console'; |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
$rootNode |
|
32
|
|
|
->children() |
|
33
|
|
|
->arrayNode('exporter') |
|
34
|
|
|
->addDefaultsIfNotSet() |
|
35
|
|
|
->children() |
|
36
|
|
|
->scalarNode('key') |
|
37
|
|
|
->isRequired() |
|
38
|
|
|
->cannotBeEmpty() |
|
39
|
|
|
->info('Unique key that wraps all the cron configured for the current application.') |
|
40
|
|
|
->example('my_symfony_app') |
|
41
|
|
|
->end() |
|
42
|
|
|
->scalarNode('mailto') |
|
43
|
|
|
->cannotBeEmpty() |
|
44
|
|
|
->info('Sets the default email address for all cron output to go to.') |
|
45
|
|
|
->example('[email protected]') |
|
46
|
|
|
->end() |
|
47
|
|
|
->scalarNode('path') |
|
48
|
|
|
->example('/usr/local/bin:/usr/bin:/bin') |
|
49
|
|
|
->info('Sets the path for all commands in the crontab.') |
|
50
|
|
|
->end() |
|
51
|
|
|
->scalarNode('executor') |
|
52
|
|
|
->cannotBeEmpty() |
|
53
|
|
|
->defaultValue('php') |
|
54
|
|
|
->example('php') |
|
55
|
|
|
->info('Allows you to specify a program that all commands should be passed to such as "/usr/local/bin/php".') |
|
56
|
|
|
->end() |
|
57
|
|
|
->scalarNode('console') |
|
58
|
|
|
->cannotBeEmpty() |
|
59
|
|
|
->defaultValue($pathToConsole) |
|
60
|
|
|
->example('%kernel.project_dir%/bin/console') |
|
61
|
|
|
->info('Allows you to specify the console that all commands should be passed to such as "bin/console".') |
|
62
|
|
|
->end() |
|
63
|
|
|
->scalarNode('shell') |
|
64
|
|
|
->cannotBeEmpty() |
|
65
|
|
|
->example('/bin/sh') |
|
66
|
|
|
->info('Allows you to specify which shell each program should be run with.') |
|
67
|
|
|
->end() |
|
68
|
|
|
->scalarNode('timezone') |
|
69
|
|
|
->example('Europe/Paris') |
|
70
|
|
|
->info('Allows you to add CRON_TZ which specifies the time zone specific for the cron table.') |
|
71
|
|
|
->end() |
|
72
|
|
|
->end() |
|
73
|
|
|
->end() |
|
74
|
|
|
->end(); |
|
75
|
|
|
|
|
76
|
|
|
return $treeBuilder; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
This check looks for function calls that miss required arguments.