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', 'twitter']) |
33
|
|
|
->end() |
34
|
|
|
->end() |
35
|
|
|
->end(); |
36
|
|
|
|
37
|
|
|
$providers = $rootNode->children()->arrayNode('providers'); |
38
|
|
|
$this->addFacebook($providers); |
39
|
|
|
$this->addTwitter($providers); |
40
|
|
|
|
41
|
|
|
return $treeBuilder; |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @param ArrayNodeDefinition $node |
46
|
|
|
*/ |
47
|
|
|
private function addFacebook(ArrayNodeDefinition $node) |
48
|
|
|
{ |
49
|
|
|
$node |
50
|
|
|
->children() |
51
|
|
|
->arrayNode('facebook') |
52
|
|
|
->children() |
53
|
|
|
->scalarNode('app_id') |
54
|
|
|
->isRequired() |
55
|
|
|
->cannotBeEmpty() |
56
|
|
|
->end() |
57
|
|
|
->scalarNode('app_secret') |
58
|
|
|
->isRequired() |
59
|
|
|
->cannotBeEmpty() |
60
|
|
|
->end() |
61
|
|
|
->scalarNode('default_access_token') |
62
|
|
|
->isRequired() |
63
|
|
|
->cannotBeEmpty() |
64
|
|
|
->end() |
65
|
|
|
->scalarNode('page_id') |
66
|
|
|
->isRequired() |
67
|
|
|
->cannotBeEmpty() |
68
|
|
|
->end() |
69
|
|
|
->booleanNode('enable_beta_mode') |
70
|
|
|
->defaultFalse() |
71
|
|
|
->end() |
72
|
|
|
->scalarNode('default_graph_version') |
73
|
|
|
->defaultNull() |
74
|
|
|
->end() |
75
|
|
|
->enumNode('persistent_data_handler') |
76
|
|
|
->values(['session', 'memory']) |
77
|
|
|
->defaultValue('memory') |
78
|
|
|
->end() |
79
|
|
|
->enumNode('pseudo_random_string_generator') |
80
|
|
|
->values(['mcrypt', 'openssl', 'urandom']) |
81
|
|
|
->defaultValue('openssl') |
82
|
|
|
->end() |
83
|
|
|
->enumNode('http_client_handler') |
84
|
|
|
->values(['curl', 'stream', 'guzzle']) |
85
|
|
|
->defaultValue('curl') |
86
|
|
|
->end() |
87
|
|
|
->end() |
88
|
|
|
->end(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @param ArrayNodeDefinition $node |
93
|
|
|
*/ |
94
|
|
|
private function addTwitter(ArrayNodeDefinition $node) |
95
|
|
|
{ |
96
|
|
|
$node |
97
|
|
|
->children() |
98
|
|
|
->arrayNode('twitter') |
99
|
|
|
->children() |
100
|
|
|
->scalarNode('consumer_key') |
101
|
|
|
->isRequired() |
102
|
|
|
->cannotBeEmpty() |
103
|
|
|
->end() |
104
|
|
|
->scalarNode('consumer_secret') |
105
|
|
|
->isRequired() |
106
|
|
|
->cannotBeEmpty() |
107
|
|
|
->end() |
108
|
|
|
->scalarNode('access_token') |
109
|
|
|
->isRequired() |
110
|
|
|
->cannotBeEmpty() |
111
|
|
|
->end() |
112
|
|
|
->scalarNode('access_token_secret') |
113
|
|
|
->isRequired() |
114
|
|
|
->cannotBeEmpty() |
115
|
|
|
->end() |
116
|
|
|
->end() |
117
|
|
|
->end(); |
118
|
|
|
} |
119
|
|
|
} |
120
|
|
|
|