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
LocaleDetectorParamStrategy
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
0.00% covered (danger)
0.00%
0 / 1
 detect
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2
3/**
4 * Locale Detector Strategy for VuFind POST Parameter
5 *
6 * PHP version 8
7 *
8 * Copyright (C) Villanova University 2018,
9 *               Leipzig University Library <info@ub.uni-leipzig.de> 2018.
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  I18n\Locale
26 * @author   Demian Katz <demian.katz@villanova.edu>
27 * @author   Sebastian Kehr <kehr@ub.uni-leipzig.de>
28 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
29 * @link     https://vufind.org Main Site
30 */
31
32namespace VuFind\I18n\Locale;
33
34use SlmLocale\LocaleEvent;
35use SlmLocale\Strategy\AbstractStrategy;
36
37use function in_array;
38
39/**
40 * Locale Detector Strategy for VuFind POST Parameter
41 *
42 * @category VuFind
43 * @package  I18n\Locale
44 * @author   Demian Katz <demian.katz@villanova.edu>
45 * @author   Sebastian Kehr <kehr@ub.uni-leipzig.de>
46 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
47 * @link     https://vufind.org Main Site
48 */
49class LocaleDetectorParamStrategy extends AbstractStrategy
50{
51    public const PARAM_NAME = 'mylang';
52
53    /**
54     * Attempt to detect the locale from a POST parameter.
55     *
56     * @param LocaleEvent $event Event
57     *
58     * @return ?string
59     */
60    public function detect(LocaleEvent $event)
61    {
62        $request = $event->getRequest();
63        $locale = $request->getPost(self::PARAM_NAME);
64        if (in_array($locale, $event->getSupported())) {
65            return $locale;
66        }
67    }
68}