1 | <?php |
||
26 | class PgBoolean implements ConverterInterface |
||
27 | { |
||
28 | /** |
||
29 | * @see ConverterInterface |
||
30 | */ |
||
31 | public function fromPg($data, $type, Session $session) |
||
32 | { |
||
33 | $data = trim($data); |
||
34 | |||
35 | if (!preg_match('/^(t|f)$/', $data)) { |
||
36 | if ($data === '') { |
||
37 | return null; |
||
38 | } |
||
39 | |||
40 | throw new ConverterException(sprintf("Unknown %s data '%s'.", $type, $data)); |
||
41 | } |
||
42 | |||
43 | return (bool) ($data === 't'); |
||
44 | } |
||
45 | |||
46 | /** |
||
47 | * @see ConverterInterface |
||
48 | */ |
||
49 | public function toPg($data, $type, Session $session) |
||
50 | { |
||
51 | if ($data === null) { |
||
52 | return sprintf("NULL::%s", $type); |
||
53 | } |
||
54 | |||
55 | return sprintf("%s '%s'", $type, $data === true ? "true" : "false"); |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * @see ConverterInterface |
||
60 | */ |
||
61 | public function toPgStandardFormat($data, $type, Session $session) |
||
69 | } |
||
70 |