1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the puli/repository package. |
5
|
|
|
* |
6
|
|
|
* (c) Bernhard Schussek <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Puli\Repository\Resource; |
13
|
|
|
|
14
|
|
|
use Puli\Repository\Api\Resource\FilesystemResource; |
15
|
|
|
use Puli\Repository\Resource\Metadata\FilesystemMetadata; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Base class for filesystem resources. |
19
|
|
|
* |
20
|
|
|
* @since 1.0 |
21
|
|
|
* |
22
|
|
|
* @author Bernhard Schussek <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
abstract class AbstractFilesystemResource extends GenericResource implements FilesystemResource |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @var string |
28
|
|
|
*/ |
29
|
|
|
private $filesystemPath; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Creates a new filesystem resource. |
33
|
|
|
* |
34
|
|
|
* @param string $filesystemPath The path on the file system. |
35
|
|
|
* @param string|null $path The repository path of the resource. |
36
|
|
|
*/ |
37
|
658 |
|
public function __construct($filesystemPath, $path = null) |
38
|
|
|
{ |
39
|
658 |
|
parent::__construct($path); |
40
|
|
|
|
41
|
658 |
|
$this->filesystemPath = str_replace(DIRECTORY_SEPARATOR, '/', $filesystemPath); |
42
|
658 |
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* {@inheritdoc} |
46
|
|
|
*/ |
47
|
411 |
|
public function getFilesystemPath() |
48
|
|
|
{ |
49
|
411 |
|
return $this->filesystemPath; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* {@inheritdoc} |
54
|
|
|
*/ |
55
|
|
|
public function getMetadata() |
56
|
|
|
{ |
57
|
|
|
return new FilesystemMetadata($this->filesystemPath); |
58
|
|
|
} |
59
|
|
|
|
60
|
32 |
|
protected function preSerialize(array &$data) |
61
|
|
|
{ |
62
|
32 |
|
parent::preSerialize($data); |
63
|
|
|
|
64
|
32 |
|
$data[] = $this->filesystemPath; |
65
|
32 |
|
} |
66
|
|
|
|
67
|
24 |
|
protected function postUnserialize(array $data) |
68
|
|
|
{ |
69
|
24 |
|
$this->filesystemPath = array_pop($data); |
70
|
|
|
|
71
|
24 |
|
parent::postUnserialize($data); |
72
|
24 |
|
} |
73
|
|
|
} |
74
|
|
|
|