1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the core-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2019 WEBEWEB |
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 WBW\Bundle\CoreBundle\Twig\Extension; |
13
|
|
|
|
14
|
|
|
use Twig\Environment; |
15
|
|
|
use Twig\TwigFunction; |
16
|
|
|
use WBW\Bundle\CoreBundle\Manager\QuoteManager; |
17
|
|
|
use WBW\Bundle\CoreBundle\Manager\QuoteManagerTrait; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Quote Twig extension. |
21
|
|
|
* |
22
|
|
|
* @author webeweb <https://github.com/webeweb/> |
23
|
|
|
* @package WBW\Bundle\CoreBundle\Twig\Extension |
24
|
|
|
*/ |
25
|
|
|
class QuoteTwigExtension extends AbstractTwigExtension { |
26
|
|
|
|
27
|
|
|
use QuoteManagerTrait; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Service name. |
31
|
|
|
* |
32
|
|
|
* @var string |
33
|
|
|
*/ |
34
|
|
|
const SERVICE_NAME = "webeweb.core.twig.extension.quote"; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Constructor. |
38
|
|
|
* |
39
|
|
|
* @param Environment $twigEnvironment The Twig environment. |
40
|
|
|
* @param QuoteManager $quoteManager The quote manager. |
41
|
|
|
*/ |
42
|
|
|
public function __construct(Environment $twigEnvironment, QuoteManager $quoteManager) { |
43
|
|
|
parent::__construct($twigEnvironment); |
44
|
|
|
$this->setQuoteManager($quoteManager); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Get the Twig functions. |
49
|
|
|
* |
50
|
|
|
* @return TwigFunction[] Returns the Twig functions. |
51
|
|
|
*/ |
52
|
|
|
public function getFunctions() { |
53
|
|
|
return [ |
54
|
|
|
new TwigFunction("quoteAuthor", [$this, "quoteAuthorFunction"], ["is_safe" => ["html"]]), |
55
|
|
|
new TwigFunction("quoteContent", [$this, "quoteContentFunction"], ["is_safe" => ["html"]]), |
56
|
|
|
]; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Displays a quote author. |
61
|
|
|
* |
62
|
|
|
* @param array $args The arguments. |
63
|
|
|
* @return string Returns the quote author. |
64
|
|
|
*/ |
65
|
|
|
public function quoteAuthorFunction(array $args = []) { |
|
|
|
|
66
|
|
|
|
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Displays a quote content. |
71
|
|
|
* |
72
|
|
|
* @param array $args The arguments. |
73
|
|
|
* @return string Returns the quote content. |
74
|
|
|
*/ |
75
|
|
|
public function quoteContentFunction(array $args = []) { |
|
|
|
|
76
|
|
|
|
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.