定制 gspataro/filesystem 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

gspataro/filesystem

最新稳定版本:1.0.0

Composer 安装命令:

composer require gspataro/filesystem

包简介

A PHP FileSystem component

关键字:

README 文档

README

A component to easily manage the files and directories of your application.

Installation

Requires PHP 8.0+

Require the component using Composer

composer require gspataro/filesystem

Quick start

To start using the FileSystem component you only need to initialize the Storage class. This will give you easy access to the files and directories present on your application's filesystem.

<?php

use GSpataro\FileSystem\Storage;

/**
 * The storage class gives you easy access to files and directories in your root folder
 * 
 * @param string $root The path of your root
 */

$storage = new Storage(__DIR__);

/**
 * Open a file
 * 
 * @param string $path The path to the file (exluding root)
 */

$storage->openFile("document.txt"); // Will open: __DIR__ . '/document.txt'

/**
 * Open a directory
 * 
 * @param string $path The path to the directory (exluding root)
 */

$storage->openDir("directory"); // Will open: __DIR__ . '/directory'

File and Directory classes

You can also instanciate File and Directory classes outside of the storage class. This will give you more flexibility in some cases. Both classes have some methods in common:

<?php

use GSpataro\FileSystem\File;
use GSpataro\FileSystem\Directory;

$file = new File(__DIR__ . '/document.txt');
$directory = new Directory(__DIR__ . '/document');

/**
 * Verify if the file/directory exists
 */

$file->exists();
$directory->exists();

// This variant throws an exeption if the file/directory does not exist

$file->existsOrDie();
$directory->existsOrDie();

/**
 * Write or create a file
 * 
 * @param mixed $content          The content to write
 * @param bool  $overwrite = true If true, overwrite the existing content, otherwise add the new content at the end of the file
 */

$file->write("Lorem ipsum");

/**
 * Create a directory
 * 
 * @param bool $recursive = false  If true, create all the non existing directories present in the path
 * @param bool $permissions = 0777 Define the permissions of the directory
 */

$directory->write();

/**
 * Read a file/directory
 * 
 * File:      return the content of the file
 * Directory: return the content of the directory as File/Directory objects contained in an array
 */

$file->read();
$directory->read();

/**
 * Delete a file
 */

$file->delete();

/**
 * Delete a directory
 * 
 * @param bool $recursive = false If true, delete the directory and its content, otherwise delete the directory only if empty
 */

$directory->delete(true);

/**
 * Move/copy a file/directory
 * 
 * Directory: this will also move/copy the content of the directory
 * @param bool $overwrite = false If true, overwrite the new path
 */

$file->move(__DIR__ . '/moved_document.txt');
$file->copy(__DIR__ . '/copied_documen.txt');

$directory->move(__DIR__ . '/moved_directory');
$directory->copy(__DIR__ . '/copied_directory');

Directory only methods

<?php

/**
 * Verify if the directory is empty
 * 
 * @return bool
 */

$directory->empty();

File only methods

<?php

/**
 * Verify if the file matches one or more extensions
 * 
 * @param string|array $extensions
 * @return bool
 */

$file->matchExtensions("txt");

// This variant throws an exception if the file doesn't match the given extension/s

$file->matchExcentionsOrDie(["txt", "md"]);

/**
 * Require PHP file
 * 
 * @return mixed
 */

$file->import();

统计信息

  • 总下载量: 11
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-03-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固