| 1 |
<?php |
| 2 |
|
| 3 |
namespace League\Flysystem\Adapter; |
| 4 |
|
| 5 |
use League\Flysystem\AdapterInterface; |
| 6 |
|
| 7 |
abstract class AbstractAdapter implements AdapterInterface |
| 8 |
{ |
| 9 |
/** |
| 10 |
* @var string|null path prefix |
| 11 |
*/ |
| 12 |
protected $pathPrefix; |
| 13 |
|
| 14 |
/** |
| 15 |
* @var string |
| 16 |
*/ |
| 17 |
protected $pathSeparator = '/'; |
| 18 |
|
| 19 |
/** |
| 20 |
* Set the path prefix. |
| 21 |
* |
| 22 |
* @param string $prefix |
| 23 |
* |
| 24 |
* @return void |
| 25 |
*/ |
| 26 |
public function setPathPrefix($prefix) |
| 27 |
{ |
| 28 |
$prefix = (string) $prefix; |
| 29 |
|
| 30 |
if ($prefix === '') { |
| 31 |
$this->pathPrefix = null; |
| 32 |
|
| 33 |
return; |
| 34 |
} |
| 35 |
|
| 36 |
$this->pathPrefix = rtrim($prefix, '\\/') . $this->pathSeparator; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Get the path prefix. |
| 41 |
* |
| 42 |
* @return string|null path prefix or null if pathPrefix is empty |
| 43 |
*/ |
| 44 |
public function getPathPrefix() |
| 45 |
{ |
| 46 |
return $this->pathPrefix; |
| 47 |
} |
| 48 |
|
| 49 |
/** |
| 50 |
* Prefix a path. |
| 51 |
* |
| 52 |
* @param string $path |
| 53 |
* |
| 54 |
* @return string prefixed path |
| 55 |
*/ |
| 56 |
public function applyPathPrefix($path) |
| 57 |
{ |
| 58 |
return $this->getPathPrefix() . ltrim($path, '\\/'); |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Remove a path prefix. |
| 63 |
* |
| 64 |
* @param string $path |
| 65 |
* |
| 66 |
* @return string path without the prefix |
| 67 |
*/ |
| 68 |
public function removePathPrefix($path) |
| 69 |
{ |
| 70 |
return substr($path, strlen((string) $this->getPathPrefix())); |
| 71 |
} |
| 72 |
} |
| 73 |
|