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; |
13
|
|
|
|
14
|
|
|
use Puli\Repository\Api\ChangeStream\VersionList; |
15
|
|
|
use Puli\Repository\Api\NoVersionFoundException; |
16
|
|
|
use Puli\Repository\Api\ResourceNotFoundException; |
17
|
|
|
use Puli\Repository\Api\ResourceRepository; |
18
|
|
|
use Puli\Repository\Api\UnsupportedLanguageException; |
19
|
|
|
use Webmozart\Assert\Assert; |
20
|
|
|
use Webmozart\PathUtil\Path; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Abstract base for repositories providing tools to avoid code duplication. |
24
|
|
|
* |
25
|
|
|
* @since 1.0 |
26
|
|
|
* |
27
|
|
|
* @author Bernhard Schussek <[email protected]> |
28
|
|
|
* @author Titouan Galopin <[email protected]> |
29
|
|
|
*/ |
30
|
|
|
abstract class AbstractRepository implements ResourceRepository |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
21 |
|
public function getVersions($path) |
36
|
|
|
{ |
37
|
|
|
// Non-editable repositories always contain only one version of a resource |
38
|
|
|
try { |
39
|
21 |
|
return new VersionList($path, array($this->get($path))); |
40
|
7 |
|
} catch (ResourceNotFoundException $e) { |
41
|
7 |
|
throw NoVersionFoundException::forPath($path, $e); |
42
|
|
|
} |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Validate a language is usable to search in repositories. |
47
|
|
|
* |
48
|
|
|
* @param string $language |
49
|
|
|
*/ |
50
|
325 |
|
protected function failUnlessGlob($language) |
51
|
|
|
{ |
52
|
325 |
|
if ('glob' !== $language) { |
53
|
18 |
|
throw UnsupportedLanguageException::forLanguage($language); |
54
|
|
|
} |
55
|
307 |
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Sanitize a given path and check its validity. |
59
|
|
|
* |
60
|
|
|
* @param string $path |
61
|
|
|
* |
62
|
|
|
* @return string |
63
|
|
|
*/ |
64
|
835 |
|
protected function sanitizePath($path) |
65
|
|
|
{ |
66
|
835 |
|
Assert::stringNotEmpty($path, 'The path must be a non-empty string. Got: %s'); |
67
|
807 |
|
Assert::startsWith($path, '/', 'The path %s is not absolute.'); |
68
|
|
|
|
69
|
793 |
|
return Path::canonicalize($path); |
70
|
|
|
} |
71
|
|
|
} |
72
|
|
|
|