georgeff/filesystem

此包已被放弃,不再维护。没有建议的替代包。

简单的文件系统包装器

1.2 2015-12-22 17:05 UTC

This package is auto-updated.

Last update: 2021-08-16 00:49:26 UTC


README

简单的 PHP 文件系统包装器。

安装

"georgeff/filesystem": "~1.0" 添加到您的 composer.json 文件中,并运行 composer install。

文件

namespace Georgeff\Filesystem

方法

static make()

创建 File 类的新实例

return Georgeff\Filesystem\File

exists($path)

检查文件是否存在

string $path

return bool

create($path, $content = null)

创建新文件

string $path

mixed|null $content

return int

throws Georgeff\Filesystem\Exception\FileExistsException 如果在给定路径上存在文件

get($path)

获取文件的正文

string $path

return string

throws Georgeff\Filesystem\Exception\FileNotFoundException 如果在给定路径上不存在文件

put($path, $content, $overwrite = true)

将内容写入文件。如果文件不存在,将创建文件。

string $path

mixed $content

bool|true $overwrite 如果为 true,则覆盖现有内容,如果为 false,则追加内容

return int

getJson($path)

获取 json 文件的正文作为关联数组

string $path

return array

throws Georgeff\Filesystem\Exception\FileNotFoundException

throws InvalidArgumentException 如果文件不是 json 文件

putJson($path, array $content, $overwrite = true)

将数组写入 json 文件

string $path

array $content

bool|true $overwrite

return int

throws Georgeff\Filesystem\Exception\FileNotFoundException

getRequire($path)

获取所需文件的正文

string $path

return mixed

throws Georgeff\Filesystem\Exception\FileNotFoundException

copy($path, $destination, $overwrite = true)

将文件复制到新位置

string $path

string $destination

bool|true $overwrite true - 如果文件在目标位置存在,则将其替换

return bool

throws Georgeff\Filesystem\Exception\FileExistsException 如果文件在目标位置存在且 $overwrite = false

throws Georgeff\Filesystem\Exception\FileNotFoundException

move($path, $destination, $overwrite = true)

将文件移动到新位置

string $path

string $destination

bool|true $overwrite true - 如果文件在目标位置存在,则将其替换

return bool

throws Georgeff\Filesystem\Exception\FileExistsException 如果文件在目标位置存在且 $overwrite = false

throws Georgeff\Filesystem\Exception\FileNotFoundException

delete($paths)

删除文件或文件数组

string|array $path

return bool

throws Georgeff\Filesystem\Exception\FileNotFoundException

name($path)

提取文件名

string $path

return string

throws Georgeff\Filesystem\Exception\FileNotFoundException

extension($path)

提取文件扩展名

string $path

return string

throws Georgeff\Filesystem\Exception\FileNotFoundException

mimeType($path)

返回文件的MIME类型

string $path

return string

throws Georgeff\Filesystem\Exception\FileNotFoundException

size($path)

返回文件的大小

string $path

return int

throws Georgeff\Filesystem\Exception\FileNotFoundException

lastModified($path)

返回最后修改时间戳

string $path

返回int型Unix时间戳

throws Georgeff\Filesystem\Exception\FileNotFoundException

目录

namespace Georgeff\Filesystem

方法

static make()

创建一个新的目录实例

返回 Georgeff\Filesystem\Directory

exists($path)

检查目录是否存在

string $path

return bool

create($path, $mode = 0777, $recursive = false)

创建一个新的目录

string $path

int $mode

bool|false $recursive

return bool

throws Georgeff\Filesystem\Exception\DirectoryExistsException

move($path, $destination, $options = null, $keep = false)

将目录移动到新位置

string $path

string $destination

int $options

bool|false $keep 如果为true,则原始文件将在原始位置保留

return bool

throws Georgeff\Filesystem\Exception\DirectoryNotFoundException

throws Georgeff\Filesystem\Exception\DirectoryExistsException

copy($path, $destination, $options = null)

string $path

string $destination

int|null $options

return bool

throws Georgeff\Filesystem\Exception\DirectoryNotFoundException

throws Georgeff\Filesystem\Exception\DirectoryExistsException

glob($path, $pattern = '*', $flags = 0)

根据给定的模式返回目录的内容

string $path

string $pattern

int $flags

return array

throws Georgeff\Filesystem\Exception\DirectoryNotFoundException

files($path)

返回目录内的所有文件

string $path

return array

throws Georgeff\Filesystem\Exception\DirectoryNotFoundException

filesRecursive($path)

递归返回目录内的所有文件

string $path

return array

throws Georgeff\Filesystem\Exception\DirectoryNotFoundException

directories($path)

获取给定路径内的所有目录

string $path

return array

throws Georgeff\Filesystem\Exception\DirectoryNotFoundException

delete($path, $keep = false)

删除目录

string $path

bool|false $keep 如果为true,则目录将被清空但保留

return bool

throws Georgeff\Filesystem\Exception\DirectoryNotFoundException

clear($path)

删除目录中的所有内容,但保留目录

string $path

return bool

throws Georgeff\Filesystem\Exception\DirectoryNotFoundException

工厂

namespace Georgeff\Filesystem

方法

static file()

return Georgeff\Filesystem\File

静态目录函数()

返回 Georgeff\Filesystem\Directory