Completed
Push — master ( 665782...a8382c )
by Matthijs
04:42 queued 02:50
created

FileSerializedResourcePersistenceHandler::getFileSystemPath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
/**
3
 * @author Matthijs van den Bos <[email protected]>
4
 * @copyright 2013 Matthijs van den Bos
5
 */
6
7
namespace VDB\Spider\PersistenceHandler;
8
9
use Symfony\Component\Finder\Finder;
10
use VDB\Spider\PersistenceHandler\FilePersistenceHandler;
11
use VDB\Spider\Resource;
12
13
class FileSerializedResourcePersistenceHandler extends FilePersistenceHandler implements PersistenceHandlerInterface
14
{
15
    public function persist(Resource $resource)
16
    {
17
        $path = $this->getResultPath() . $this->getFileSystemPath($resource);
18
        if (!is_dir($path)) {
19
            mkdir($path, 0777, true);
20
        }
21
        $file = new \SplFileObject($path . DIRECTORY_SEPARATOR . $this->getFileSystemFilename($resource), 'w');
22
        $this->totalSizePersisted += $file->fwrite(serialize($resource));
23
    }
24
25
    /**
26
     * @return Resource
27
     */
28
    public function current()
29
    {
30
        return unserialize($this->getIterator()->current()->getContents());
31
    }
32
}
33