Created
March 16, 2017 00:31
-
-
Save yawo/72643110bd33e074b2b8ff0459436e55 to your computer and use it in GitHub Desktop.
This file contains 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 | |
use VDB\Spider\PersistenceHandler\FileSerializedResourcePersistenceHandler as DefaultFileSerializedResourcePersistenceHandler; | |
use Symfony\Component\Finder\Finder; | |
use VDB\Spider\PersistenceHandler\FilePersistenceHandler; | |
use VDB\Spider\Resource; | |
use VDB\Spider\PersistenceHandler\PersistenceHandlerInterface; | |
class FileSerializedResourcePersistenceHandler extends DefaultFileSerializedResourcePersistenceHandler implements PersistenceHandlerInterface{ | |
private $filePrefix=''; | |
public function setFilePrefix($filePrefix){ | |
$this->filePrefix = $filePrefix; | |
} | |
public function persist(Resource $resource) | |
{ | |
if(strpos($resource->getUri(), '_cod')>-1){ | |
$fileName = $this->filePrefix.explode('_',$resource->getUri())[1];//urlencode($resource->getUri()->toString()); | |
}else{ | |
$fileName = urlencode($resource->getUri()->toString()); | |
} | |
//echo "=== $fileName \n"; | |
$file = new \SplFileObject($this->getResultPath() . $fileName, 'w'); | |
$this->totalSizePersisted += $file->fwrite(serialize($resource)); | |
} | |
/** | |
* @return Resource | |
*/ | |
public function current() | |
{ | |
return unserialize($this->getIterator()->current()->getContents()); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment