Added Filesystem::basename() method

This commit is contained in:
Matias Griese
2020-09-07 13:09:07 +03:00
parent c53e2843be
commit d99e1f519e
2 changed files with 23 additions and 7 deletions

View File

@@ -52,6 +52,7 @@ class Filesystem implements FilesystemInterface
* Always use Filesystem::getInstance() instead.
*
* @param bool|null $normalize
* @internal
*/
protected function __construct(bool $normalize = null)
{
@@ -127,6 +128,15 @@ class Filesystem implements FilesystemInterface
return $this->toString($scheme, $path);
}
/**
* {@inheritdoc}
* @see FilesystemInterface::basename()
*/
public function basename(string $path, ?string $suffix = null): string
{
return basename($path, $suffix);
}
/**
* {@inheritdoc}
* @see FilesystemInterface::dirname()
@@ -162,7 +172,7 @@ class Filesystem implements FilesystemInterface
* {@inheritdoc}
* @see FilesystemInterface::pathinfo()
*/
public function pathinfo(string $path, int $options = null)
public function pathinfo(string $path, ?int $options = null)
{
[$scheme, $path] = $this->getSchemeAndHierarchy($path);
@@ -201,7 +211,7 @@ class Filesystem implements FilesystemInterface
* @param int|null $options
* @return array|string
*/
protected function pathinfoInternal(?string $scheme, string $path, int $options = null)
protected function pathinfoInternal(?string $scheme, string $path, ?int $options = null)
{
if ($options) {
return \pathinfo($path, $options);

View File

@@ -28,7 +28,6 @@ interface FilesystemInterface
*
* @param string $path A filename or path, does not need to exist as a file.
* @param int $levels The number of parent directories to go up (>= 1).
*
* @return string Returns parent path.
* @throws \RuntimeException
* @api
@@ -39,13 +38,22 @@ interface FilesystemInterface
* Normalize path by cleaning up `\`, `/./`, `//` and `/../`.
*
* @param string $path A filename or path, does not need to exist as a file.
*
* @return string Returns normalized path.
* @throws \RuntimeException
* @api
*/
public function normalize(string $path): string;
/**
* Returns filename component of path.
*
* @param string $path A filename or path, does not need to exist as a file.
* @param string|null $suffix If the filename ends in suffix this will also be cut off.
* @return string
* @api
*/
public function basename(string $path, ?string $suffix = null): string;
/**
* Stream-safe `\dirname()` replacement.
*
@@ -53,7 +61,6 @@ interface FilesystemInterface
*
* @param string $path A filename or path, does not need to exist as a file.
* @param int $levels The number of parent directories to go up (>= 1).
*
* @return string Returns path to the directory.
* @throws \RuntimeException
* @api
@@ -67,9 +74,8 @@ interface FilesystemInterface
*
* @param string $path A filename or path, does not need to exist as a file.
* @param int|null $options A PATHINFO_* constant.
*
* @return array|string
* @api
*/
public function pathinfo(string $path, int $options = null);
public function pathinfo(string $path, ?int $options = null);
}