majiameng /
uploads
| 1 | <?php |
||||
| 2 | namespace tinymeng\uploads\Connector; |
||||
| 3 | |||||
| 4 | /** |
||||
| 5 | * 所有第三方上传类必须继承的抽象类 |
||||
| 6 | */ |
||||
| 7 | abstract class Gateway implements GatewayInterface |
||||
| 8 | { |
||||
| 9 | /** |
||||
| 10 | * 配置信息 |
||||
| 11 | * |
||||
| 12 | * @var |
||||
| 13 | */ |
||||
| 14 | protected $config; |
||||
| 15 | |||||
| 16 | /** |
||||
| 17 | * @var string|null path prefix |
||||
| 18 | */ |
||||
| 19 | protected $pathPrefix; |
||||
| 20 | |||||
| 21 | /** |
||||
| 22 | * @var string |
||||
| 23 | */ |
||||
| 24 | protected $pathSeparator = '/'; |
||||
| 25 | /** |
||||
| 26 | * @var |
||||
| 27 | */ |
||||
| 28 | protected $client; |
||||
| 29 | |||||
| 30 | |||||
| 31 | /** |
||||
| 32 | * Gateway constructor. |
||||
| 33 | * @param null $config |
||||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||||
| 34 | * @throws \Exception |
||||
| 35 | */ |
||||
| 36 | public function __construct($config = null) |
||||
| 37 | { |
||||
| 38 | if (!$config) { |
||||
|
0 ignored issues
–
show
|
|||||
| 39 | throw new \Exception('传入的配置不能为空'); |
||||
| 40 | } |
||||
| 41 | $this->config = $config; |
||||
| 42 | } |
||||
| 43 | |||||
| 44 | /** |
||||
| 45 | * Set the path prefix. |
||||
| 46 | * @param string $prefix |
||||
| 47 | * @return void |
||||
| 48 | */ |
||||
| 49 | public function setPathPrefix($prefix) |
||||
| 50 | { |
||||
| 51 | $prefix = (string) $prefix; |
||||
| 52 | |||||
| 53 | if ($prefix === '') { |
||||
| 54 | $this->pathPrefix = null; |
||||
| 55 | return; |
||||
| 56 | } |
||||
| 57 | |||||
| 58 | $this->pathPrefix = rtrim($prefix, '\\/') . $this->pathSeparator; |
||||
| 59 | } |
||||
| 60 | |||||
| 61 | /** |
||||
| 62 | * Get the path prefix. |
||||
| 63 | * @return string|null path prefix or null if pathPrefix is empty |
||||
| 64 | */ |
||||
| 65 | public function getPathPrefix() |
||||
| 66 | { |
||||
| 67 | return $this->pathPrefix; |
||||
| 68 | } |
||||
| 69 | |||||
| 70 | /** |
||||
| 71 | * Prefix a path. |
||||
| 72 | * @param string $path |
||||
| 73 | * @return string prefixed path |
||||
| 74 | */ |
||||
| 75 | public function applyPathPrefix($path) |
||||
| 76 | { |
||||
| 77 | return $this->getPathPrefix() . ltrim($path, '\\/'); |
||||
| 78 | } |
||||
| 79 | |||||
| 80 | /** |
||||
| 81 | * Remove a path prefix. |
||||
| 82 | * @param string $path |
||||
| 83 | * @return string path without the prefix |
||||
| 84 | */ |
||||
| 85 | public function removePathPrefix($path) |
||||
| 86 | { |
||||
| 87 | return substr($path, strlen($this->getPathPrefix())); |
||||
|
0 ignored issues
–
show
It seems like
$this->getPathPrefix() can also be of type null; however, parameter $string of strlen() does only seem to accept string, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 88 | } |
||||
| 89 | |||||
| 90 | |||||
| 91 | } |
||||
| 92 |