Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a Twig extension to expose the RuntimeConfig.
- Loading branch information
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
|
||
namespace OpenSky\Bundle\RuntimeConfigBundle\Twig\Extension; | ||
|
||
use OpenSky\Bundle\RuntimeConfigBundle\Service\RuntimeParameterBag; | ||
|
||
class RuntimeConfigExtension extends \Twig_Extension | ||
{ | ||
protected $runtimeConfig; | ||
|
||
/** | ||
* Constructor. | ||
* | ||
* @param ContainerInterface $container | ||
*/ | ||
public function __construct(RuntimeParameterBag $runtimeConfig) | ||
{ | ||
$this->runtimeConfig = $runtimeConfig; | ||
} | ||
|
||
/** | ||
* Returns a list of global functions to add to the existing list. | ||
* | ||
* @return array An array of global functions | ||
*/ | ||
public function getFunctions() | ||
{ | ||
return array( | ||
'runtime_config' => new \Twig_Function_Method($this, 'getRuntimeConfig'), | ||
); | ||
} | ||
|
||
/** | ||
* Returns the name of the extension. | ||
* | ||
* @return string The extension name | ||
*/ | ||
public function getName() | ||
{ | ||
return 'runtime_config'; | ||
} | ||
|
||
public function getRuntimeConfig($name) | ||
{ | ||
return $this->runtimeConfig->get($name); | ||
} | ||
} |
d544ed9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, this was a long time in the making.
d544ed9
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jmikola apparently nobody but me needed it?