mattgorle/filename-suffixer 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

mattgorle/filename-suffixer

最新稳定版本:0.2.1

Composer 安装命令:

composer require mattgorle/filename-suffixer

包简介

Ensures unique filenames by adding a numeric suffix

README 文档

README

Ensures that filenames are unique by appending a suffix to the filename.

If a file with $filename does not already exist, then the original filename is offered instead of an altered one.

Examples

For a file named test_file.txt, FilenameSuffixer::suffix will return:

  • test_file.txt if the file does not exist
  • test_file-1.txt if a file called test_file.txt already exists
  • test_file-2.txt if files called test_file.txt and test_file-1.txt already exist
  • etc...

Versioning

This project follows semantic versioning.

Installation

composer require mattgorle/filename-suffixer

Usage

use Gorle\FilenameSuffixer\FilenameSuffixer;

$filename = 'your_file.jpg'

$safeFilename = FilenameSuffixer::suffix($filename); 
// - your_file.jpg if the file does not already exist
// - your_file-1.jpg if your_file.jpg already exists
// - your_file-2.jpg if your_file-1.jpg already exists
// - etc...

Customising behaviour

I have tried to select sensible defaults, but you can modify several parameters to suit your individual use case by changing the value of the static properties on FilenameSuffixer.

You can customise the following:

Option Default Value Property
File extension separator . FilenameSuffixer::$extensionSeparator
Suffix separator - FilenameSuffixxer::$suffixSeparator
Path separator / FilenameSuffixer::$pathSeparator
Suffix starting number 1 FilenameSuffixer::$suffixStartsAt

Examples

use Gorle\FilenameSuffixer\FilenameSuffixer;

FilenameSuffixer::$extensionSeparator = '_'; 
FilenameSuffixer::$pathSeparator = ':';
FilenameSuffixer::$suffixStartsAt = 31;
FilenameSuffixer::$suffixSeparator = '_';

Resetting the suffixer after changing defaults

Help, I've changed loads of stuff and now I can't find my way back!!! 😭

Simply call FilenameSuffixer::reset() and the initial defaults will be reinstated.

Honestly, I don't know if this is going to be a useful feature - it came up in testing and it feels more like a consequence of implementing this as a static class. Probably needs some thought!

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: mit
  • 更新时间: 2021-08-14