stk2k/file-system

简单的文件系统类

0.2.3 2021-07-02 10:19 UTC

This package is auto-updated.

Last update: 2024-08-29 05:42:27 UTC


README

Latest Version on Packagist Software License Build Status Coverage Status Code Climate Total Downloads

描述

简单的文件系统类

特性

  • 简单的文件类(File)
  • 文件功能外观类(FileFacade)

用法

创建文件

use stk2k\filesystem\FileSystem;

FileSystem::put('/path/to/file', 'Hello, World');

删除文件

use stk2k\filesystem\FileSystem;

FileSystem::delete('/path/to/file');

获取文件内容

use stk2k\filesystem\FileSystem;

// getting whole content as string
$ret = FileSystem::get('/path/to/file');
echo $ret;

// getting whole content as array
$ret = FileSystem::getAsArray('/path/to/file');
print_r($ret);

设置文件内容

use stk2k\filesystem\File;
use stk2k\filesystem\FileSystem;

// putting string content
$ret = FileSystem::put('/path/to/file', 'Hello, World!');
echo $ret->get();       // Hello, World!

// putting array(of strings) content
$ret = FileSystem::put('/path/to/file', ['Foo', 'Bar']);
echo $ret->get();
// Foo
// Bar

// putting File object
file_put_contents('/path/to/file1', 'Hello, World!');
$ret = FileSystem::put('/path/to/file2', new File('/path/to/file1'));
echo $ret->get();       // Hello, World!

// putting object content(Stringable)
class MyStringableObject
{
    public function __toString() : string
    {
        return 'Hello, World!';
    }
}
$ret = FileSystem::put('/path/to/file', new MyStringableObject());
echo $ret->get();       // Hello, World!

文件对象

use stk2k\filesystem\File;

$ret = new File('/path/to/file');
echo $ret->get();

要求

PHP 7.2或更高版本

安装stk2k/file-system

安装stk2k/file-system推荐的方式是通过Composer

composer require stk2k/file-system

安装后,您需要引入Composer的自动加载器

require 'vendor/autoload.php';

许可协议

本库采用MIT许可协议。

作者

stk2k

免责声明

本软件不提供任何保修。

我们不承担使用本软件造成的任何结果的责任。

请自行承担责任。