honth/filehandler

此包已被废弃,不再维护。未建议替代包。

此包允许轻松读取和操作系统文件。

v1.0.0 2016-08-01 19:09 UTC

This package is not auto-updated.

Last update: 2016-10-29 12:21:50 UTC


README

此包允许轻松读取和操作系统文件。

如何安装

此包使用 Composer。要使用 Composer 安装,只需在您的项目控制台执行以下操作

composer require honth/filehandler

如果您没有 Composer,您可以从 GitHub 下载其 zip 文件。

安装完成后,您需要设置项目根目录。这不是必需的,但在传递目录数组时,生成的路径将添加项目根目录。

如何使用

Filesystem 允许您在系统中操作文件。请记住,Filesystem 使用 file_put_contents() 来写入文件。这意味着最好收集文件的所有内容,然后一次性写入。

使用 Filesystem 和 File 的示例

<?php

use Honth\FileHandler\File;
use Honth\FileHandler\Filesystem;
use Honth\FileHandler\Path;

require "vendor/autoload.php";

Path::setProjectRoot(__DIR__);

Filesystem::mkdir(Path::make(__DIR__ . "/bin/log/"));
// Both of these works but the second one requires that you have set the project root.
Filesystem::mkdir(Path::make(["bin", "log"]));

$file = new File(Path::make(["bin", "log"], "info.log"));
$file->write("Hello World!");

$file->rename(__DIR__ . "/test.log");

Fileloader

此类允许您轻松加载 PHP 文件。您还可以传递在加载文件时发送的数据。当使用框架时,将任务分割到不同的文件中时,这可能很有用。

Fileloader::load("example.php", ["app" => $app]);

// Meanwhile in example.php:
$app->something();

JSON

此类允许您加载和保存 JSON 文件。

$jsonData = JSON::load(__DIR__ . "/composer.json");
JSON::save($jsonData, __DIR__ . "/composer-copy.json");

许可

这是一个开源软件,在 MIT 许可证 下授权。