/var/www/hkosl.com/b2b2c/webadmin/libraies/aura/accept/src/Language/LanguageValue.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php
/**
 *
 * This file is part of Aura for PHP.
 *
 * @license http://opensource.org/licenses/bsd-license.php BSD
 *
 */
namespace Aura\Accept\Language;

use 
Aura\Accept\AbstractValue;

/**
 *
 * Represents an acceptable language value.
 *
 * @package Aura.Accept
 *
 */
class LanguageValue extends AbstractValue
{
    
/**
     *
     * The language type.
     *
     * @var string
     *
     */
    
protected $type '*';

    
/**
     *
     * The language subtype, if any.
     *
     * @var string
     *
     */
    
protected $subtype;

    
/**
     *
     * Finishes construction of the value object.
     *
     * @return null
     *
     */
    
protected function init()
    {
        list(
$this->type$this->subtype) = array_pad(explode('-'$this->value), 2false);
    }

    
/**
     *
     * Returns the language type.
     *
     * @return string
     *
     */
    
public function getType()
    {
        return 
$this->type;
    }

    
/**
     *
     * Returns the language subtype.
     *
     * @return string
     *
     */
    
public function getSubtype()
    {
        return 
$this->subtype;
    }

    
/**
     *
     * Checks if an available language value matches this acceptable value.
     *
     * @param Language $avail An available language value.
     *
     * @return True on a match, false if not.
     *
     */
    
public function match(LanguageValue $avail)
    {
        if (
$avail->getValue() == '*') {
            return 
true;
        }

        
// is it a full match?
        
if (strtolower($this->value) == strtolower($avail->getValue())) {
            return 
$this->matchParameters($avail);
        }

        
// is it a type-without-subtype match?
        
return ! $this->subtype
            
&& strtolower($this->type) == strtolower($avail->getType())
            && 
$this->matchParameters($avail);
    }
}