1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of Pomm's Foundation package. |
4
|
|
|
* |
5
|
|
|
* (c) 2014 - 2015 Grégoire HUBERT <[email protected]> |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
namespace PommProject\Foundation\Converter; |
11
|
|
|
|
12
|
|
|
use PommProject\Foundation\Client\Client; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* ConverterClient |
16
|
|
|
* |
17
|
|
|
* Converter wrapper as Session's client. |
18
|
|
|
* |
19
|
|
|
* @package Foundation |
20
|
|
|
* @copyright 2014 - 2015 Grégoire HUBERT |
21
|
|
|
* @author Grégoire HUBERT |
22
|
|
|
* @license X11 {@link http://opensource.org/licenses/mit-license.php} |
23
|
|
|
* @see Client |
24
|
|
|
*/ |
25
|
|
|
class ConverterClient extends Client |
26
|
|
|
{ |
27
|
|
|
protected $converter; |
28
|
|
|
protected $name; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* __construct |
32
|
|
|
* |
33
|
|
|
* Wrap the given converter. |
34
|
|
|
* |
35
|
|
|
* @access public |
36
|
|
|
* @param string $name |
37
|
|
|
* @param ConverterInterface $converter |
38
|
|
|
*/ |
39
|
|
|
public function __construct($name, ConverterInterface $converter) |
40
|
|
|
{ |
41
|
|
|
$this->name = $name; |
42
|
|
|
$this->converter = $converter; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* getClientType |
47
|
|
|
* |
48
|
|
|
* @see ClientInterface |
49
|
|
|
*/ |
50
|
|
|
public function getClientType() |
51
|
|
|
{ |
52
|
|
|
return 'converter'; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* getClientIdentifier |
57
|
|
|
* |
58
|
|
|
* @see ClientInterface |
59
|
|
|
*/ |
60
|
|
|
public function getClientIdentifier() |
61
|
|
|
{ |
62
|
|
|
return $this->name; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* toPg |
67
|
|
|
* |
68
|
|
|
* Trigger converter's toPg conversion method. |
69
|
|
|
* |
70
|
|
|
* @access public |
71
|
|
|
* @param mixed $value |
72
|
|
|
* @param string $type |
73
|
|
|
* @return string |
74
|
|
|
* @see ConverterInterface |
75
|
|
|
*/ |
76
|
|
View Code Duplication |
public function toPg($value, $type = null) |
77
|
|
|
{ |
78
|
|
|
return $this->converter->toPg( |
79
|
|
|
$value, |
80
|
|
|
$type === null ? $this->getClientIdentifier() : $type, |
81
|
|
|
$this->getSession() |
82
|
|
|
); |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* fromPg |
87
|
|
|
* |
88
|
|
|
* Trigger converter's fromPg conversion method. |
89
|
|
|
* |
90
|
|
|
* @access public |
91
|
|
|
* @param mixed $value |
92
|
|
|
* @param string $type |
93
|
|
|
* @return mixed |
94
|
|
|
* @see ConverterInterface |
95
|
|
|
*/ |
96
|
|
View Code Duplication |
public function fromPg($value, $type = null) |
97
|
|
|
{ |
98
|
|
|
return $this->converter->fromPg( |
99
|
|
|
$value, |
100
|
|
|
$type === null ? $this->getClientIdentifier() : $type, |
101
|
|
|
$this->getSession() |
102
|
|
|
); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* toPgStandardFormat |
107
|
|
|
* |
108
|
|
|
* Export data as CSV representation |
109
|
|
|
* |
110
|
|
|
* @access public |
111
|
|
|
* @param mixed $value |
112
|
|
|
* @param string $type |
113
|
|
|
* @return string |
114
|
|
|
* @see ConverterInterface |
115
|
|
|
*/ |
116
|
|
View Code Duplication |
public function toPgStandardFormat($value, $type = null) |
117
|
|
|
{ |
118
|
|
|
return $this->converter->toPgStandardFormat( |
119
|
|
|
$value, |
120
|
|
|
$type === null ? $this->getClientIdentifier() : $type, |
121
|
|
|
$this->getSession() |
122
|
|
|
); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* getConverter |
127
|
|
|
* |
128
|
|
|
* Return the embedded converter. |
129
|
|
|
* |
130
|
|
|
* @access public |
131
|
|
|
* @return ConverterInterface |
132
|
|
|
*/ |
133
|
|
|
public function getConverter() |
134
|
|
|
{ |
135
|
|
|
return $this->converter; |
136
|
|
|
} |
137
|
|
|
} |
138
|
|
|
|