-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTree.php
More file actions
119 lines (103 loc) · 3.97 KB
/
Tree.php
File metadata and controls
119 lines (103 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
/**
* (c) Bureau Pieper <piet@bureaupieper.nl>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Bureaupieper\StoreeClient\Resources;
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
class ConfigTree
{
static function get($platform = null)
{
$isSymfony = $platform == 'symfony';
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('bureaupieper_storee', 'array');
$root = $rootNode->children();
$root->scalarNode('endpoint')
->defaultValue('https://store-e.nl/api')
->cannotBeEmpty()
->validate()
->ifTrue(function($v) { return !preg_match('/^https?:\/\//', $v); })
->thenInvalid('Endpoint not http')
->end()
->end();
$root->scalarNode('apikey')
->isRequired()
->validate()
->ifTrue(function($v) { return !$v; })
->thenInvalid('Cannot be the empty string')
->end()
->end();
$root->scalarNode('version')
->isRequired()
->validate()
->ifTrue(function($v) { return !preg_match('/^[1-9][0-9]*$/', $v); })
->thenInvalid('Version not numeric')
->end()
->cannotBeEmpty()
->end();
$root->scalarNode('platform')
->cannotBeEmpty()
->isRequired()
->validate()
->ifTrue(function($v) { return !is_string($v); })
->thenInvalid('Platform not a string')
->end()
->end();
$root->scalarNode('format')
->defaultValue('json')
->validate()
->ifNotInArray(array('json', 'xml'))
->thenInvalid('Invalid format "%s"')
->end()
->cannotBeEmpty()
->end();
if ($isSymfony) {
$root->scalarNode('guzzle')
->defaultNull()
->end();
}
$logging = $root->arrayNode('logs')->canBeEnabled()->addDefaultsIfNotSet()->children();
if ($isSymfony) {
$logging->scalarNode('service')
->defaultNull()
->end();
}
$defaults = $logging->arrayNode('default_driver')->canBeDisabled()->addDefaultsIfNotSet()->children();
$defaults->scalarNode('path')
->defaultValue($isSymfony ? '%kernel.logs_dir%' : __DIR__ . '/../var/cache')
->cannotBeEmpty()
->end();
$mail = $defaults->arrayNode('mail')->canBeEnabled()->addDefaultsIfNotSet()->children();
$mail->scalarNode('to')
->cannotBeEmpty()
->isRequired()
->end();
$mail->scalarNode('subject')
->cannotBeEmpty()
->isRequired()
->end();
$mail->scalarNode('from')
->cannotBeEmpty()
->isRequired()
->end();
$cache = $root->arrayNode('cache')->canBeEnabled()->addDefaultsIfNotSet()->children();
$cache->integerNode('ttr')
->defaultValue(10 * 60)
->cannotBeEmpty()
->end();
if ($isSymfony) {
$cache->scalarNode('service')
->defaultNull()
->end();
}
$defaults = $cache->arrayNode('default_driver')->canBeDisabled()->addDefaultsIfNotSet()->children();
$defaults->scalarNode('path')
->defaultValue($isSymfony ? '%kernel.cache_dir%' : __DIR__ . '/../../var/cache')
->cannotBeEmpty()
->end();
return $treeBuilder;
}
}