1 | <?php |
||
13 | class Csv extends AbstractString implements VOArrayable |
||
14 | { |
||
15 | /** |
||
16 | * @param array $array |
||
17 | * @param string $delimiter |
||
18 | * @param string $enclosure |
||
19 | * @param string $escape |
||
20 | * @return static |
||
21 | */ |
||
22 | 16 | public static function fromArray( |
|
30 | |||
31 | /** |
||
32 | * @param VOArray $voArray |
||
33 | * @param string $delimiter |
||
34 | * @param string $enclosure |
||
35 | * @param string $escape |
||
36 | * @return static |
||
37 | */ |
||
38 | 1 | public static function fromVOArray( |
|
46 | |||
47 | /** |
||
48 | * @param string $delimiter |
||
49 | * @param string $enclosure |
||
50 | * @param string $escape |
||
51 | * @return array |
||
52 | */ |
||
53 | 2 | public function toArray($delimiter = ",", $enclosure = '"', $escape = "\\") |
|
61 | |||
62 | /** |
||
63 | * Move this out into the VOClosure namespace. |
||
64 | * |
||
65 | * @param $delimiter |
||
66 | * @param $enclosure |
||
67 | * @param $escape |
||
68 | * @return \Closure |
||
69 | */ |
||
70 | private function iterateCallback($delimiter, $enclosure, $escape) |
||
76 | |||
77 | /** |
||
78 | * Hack |
||
79 | * |
||
80 | * PHP does not have a function to convert an array to CSV, however, fputcsv() does. |
||
81 | * We do this in memory using a file handle. It's not pretty, but it works. |
||
82 | * |
||
83 | * I'm planning on abstracting this out into the File namespace in the near future. |
||
84 | * |
||
85 | * @param array $array |
||
86 | * @param string $delimiter |
||
87 | * @param string $enclosure |
||
88 | * @param string $escape |
||
89 | * @return string |
||
90 | */ |
||
91 | 16 | private static function hack(array $array, $delimiter, $enclosure, $escape) |
|
100 | |||
101 | /** |
||
102 | * @param $handle |
||
103 | * @param array $array |
||
104 | * @param $delimiter |
||
105 | * @param $enclosure |
||
106 | * @param $escape |
||
107 | */ |
||
108 | 1 | private static function hackWrite($handle, array $array, $delimiter, $enclosure, $escape) |
|
114 | |||
115 | /** |
||
116 | * @param $handle |
||
117 | * @param string $contents |
||
118 | * @return string |
||
119 | */ |
||
120 | 16 | private static function hackRead($handle, $contents = '') |
|
128 | } |
||
129 |