mitsuru793/file-constructor

从 PHP 数组创建文件和目录。

v0.0.1 2021-01-09 18:23 UTC

This package is auto-updated.

Last update: 2024-09-10 02:01:26 UTC


README

从 PHP 数组创建文件和目录。

安装

composer mitsuru793/file-constructor

示例

<?php

$root = '/tmp/test';
$fs = new FileConstructor($root);
$fs->append([
    'dir1' => [],
    'dir2' => [
        'dir3' => [],
        'dir2-f1' => '',
    ],
    'f1' => '',
    'f2' => 'hello',
]);

// has made dirs and files
// If value is string, it's file content.

测试

您可以使用工厂方法来使用临时目录。这将使根目录作为临时目录。

<?php
$fs = FileConstructor::inTempDir();
$fs->append([
    'f1' => 'hello',
]);