|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Copyright (c) 1998-2015 Browser Capabilities Project |
|
4
|
|
|
* |
|
5
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a |
|
6
|
|
|
* copy of this software and associated documentation files (the "Software"), |
|
7
|
|
|
* to deal in the Software without restriction, including without limitation |
|
8
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense, |
|
9
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the |
|
10
|
|
|
* Software is furnished to do so, subject to the following conditions: |
|
11
|
|
|
* |
|
12
|
|
|
* The above copyright notice and this permission notice shall be included |
|
13
|
|
|
* in all copies or substantial portions of the Software. |
|
14
|
|
|
* |
|
15
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
|
16
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
17
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
18
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
19
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
|
20
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
|
21
|
|
|
* THE SOFTWARE. |
|
22
|
|
|
* |
|
23
|
|
|
* @category Browscap-PHP |
|
24
|
|
|
* @copyright 1998-2015 Browser Capabilities Project |
|
25
|
|
|
* @license http://www.opensource.org/licenses/MIT MIT License |
|
26
|
|
|
* @link https://github.com/browscap/browscap-php/ |
|
27
|
|
|
* @since added with version 3.0 |
|
28
|
|
|
*/ |
|
29
|
|
|
|
|
30
|
|
|
namespace BrowscapPHP\Data; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Ini parser class (compatible with PHP 5.3+) |
|
34
|
|
|
* |
|
35
|
|
|
* @category Browscap-PHP |
|
36
|
|
|
* @author Christoph Ziegenberg <[email protected]> |
|
37
|
|
|
* @author Thomas Müller <[email protected]> |
|
38
|
|
|
* @copyright Copyright (c) 1998-2015 Browser Capabilities Project |
|
39
|
|
|
* @version 3.0 |
|
40
|
|
|
* @license http://www.opensource.org/licenses/MIT MIT License |
|
41
|
|
|
* @link https://github.com/browscap/browscap-php/ |
|
42
|
|
|
*/ |
|
43
|
|
|
class PropertyFormatter |
|
44
|
|
|
{ |
|
45
|
|
|
/** |
|
46
|
|
|
* @var PropertyHolder |
|
47
|
|
|
*/ |
|
48
|
|
|
private $propertyHolder = null; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* class constructor |
|
52
|
|
|
* |
|
53
|
|
|
* @param PropertyHolder $propertyHolder |
|
54
|
|
|
*/ |
|
55
|
6 |
|
public function __construct(PropertyHolder $propertyHolder) |
|
56
|
|
|
{ |
|
57
|
6 |
|
$this->propertyHolder = $propertyHolder; |
|
58
|
6 |
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* formats the name of a property |
|
62
|
|
|
* |
|
63
|
|
|
* @param string $value |
|
64
|
|
|
* @param string $property |
|
65
|
|
|
* |
|
66
|
|
|
* @return string |
|
67
|
|
|
*/ |
|
68
|
6 |
|
public function formatPropertyValue($value, $property) |
|
69
|
|
|
{ |
|
70
|
6 |
|
$valueOutput = $value; |
|
71
|
|
|
|
|
72
|
6 |
|
switch ($this->propertyHolder->getPropertyType($property)) { |
|
73
|
6 |
|
case PropertyHolder::TYPE_BOOLEAN: |
|
74
|
6 |
|
if (true === $value || $value === 'true' || $value === '1') { |
|
75
|
6 |
|
$valueOutput = true; |
|
76
|
6 |
|
} elseif (false === $value || $value === 'false' || $value === '') { |
|
77
|
6 |
|
$valueOutput = false; |
|
78
|
|
|
} else { |
|
79
|
|
|
$valueOutput = ''; |
|
80
|
|
|
} |
|
81
|
6 |
|
break; |
|
82
|
6 |
|
case PropertyHolder::TYPE_IN_ARRAY: |
|
83
|
|
|
try { |
|
84
|
1 |
|
$valueOutput = $this->propertyHolder->checkValueInArray($property, $value); |
|
85
|
|
|
} catch (\InvalidArgumentException $ex) { |
|
86
|
|
|
$valueOutput = ''; |
|
87
|
|
|
} |
|
88
|
1 |
|
break; |
|
89
|
|
|
default: |
|
90
|
|
|
// nothing t do here |
|
91
|
6 |
|
break; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
6 |
|
return $valueOutput; |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|