Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
85.71% |
6 / 7 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
| config | |
85.71% |
6 / 7 |
|
75.00% |
3 / 4 |
4.05 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getFunctions | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| get_config | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * This file is part of the phpBB Forum Software package. |
| 5 | * |
| 6 | * @copyright (c) phpBB Limited <https://www.phpbb.com> |
| 7 | * @license GNU General Public License, version 2 (GPL-2.0) |
| 8 | * |
| 9 | * For full copyright and license information, please see |
| 10 | * the docs/CREDITS.txt file. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | namespace phpbb\template\twig\extension; |
| 15 | |
| 16 | use Twig\Extension\AbstractExtension; |
| 17 | |
| 18 | class config extends AbstractExtension |
| 19 | { |
| 20 | /** @var \phpbb\config\config */ |
| 21 | protected $config; |
| 22 | |
| 23 | /** |
| 24 | * Constructor. |
| 25 | * |
| 26 | * @param \phpbb\config\config $config Configuration object |
| 27 | */ |
| 28 | public function __construct(\phpbb\config\config $config) |
| 29 | { |
| 30 | $this->config = $config; |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Get the name of this extension |
| 35 | * |
| 36 | * @return string |
| 37 | */ |
| 38 | public function getName() |
| 39 | { |
| 40 | return 'config'; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Returns a list of global functions to add to the existing list. |
| 45 | * |
| 46 | * @return \Twig\TwigFunction[] An array of global functions |
| 47 | */ |
| 48 | public function getFunctions(): array |
| 49 | { |
| 50 | return array( |
| 51 | new \Twig\TwigFunction('config', array($this, 'get_config')), |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Retrieves a configuration value for use in templates. |
| 57 | * |
| 58 | * @return int|string The configuration value |
| 59 | */ |
| 60 | public function get_config() |
| 61 | { |
| 62 | $args = func_get_args(); |
| 63 | |
| 64 | return $this->config->offsetGet($args[0]); |
| 65 | } |
| 66 | } |