1 | <?php |
||
34 | class CSVelte |
||
35 | { |
||
36 | /** |
||
37 | * CSVelte\Reader Factory |
||
38 | * |
||
39 | * Factory method for creating a new CSVelte\Reader object |
||
40 | * Used to create a local file CSV reader object. |
||
41 | * |
||
42 | * @param string The filename to read |
||
43 | * @param CSVelte\Flavor An explicit flavor object that will be passed to the reader |
||
44 | * @return CSVelte\Reader An iterator for specified CSV file |
||
45 | * @throws CSVelte\Exception\PermissionDeniedException |
||
46 | * @throws CSVelte\Exception\FileNotFoundException |
||
47 | * @access public |
||
48 | */ |
||
49 | 5 | public static function reader($filename, $flavor = null) |
|
55 | |||
56 | /** |
||
57 | * String Reader Factory |
||
58 | * |
||
59 | * Factory method for creating a new CSVelte\Reader object for reading |
||
60 | * from a PHP string |
||
61 | * |
||
62 | * @param string The CSV data to read |
||
63 | * @param CSVelte\Flavor An explicit flavor object that will be passed to the reader |
||
64 | * @return CSVelte\Reader An iterator for provided CSV data |
||
65 | * @access public |
||
66 | */ |
||
67 | 1 | public static function stringReader($str, $flavor = null) |
|
71 | |||
72 | /** |
||
73 | * CSVelte\Writer Factory |
||
74 | * |
||
75 | * Factory method for creating a new CSVelte\Writer object for writing |
||
76 | * CSV data to a file. If file doesn't exist, it will be created. If it |
||
77 | * already contains data, it will be overwritten. |
||
78 | * |
||
79 | * @param string The filename to write to. |
||
80 | * @param CSVelte\Flavor An explicit flavor object for the writer to use |
||
81 | * @return CSVelte\Writer A writer object for writing to given filename |
||
82 | * @access public |
||
83 | */ |
||
84 | 2 | public static function writer($filename, $flavor = null) |
|
89 | |||
90 | /** |
||
91 | * Export CSV data to local file |
||
92 | * |
||
93 | * Facade method for exporting data to given filename. IF file doesn't exist |
||
94 | * it will be created. If it does exist it will be overwritten. |
||
95 | * |
||
96 | * @param string The filename to export data to |
||
97 | * @param Iterator|array Data to write to CSV file |
||
98 | * @param CSVelte\Flavor An explicit flavor object that will be passed to the writer |
||
99 | * @return int Number of rows written |
||
100 | * @access public |
||
101 | */ |
||
102 | 2 | public static function export($filename, $data, $flavor = null) |
|
108 | |||
109 | /** |
||
110 | * Assert that file is readable |
||
111 | * |
||
112 | * Assert that a particular file exists and is readable (user has permission |
||
113 | * to read/access it) |
||
114 | * |
||
115 | * @param string The name of the file you wish to check |
||
116 | * @return void |
||
117 | * @access protected |
||
118 | * @throws CSVelte\Exception\IOException |
||
119 | * @internal |
||
120 | */ |
||
121 | 5 | protected static function assertFileIsReadable($filename) |
|
122 | { |
||
123 | 5 | self::assertFileExists($filename); |
|
124 | 4 | if (!is_readable($filename)) { |
|
125 | 1 | throw new IOException('Permission denied for: ' . $filename, IOException::ERR_FILE_PERMISSION_DENIED); |
|
126 | } |
||
127 | 3 | } |
|
128 | |||
129 | /** |
||
130 | * Assert that a particular file exists |
||
131 | * |
||
132 | * @param string The name of the file you wish to check |
||
133 | * @return void |
||
134 | * @access protected |
||
135 | * @throws CSVelte\Exception\IOException |
||
136 | * @internal |
||
137 | */ |
||
138 | 5 | protected static function assertFileExists($filename) |
|
144 | } |
||
145 |