php-translation /
symfony-bundle
| 1 | <?php |
||
| 2 | |||
| 3 | /* |
||
| 4 | * This file is part of the PHP Translation package. |
||
| 5 | * |
||
| 6 | * (c) PHP Translation team <[email protected]> |
||
| 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 Translation\Bundle\Twig; |
||
| 13 | |||
| 14 | use Symfony\Bridge\Twig\Extension\TranslationExtension; |
||
| 15 | use Symfony\Component\HttpFoundation\RequestStack; |
||
| 16 | use Translation\Bundle\EditInPlace\ActivatorInterface; |
||
| 17 | use Twig\Extension\AbstractExtension; |
||
| 18 | use Twig\TwigFilter; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Override the `trans` functions `is_safe` option to allow HTML output from the |
||
| 22 | * translator. This extension is used by for the EditInPlace feature. |
||
| 23 | * |
||
| 24 | * @author Damien Alexandre <[email protected]> |
||
| 25 | */ |
||
| 26 | final class EditInPlaceExtension extends AbstractExtension |
||
| 27 | { |
||
| 28 | private $extension; |
||
| 29 | private $requestStack; |
||
| 30 | private $activator; |
||
| 31 | |||
| 32 | public function __construct(TranslationExtension $extension, RequestStack $requestStack, ActivatorInterface $activator) |
||
| 33 | { |
||
| 34 | $this->extension = $extension; |
||
| 35 | $this->requestStack = $requestStack; |
||
| 36 | $this->activator = $activator; |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * {@inheritdoc} |
||
| 41 | */ |
||
| 42 | public function getFilters(): array |
||
| 43 | { |
||
| 44 | return [ |
||
| 45 | new TwigFilter('trans', [$this->extension, 'trans'], ['is_safe_callback' => [$this, 'isSafe']]), |
||
| 46 | new TwigFilter('transchoice', [$this->extension, 'transchoice'], ['is_safe_callback' => [$this, 'isSafe']]), |
||
| 47 | ]; |
||
| 48 | } |
||
| 49 | |||
| 50 | /** |
||
| 51 | * Escape output if the EditInPlace is disabled. |
||
| 52 | */ |
||
| 53 | public function isSafe($node): array |
||
|
0 ignored issues
–
show
|
|||
| 54 | { |
||
| 55 | return $this->activator->checkRequest($this->requestStack->getMasterRequest()) ? ['html'] : []; |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * {@inheritdoc} |
||
| 60 | */ |
||
| 61 | public function getName(): string |
||
| 62 | { |
||
| 63 | return self::class; |
||
| 64 | } |
||
| 65 | } |
||
| 66 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.