承接 dnj/local-filesystem 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

dnj/local-filesystem

Composer 安装命令:

composer require dnj/local-filesystem

包简介

Local disk implementation of dnj/filesystem

README 文档

README

Latest Version on Packagist Total Downloads Software License Testing status

Introduction

This is a simple implemenetation of DNJ\FileSystem for local disk based file system.

How To Use

This is an implementation of local disk filesystem that allows you to work with local files.
First of all, you need to add this library to your project, so run:

composer require dnj/local-filesystem

File basic usage:

Read file:

<?php
use dnj\Filesystem\Local\File;

$file = new File('/etc/hosts');
$content = $file->read();
echo $content; // prints: 127.0.0.1       localhost 

Write file:

<?php
use dnj\Filesystem\Local\File;

$file = new File('~/adele-hello.txt');

$lyrics = <<<EOF
Hello, it's me
I was wondering if after all these years you'd like to meet
To go over everything
They say that time's supposed to heal ya, but I ain't done much healing
EOF;

try {
    $file->write($lyrics);
} catch (IOException $e) {
    // in case failed for any reason, like permission denied
}

Rename file:

<?php
use dnj\Filesystem\Local\File;


$file = new File('~/adele-hello.txt');
$lyrics = <<<EOF
I heard that you're settled down
That you found a girl and you're married now
I heard that your dreams came true
Guess she gave you things, I didn't give to you
Old friend, why are you so shy?
EOF;

try {
    $file->write($lyrics);
} catch (IOException $e) {
    // in case failed for any reason, like permission denied, ...
}


try {
    $file->rename('adele-someone-like-you.txt');

    // or you can completly move this file to new dest:
    $destFile = new File('/tmp/adele-someone-like-you.txt');
    $file->move($destFile);
} catch (IOException $e) {
    // in case failed for any reason, like permission denied, ...
}

Get size of file:

<?php
use dnj\Filesystem\Local\File;

$file = new File('/etc/hosts');
echo $file->size(); // prints the size of file in bytes

Existence of file and touch it (create it) if not exists:

<?php
use dnj\Filesystem\Local\File;

$file = new File('~/dnj-does-file-exists.txt');
echo 'file ' . ($file->exists() ? 'exists.' : 'not exists!');

if ($file->exists()) {
    echo 'File exists.' . PHP_EOL;
} else {
    echo 'File does not exists!' . PHP_EOL;
    // touch file
    $file->touch();
}

Delete file:

<?php
use dnj\Filesystem\Local\File;

$file = new File('~/test-dnj-delete-file.txt');
$file->write('Hello World!');
$file->delete();

Append to file:

<?php
use dnj\Filesystem\Local\File;

$file = new File('~/hello-world.txt');
$file->write('Hello');
echo $file->read(); // prints: Hello

$file->append(' World!');
echo $file->read(); // prints: Hello World!

Directory basic usage:

Check directory existence:

<?php
use dnj\Filesystem\Local\Directory;

$dir = new Directory('~/dnj/');
$dir->exists(); // return bool

Make directory:

<?php
use dnj\Filesystem\Local\Directory;

$dir = new Directory('~/dnj/');
$dir->make();
// or:
$recursive = true;
$dir->make($recursive, 0700); // make recursivley with permission 0700

Get files of directory:

<?php
use dnj\Filesystem\Local\Directory;

$dir = new Directory('/tmp/');
if ($dir->exists()) {
    // $directory->file() returns Generator of dnj\Filesystem\Local\File;
    $recursive = false;
    foreach ($directory->files($recursive) as $file) {
        echo $file->getPath() . PHP_EOL;
    }
}

Get directories of directory:

<?php
use dnj\Filesystem\Local\Directory;

$parent = new Directory('/tmp/');
if ($dir->exists()) {
    // $directory->directories() returns Generator of dnj\Filesystem\Local\Directory;
    $recursive = false;
    foreach ($parent->directories($recursive) as $directory) {
        echo $directory->getPath() . PHP_EOL;
    }
}

Get directories of directory:

<?php
use dnj\Filesystem\Local\Directory;

$dir = new Directory('/tmp/');
if ($dir->exists()) {
    // $directory->file() returns Generator of dnj\Filesystem\Local\File;
    $recursive = false;
    foreach ($directory->files($recursive) as $file) {
        echo $file->getPath() . PHP_EOL;
    }
}

Get items (files and directories) of directory:

<?php
use dnj\Filesystem\Local\Directory;

$dir = new Directory('/tmp/');
if ($dir->exists()) {
    // $directory->file() returns Generator of dnj\Filesystem\Local\File|dnj\Filesystem\Local\Directory;
    $recursive = false;
    foreach ($directory->items($recursive) as $node) {
        echo $node->getPath() . PHP_EOL;
    }
}

Get size of a directory:

<?php
use dnj\Filesystem\Local\Directory;

$dir = new Directory('/tmp/');
$recursively = true;
echo $dir->size($recursively); // prints the size of directory and all of it's contents

Get file from directory:

<?php
use dnj\Filesystem\Local\Directory;

$parent = new Directory('/tmp/');
$file = $parent->file('test-file.txt');
$file->write('https://dnj.co.ir');

echo $file->getPath(); // prints: /tmp/test-file.txt

Get directory from directory:

<?php
use dnj\Filesystem\Local\Directory;

$parent = new Directory('/tmp/');
$directory = $parent->file('test-directory');
$directory->make();

echo $directory->getPath(); // prints: /tmp/test-directory

Delete directory:

<?php
use dnj\Filesystem\Local\Directory;

$parent = new Directory('/tmp/');
$directory = $parent->file('test-directory');
$directory->make();

echo $directory->getPath(); // prints: /tmp/test-directory

$directory->delete(); // delete directory and all of it's content

About

We'll try to maintain this project as simple as possible, but Pull Requests are welcomed!

License

The MIT License (MIT). Please see License File for more information.

dnj/local-filesystem 适用场景与选型建议

dnj/local-filesystem 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.82k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 09 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 dnj/local-filesystem 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 dnj/local-filesystem 我们能提供哪些服务?
定制开发 / 二次开发

基于 dnj/local-filesystem 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-09-26