Skip to content

Instantly share code, notes, and snippets.

@rsmarshall
Created April 11, 2014 08:19
Show Gist options
  • Select an option

  • Save rsmarshall/10449488 to your computer and use it in GitHub Desktop.

Select an option

Save rsmarshall/10449488 to your computer and use it in GitHub Desktop.
<?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