Created
April 11, 2014 08:19
-
-
Save rsmarshall/10449488 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php namespace Parfetts\Services; | |
| class FileWriter | |
| { | |
| private | |
| $_fileObject; | |
| /** | |
| * @param $filename | |
| * @return void | |
| */ | |
| public function newFile($filename) | |
| { | |
| /** | |
| * @todo Not happy about doing a new here, need to pass options to SplFileObject on construction | |
| */ | |
| $this->_fileObject = new \SplFileObject($filename, 'w'); | |
| } | |
| /** | |
| * @param $data | |
| * @return bool | |
| */ | |
| public function writeLineCsv($data) | |
| { | |
| if ($this->_fileObject->isWritable()) { | |
| $this->_fileObject->fputcsv($data); | |
| return true; | |
| } | |
| } | |
| /** | |
| * SplFileObject has no close so this is to remove the active object | |
| */ | |
| public function __destruct() | |
| { | |
| unset($this->_fileObject); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment