1: <?php
2:
3: /**
4: * This file is part of the Minion package.
5: * For the full copyright and license information, please view the LICENSE
6: * file that was distributed with this source code.
7: *
8: * @license MIT License
9: */
10:
11: namespace Minion\Twig;
12:
13: use Minion\Application;
14:
15: /**
16: * Class MiscExtension.
17: *
18: * @package Minion
19: * @author Damian SzczerbiĆski <dszczer@gmail.com>
20: */
21: class MiscExtension extends \Twig_Extension
22: {
23: /** @var Application Application container */
24: private $container;
25:
26: /**
27: * MiscExtension constructor.
28: * Inject dependencies
29: *
30: * @param Application $app Framework
31: *
32: * @return MiscExtension
33: */
34: public function __construct(Application $app) {
35: $this->container = $app;
36: }
37:
38: /**
39: * {@inheritdoc}
40: */
41: public function getName() {
42: return 'minion_twig_misc';
43: }
44:
45: /**
46: * {@inheritdoc}
47: */
48: public function getFunctions() {
49: return [
50: new \Twig_Function('static', [$this, 'staticFunction']),
51: ];
52: }
53:
54: /**
55: * Call static by fully qualified name.
56: *
57: * @param callable $callable Fully qualified static method or function name
58: * @param array $arguments Optional arguments
59: *
60: * @throws \InvalidArgumentException Callable must be string type
61: *
62: * @return mixed
63: */
64: public function staticFunction(callable $callable, array $arguments = []) {
65: if(!\is_string($callable))
66: throw new \InvalidArgumentException("\$callable argument must be a string callable");
67:
68: return \call_user_func_array($callable, $arguments);
69: }
70: }