• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

craue / CraueConfigBundle / 5901672069

pending completion
5901672069

Pull #62

github

web-flow
Merge 668619b46 into 288728580
Pull Request #62: also update the cache when updating a setting entity directly

7 of 7 new or added lines in 2 files covered. (100.0%)

200 of 210 relevant lines covered (95.24%)

17.79 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.0
/Twig/Extension/ConfigTemplateExtension.php
1
<?php
2

3
namespace Craue\ConfigBundle\Twig\Extension;
4

5
use Craue\ConfigBundle\Util\Config;
6
use Twig\Extension\AbstractExtension;
7
use Twig\TwigFilter;
8
use Twig\TwigFunction;
9

10
/**
11
 * @author Christian Raue <christian.raue@gmail.com>
12
 * @copyright 2011-2023 Christian Raue
13
 * @license http://opensource.org/licenses/mit-license.php MIT License
14
 */
15
class ConfigTemplateExtension extends AbstractExtension {
16

17
        /**
18
         * @var string[]
19
         */
20
        protected $sectionOrder = [];
21

22
        /**
23
         * @var Config
24
         */
25
        protected $config;
26

27
        /**
28
         * @param string[] $sectionOrder The order in which sections will be rendered.
29
         */
30
        public function setSectionOrder(array $sectionOrder = []) {
31
                $this->sectionOrder = $sectionOrder;
35✔
32
        }
33

34
        /**
35
         * @param Config $config
36
         */
37
        public function setConfig(Config $config) {
38
                $this->config = $config;
35✔
39
        }
40

41
        /**
42
         * {@inheritDoc}
43
         */
44
        public function getName() {
45
                return 'craue_config_template';
×
46
        }
47

48
        /**
49
         * {@inheritDoc}
50
         */
51
        public function getFilters() : array {
52
                return [
3✔
53
                        new TwigFilter('craue_sortSections', [$this, 'sortSections']),
3✔
54
                ];
3✔
55
        }
56

57
        /**
58
         * {@inheritDoc}
59
         */
60
        public function getFunctions() : array {
61
                return [
3✔
62
                        new TwigFunction('craue_setting', [$this, 'getSetting']),
3✔
63
                ];
3✔
64
        }
65

66
        /**
67
         * @param string[] $sections
68
         * @return string[]
69
         */
70
        public function sortSections(array $sections) {
71
                $finalSectionOrder = [];
28✔
72

73
                // add null section first (if it exists)
74
                $nullIndex = array_search(null, $sections, true);
28✔
75
                if ($nullIndex !== false) {
28✔
76
                        $finalSectionOrder[] = $sections[$nullIndex];
22✔
77
                        unset($sections[$nullIndex]);
22✔
78
                }
79

80
                // add sections in given order
81
                foreach (array_intersect($this->sectionOrder, $sections) as $section) {
28✔
82
                        $finalSectionOrder[] = $section;
3✔
83
                }
84

85
                // add remaining sections
86
                foreach (array_diff($sections, $this->sectionOrder) as $section) {
28✔
87
                        $finalSectionOrder[] = $section;
9✔
88
                }
89

90
                return $finalSectionOrder;
28✔
91
        }
92

93
        /**
94
         * @param string $name Name of the setting.
95
         * @return string|null Value of the setting.
96
         * @throws \RuntimeException If the setting is not defined.
97
         */
98
        public function getSetting($name) {
99
                return $this->config->get($name);
3✔
100
        }
101

102
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc