Skip to content

Instantly share code, notes, and snippets.

@colindecarlo
Created May 23, 2012 02:25
Show Gist options
  • Save colindecarlo/2772887 to your computer and use it in GitHub Desktop.
Save colindecarlo/2772887 to your computer and use it in GitHub Desktop.
persist method from the Persister abstract class
<?php
// interesting bits up here
public function persist()
{
try {
// maybe do some preprocessing of the file
// make sure it's safe, etc
// call out to a protected method to actually store the file somewhere
$this->_persist();
} catch (\Exception $e) {
// this exception will have some nitty gritty details useful for logging
$this->_logger->log(
'Unable to persist uploaded file: ' . $e->getMessage(),
Logger::LEVEL_OHNOES
);
// throw a new friendly exception
throw new \Exception(
'We were unable to store your file, maybe retry a little later?',
0, // we don't need no stinking error codes
$e
);
}
$this->_logger->log('Successfully stored uploaded file in: ' . $this->getLocation());
return true;
}
// moar interesting bits down here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment