Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
CRAP
0.00% covered (danger)
0.00%
0 / 1
TransEscWithPrefix
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 1
 __invoke
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * Translate with prefix + escape view helper
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2010.
9 * Copyright (C) The National Library of Finland 2019.
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2,
13 * as published by the Free Software Foundation.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23 *
24 * @category VuFind
25 * @package  View_Helpers
26 * @author   Demian Katz <demian.katz@villanova.edu>
27 * @author   Ere Maijala <ere.maijala@helsinki.fi>
28 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
29 * @link     https://vufind.org/wiki/development Wiki
30 */
31
32namespace VuFind\View\Helper\Root;
33
34use Laminas\View\Helper\AbstractHelper;
35use VuFind\I18n\Translator\TranslatorAwareInterface;
36
37/**
38 * Translate with prefix + escape view helper
39 *
40 * Like transEsc, but applies a prefix to the translation key.
41 *
42 * @category VuFind
43 * @package  View_Helpers
44 * @author   Demian Katz <demian.katz@villanova.edu>
45 * @author   Ere Maijala <ere.maijala@helsinki.fi>
46 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
47 * @link     https://vufind.org/wiki/development Wiki
48 */
49class TransEscWithPrefix extends AbstractHelper implements TranslatorAwareInterface
50{
51    use \VuFind\I18n\Translator\TranslatorAwareTrait;
52
53    /**
54     * Translate and escape a value while applying a prefix
55     *
56     * @param string              $prefix          Translation key prefix
57     * @param string|object|array $str             String to translate or an array of text
58     *                                             domain and string to translate
59     * @param array               $tokens          Tokens to inject into the translated string
60     * @param string              $default         Default value to use if no translation is
61     *                                             found (null for no default).
62     * @param bool                $useIcuFormatter Should we use an ICU message formatter instead
63     * of the default behavior?
64     * @param string[]            $fallbackDomains Text domains to check if no match is found in
65     * the domain specified in $target
66     *
67     * @return string
68     */
69    public function __invoke(
70        $prefix,
71        $str,
72        $tokens = [],
73        $default = null,
74        $useIcuFormatter = false,
75        $fallbackDomains = []
76    ) {
77        $escaper = $this->getView()->plugin('escapeHtml');
78        return $escaper(
79            $this->translateWithPrefix($prefix, $str, $tokens, $default, $useIcuFormatter, $fallbackDomains)
80        );
81    }
82}