|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace MartinGeorgiev\SocialPost\DependencyInjection; |
|
6
|
|
|
|
|
7
|
|
|
use Symfony\Component\Config\Definition\Builder\ArrayNodeDefinition; |
|
8
|
|
|
use Symfony\Component\Config\Definition\Builder\TreeBuilder; |
|
9
|
|
|
use Symfony\Component\Config\Definition\ConfigurationInterface; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @since 1.0.0 |
|
13
|
|
|
* @author Martin Georgiev <[email protected]> |
|
14
|
|
|
* @license https://opensource.org/licenses/MIT MIT |
|
15
|
|
|
* @link https://github.com/martin-georgiev/social-post-bundle Package's homepage |
|
16
|
|
|
*/ |
|
17
|
|
|
class Configuration implements ConfigurationInterface |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* {@inheritdoc} |
|
21
|
|
|
*/ |
|
22
|
|
|
public function getConfigTreeBuilder() |
|
23
|
|
|
{ |
|
24
|
|
|
$treeBuilder = new TreeBuilder(); |
|
25
|
|
|
$rootNode = $treeBuilder->root('social_post'); |
|
26
|
|
|
|
|
27
|
|
|
$rootNode |
|
28
|
|
|
->children() |
|
29
|
|
|
->arrayNode('publish_on') |
|
30
|
|
|
->requiresAtLeastOneElement() |
|
31
|
|
|
->prototype('enum') |
|
32
|
|
|
->values(['facebook', 'linkedin', 'twitter']) |
|
33
|
|
|
->end() |
|
34
|
|
|
->end() |
|
35
|
|
|
->end(); |
|
36
|
|
|
|
|
37
|
|
|
$providers = $rootNode->children()->arrayNode('providers'); |
|
38
|
|
|
$this->addFacebook($providers); |
|
39
|
|
|
$this->addLinkedIn($providers); |
|
40
|
|
|
$this->addTwitter($providers); |
|
41
|
|
|
|
|
42
|
|
|
return $treeBuilder; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @param ArrayNodeDefinition $node |
|
47
|
|
|
*/ |
|
48
|
|
|
private function addFacebook(ArrayNodeDefinition $node) |
|
49
|
|
|
{ |
|
50
|
|
|
$node |
|
51
|
|
|
->children() |
|
52
|
|
|
->arrayNode('facebook') |
|
53
|
|
|
->children() |
|
54
|
|
|
->scalarNode('app_id') |
|
55
|
|
|
->isRequired() |
|
56
|
|
|
->cannotBeEmpty() |
|
57
|
|
|
->end() |
|
58
|
|
|
->scalarNode('app_secret') |
|
59
|
|
|
->isRequired() |
|
60
|
|
|
->cannotBeEmpty() |
|
61
|
|
|
->end() |
|
62
|
|
|
->scalarNode('default_access_token') |
|
63
|
|
|
->isRequired() |
|
64
|
|
|
->cannotBeEmpty() |
|
65
|
|
|
->end() |
|
66
|
|
|
->scalarNode('page_id') |
|
67
|
|
|
->isRequired() |
|
68
|
|
|
->cannotBeEmpty() |
|
69
|
|
|
->end() |
|
70
|
|
|
->booleanNode('enable_beta_mode') |
|
71
|
|
|
->defaultFalse() |
|
72
|
|
|
->end() |
|
73
|
|
|
->scalarNode('default_graph_version') |
|
74
|
|
|
->defaultNull() |
|
75
|
|
|
->end() |
|
76
|
|
|
->enumNode('persistent_data_handler') |
|
77
|
|
|
->values(['session', 'memory']) |
|
78
|
|
|
->defaultValue('memory') |
|
79
|
|
|
->end() |
|
80
|
|
|
->enumNode('pseudo_random_string_generator') |
|
81
|
|
|
->values(['mcrypt', 'openssl', 'urandom']) |
|
82
|
|
|
->defaultValue('openssl') |
|
83
|
|
|
->end() |
|
84
|
|
|
->enumNode('http_client_handler') |
|
85
|
|
|
->values(['curl', 'stream', 'guzzle']) |
|
86
|
|
|
->defaultValue('curl') |
|
87
|
|
|
->end() |
|
88
|
|
|
->end() |
|
89
|
|
|
->end(); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @param ArrayNodeDefinition $node |
|
94
|
|
|
*/ |
|
95
|
|
|
private function addLinkedIn(ArrayNodeDefinition $node) |
|
96
|
|
|
{ |
|
97
|
|
|
$node |
|
98
|
|
|
->children() |
|
99
|
|
|
->arrayNode('linkedin') |
|
100
|
|
|
->children() |
|
101
|
|
|
->scalarNode('client_id') |
|
102
|
|
|
->isRequired() |
|
103
|
|
|
->cannotBeEmpty() |
|
104
|
|
|
->end() |
|
105
|
|
|
->scalarNode('client_secret') |
|
106
|
|
|
->isRequired() |
|
107
|
|
|
->cannotBeEmpty() |
|
108
|
|
|
->end() |
|
109
|
|
|
->scalarNode('access_token') |
|
110
|
|
|
->isRequired() |
|
111
|
|
|
->cannotBeEmpty() |
|
112
|
|
|
->end() |
|
113
|
|
|
->scalarNode('company_page_id') |
|
114
|
|
|
->isRequired() |
|
115
|
|
|
->cannotBeEmpty() |
|
116
|
|
|
->end() |
|
117
|
|
|
->end() |
|
118
|
|
|
->end(); |
|
119
|
|
|
} |
|
120
|
|
|
|
|
121
|
|
|
/** |
|
122
|
|
|
* @param ArrayNodeDefinition $node |
|
123
|
|
|
*/ |
|
124
|
|
|
private function addTwitter(ArrayNodeDefinition $node) |
|
125
|
|
|
{ |
|
126
|
|
|
$node |
|
127
|
|
|
->children() |
|
128
|
|
|
->arrayNode('twitter') |
|
129
|
|
|
->children() |
|
130
|
|
|
->scalarNode('consumer_key') |
|
131
|
|
|
->isRequired() |
|
132
|
|
|
->cannotBeEmpty() |
|
133
|
|
|
->end() |
|
134
|
|
|
->scalarNode('consumer_secret') |
|
135
|
|
|
->isRequired() |
|
136
|
|
|
->cannotBeEmpty() |
|
137
|
|
|
->end() |
|
138
|
|
|
->scalarNode('access_token') |
|
139
|
|
|
->isRequired() |
|
140
|
|
|
->cannotBeEmpty() |
|
141
|
|
|
->end() |
|
142
|
|
|
->scalarNode('access_token_secret') |
|
143
|
|
|
->isRequired() |
|
144
|
|
|
->cannotBeEmpty() |
|
145
|
|
|
->end() |
|
146
|
|
|
->end() |
|
147
|
|
|
->end(); |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
|