]> Raphaël G. Git Repositories - treebundle/blob - DependencyInjection/Configuration.php
Add bundle user repository
[treebundle] / DependencyInjection / Configuration.php
1 <?php declare(strict_types=1);
2
3 /*
4 * This file is part of the Rapsys TreeBundle package.
5 *
6 * (c) Raphaël Gertz <symfony@rapsys.eu>
7 *
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
10 */
11
12 namespace Rapsys\TreeBundle\DependencyInjection;
13
14 use Symfony\Component\Config\Definition\Builder\TreeBuilder;
15 use Symfony\Component\Config\Definition\ConfigurationInterface;
16
17 use Rapsys\TreeBundle\RapsysTreeBundle;
18
19 /**
20 * This is the class that validates and merges configuration from your app/config files.
21 *
22 * To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/configuration.html}
23 */
24 class Configuration implements ConfigurationInterface {
25 /**
26 * {@inheritdoc}
27 */
28 public function getConfigTreeBuilder(): TreeBuilder {
29 $treeBuilder = new TreeBuilder($alias = RapsysTreeBundle::getAlias());
30
31 // Here you should define the parameters that are allowed to
32 // configure your bundle. See the documentation linked above for
33 // more information on that topic.
34 //Set defaults
35 $defaults = [
36 'contact' => [
37 'address' => 'contact@example.com',
38 'name' => 'John Doe'
39 ],
40 'copy' => [
41 'by' => 'Rapsys',
42 'link' => 'https://rapsys.eu',
43 'long' => 'All rights reserved',
44 'short' => 'Copyright 2023-2024',
45 'title' => 'Rapsys'
46 ],
47 'donate' => 'https://paypal.me/milongaraphael',
48 'facebook' => [
49 'apps' => [],
50 'height' => 630,
51 'width' => 1200
52 ],
53 'icon' => [
54 'ico' => '@RapsysTree/ico/icon.ico',
55 //The png icon array
56 //XXX: see https://www.emergeinteractive.com/insights/detail/the-essentials-of-favicons/
57 //XXX: see https://caniuse.com/#feat=link-icon-svg
58 'png' => [
59 //Default
60 256 => '@RapsysTree/png/icon.256.png',
61
62 //For google
63 //Chrome for Android home screen icon
64 196 => '@RapsysTree/png/icon.196.png',
65 //Google Developer Web App Manifest Recommendation
66 192 => '@RapsysTree/png/icon.192.png',
67 //Chrome Web Store icon
68 128 => '@RapsysTree/png/icon.128.png',
69
70 //Fallback
71 32 => '@RapsysTree/png/icon.32.png',
72
73 //For apple
74 //XXX: old obsolete format: [57, 72, 76, 114, 120, 144]
75 //XXX: see https://webhint.io/docs/user-guide/hints/hint-apple-touch-icons/
76 //XXX: see https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/ConfiguringWebApplications/ConfiguringWebApplications.html
77 //iPhone Retina
78 180 => '@RapsysTree/png/icon.180.png',
79 //iPad Retina touch icon
80 167 => '@RapsysTree/png/icon.167.png',
81 //iPad touch icon
82 152 => '@RapsysTree/png/icon.152.png',
83 //iOS7
84 120 => '@RapsysTree/png/icon.120.png',
85
86 //For windows
87 //XXX: see https://docs.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/platform-apis/dn255024(v=vs.85)
88 310 => '@RapsysTree/png/icon.310.png',
89 150 => '@RapsysTree/png/icon.150.png',
90 70 => '@RapsysTree/png/icon.70.png'
91 ],
92 'svg' => '@RapsysTree/svg/icon.svg'
93 ],
94 //XXX: revert to underscore because of that shit:
95 //XXX: see https://symfony.com/doc/current/components/config/definition.html#normalization
96 //XXX: see https://github.com/symfony/symfony/issues/7405
97 'languages' => [
98 'en_gb' => 'English'
99 ],
100 //TODO: copy to '%kernel.default_locale%'
101 'locale' => 'en_gb',
102 //TODO: copy to '%kernel.translator.fallbacks%'
103 'locales' => [ 'en_gb' ],
104 'logo' => [
105 'alt' => 'Veranda\'s gallery system logo',
106 'png' => '@RapsysTree/png/logo.png',
107 'svg' => '@RapsysTree/svg/logo.svg'
108 ],
109 'path' => is_link(($prefix = is_dir('public') ? './public/' : './').($link = 'bundles/'.str_replace('_', '', $alias))) && is_dir(realpath($prefix.$link)) || is_dir($prefix.$link) ? $link : dirname(__DIR__).'/Resources/public',
110 'root' => 'rapsystree',
111 'roots' => [],
112 'title' => 'Veranda\'s gallery system'
113 ];
114
115 //Here we define the parameters that are allowed to configure the bundle.
116 //TODO: see https://github.com/symfony/symfony/blob/master/src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php for default value and description
117 //TODO: see http://symfony.com/doc/current/components/config/definition.html
118 //XXX: use bin/console config:dump-reference to dump class infos
119
120 //Here we define the parameters that are allowed to configure the bundle.
121 $treeBuilder
122 //Parameters
123 ->getRootNode()
124 ->addDefaultsIfNotSet()
125 ->children()
126 ->arrayNode('contact')
127 ->addDefaultsIfNotSet()
128 ->children()
129 ->scalarNode('address')->cannotBeEmpty()->defaultValue($defaults['contact']['address'])->end()
130 ->scalarNode('name')->cannotBeEmpty()->defaultValue($defaults['contact']['name'])->end()
131 ->end()
132 ->end()
133 ->arrayNode('copy')
134 ->addDefaultsIfNotSet()
135 ->children()
136 ->scalarNode('by')->defaultValue($defaults['copy']['by'])->end()
137 ->scalarNode('link')->defaultValue($defaults['copy']['link'])->end()
138 ->scalarNode('long')->defaultValue($defaults['copy']['long'])->end()
139 ->scalarNode('short')->defaultValue($defaults['copy']['short'])->end()
140 ->scalarNode('title')->defaultValue($defaults['copy']['title'])->end()
141 ->end()
142 ->end()
143 ->scalarNode('donate')->cannotBeEmpty()->defaultValue($defaults['donate'])->end()
144 ->arrayNode('facebook')
145 ->addDefaultsIfNotSet()
146 ->children()
147 ->arrayNode('apps')
148 ->treatNullLike([])
149 ->defaultValue($defaults['facebook']['apps'])
150 ->scalarPrototype()->end()
151 ->end()
152 ->integerNode('height')->min(0)->defaultValue($defaults['facebook']['height'])->end()
153 ->integerNode('width')->min(0)->defaultValue($defaults['facebook']['width'])->end()
154 ->end()
155 ->end()
156 ->arrayNode('icon')
157 ->addDefaultsIfNotSet()
158 ->children()
159 ->scalarNode('ico')->defaultValue($defaults['icon']['ico'])->end()
160 ->arrayNode('png')
161 ->treatNullLike([])
162 ->defaultValue($defaults['icon']['png'])
163 ->scalarPrototype()->end()
164 ->end()
165 ->scalarNode('svg')->defaultValue($defaults['icon']['svg'])->end()
166 ->end()
167 ->end()
168 #TODO: see if we can't prevent key normalisation with ->normalizeKeys(false)
169 #->scalarNode('languages')->cannotBeEmpty()->defaultValue($defaults['languages'])->end()
170 ->variableNode('languages')
171 ->treatNullLike([])
172 ->defaultValue($defaults['languages'])
173 #->scalarPrototype()->end()
174 ->end()
175 ->scalarNode('locale')->cannotBeEmpty()->defaultValue($defaults['locale'])->end()
176 #TODO: see if we can't prevent key normalisation with ->normalizeKeys(false)
177 #->scalarNode('locales')->cannotBeEmpty()->defaultValue($defaults['locales'])->end()
178 ->variableNode('locales')
179 ->treatNullLike([])
180 ->defaultValue($defaults['locales'])
181 #->scalarPrototype()->end()
182 ->end()
183 ->arrayNode('logo')
184 ->addDefaultsIfNotSet()
185 ->children()
186 ->scalarNode('alt')->defaultValue($defaults['logo']['alt'])->end()
187 ->scalarNode('png')->defaultValue($defaults['logo']['png'])->end()
188 ->scalarNode('svg')->defaultValue($defaults['logo']['svg'])->end()
189 ->end()
190 ->end()
191 ->scalarNode('path')->defaultValue($defaults['path'])->end()
192 ->scalarNode('root')->cannotBeEmpty()->defaultValue($defaults['root'])->end()
193 #TODO: see if we can't prevent key normalisation with ->normalizeKeys(false)
194 #->scalarNode('roots')->cannotBeEmpty()->defaultValue($defaults['roots'])->end()
195 ->variableNode('roots')
196 ->treatNullLike([])
197 ->defaultValue($defaults['roots'])
198 #->scalarPrototype()->end()
199 ->end()
200 ->scalarNode('title')->cannotBeEmpty()->defaultValue($defaults['title'])->end()
201 ->end()
202 ->end();
203
204 return $treeBuilder;
205 }
206 }