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\ResourceRepository; |
15
|
|
|
use Puli\Repository\Api\UnsupportedLanguageException; |
16
|
|
|
use Puli\Repository\ChangeStream\ResourceStack; |
17
|
|
|
use Webmozart\Assert\Assert; |
18
|
|
|
use Webmozart\PathUtil\Path; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Abstract base for repositories providing tools to avoid code duplication. |
22
|
|
|
* |
23
|
|
|
* @since 1.0 |
24
|
|
|
* |
25
|
|
|
* @author Bernhard Schussek <[email protected]> |
26
|
|
|
* @author Titouan Galopin <[email protected]> |
27
|
|
|
*/ |
28
|
|
|
abstract class AbstractRepository implements ResourceRepository |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* {@inheritdoc} |
32
|
|
|
*/ |
33
|
|
|
public function getStack($path) |
34
|
|
|
{ |
35
|
|
|
// The basic repositories are not editable: you cannot have multiple versions of the same resource. |
36
|
|
|
return new ResourceStack(array($this->get($path))); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Validate a language is usable to search in repositories. |
41
|
|
|
* |
42
|
|
|
* @param string $language |
43
|
|
|
*/ |
44
|
214 |
|
protected function validateSearchLanguage($language) |
45
|
|
|
{ |
46
|
214 |
|
if ('glob' !== $language) { |
47
|
10 |
|
throw UnsupportedLanguageException::forLanguage($language); |
48
|
|
|
} |
49
|
204 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* Sanitize a given path and check its validity. |
53
|
|
|
* |
54
|
|
|
* @param string $path |
55
|
|
|
* |
56
|
|
|
* @return string |
57
|
|
|
*/ |
58
|
556 |
|
protected function sanitizePath($path) |
59
|
|
|
{ |
60
|
556 |
|
Assert::stringNotEmpty($path, 'The path must be a non-empty string. Got: %s'); |
61
|
536 |
|
Assert::startsWith($path, '/', 'The path %s is not absolute.'); |
62
|
|
|
|
63
|
526 |
|
return Path::canonicalize($path); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|