for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* @author Matthijs van den Bos <[email protected]>
* @copyright 2013 Matthijs van den Bos
*/
namespace VDB\Spider\PersistenceHandler;
use Symfony\Component\Finder\Finder;
use VDB\Spider\PersistenceHandler\FilePersistenceHandler;
use VDB\Spider\Resource;
class FileSerializedResourcePersistenceHandler extends FilePersistenceHandler implements PersistenceHandlerInterface
{
public function persist(Resource $resource)
$path = $this->getResultPath() . $this->getFileSystemPath($resource);
if (! is_dir($path)) {
mkdir($path, 0777, true);
}
$file = new \SplFileObject($path . DIRECTORY_SEPARATOR . $this->getFileSystemFilename($resource), 'w');
$this->totalSizePersisted += $file->fwrite(serialize($resource));
protected function getFileSystemFilename($resource)
$fullPath = $resource->getUri()->getPath();
return urlencode(basename($fullPath));
protected function getFileSystemPath($resource)
$hostname = $resource->getUri()->getHost();
return $hostname . dirname($fullPath);
* @return Resource
public function current()
return unserialize($this->getIterator()->current()->getContents());