blaspsoft/onym
Composer 安装命令:
composer require blaspsoft/onym
包简介
Onym is a lightweight Laravel package designed to generate unique, structured, and meaningful filenames effortlessly.
关键字:
README 文档
README
Onym - Flexible Filename Generator
A flexible Laravel package for generating filenames using various strategies and options.
🚀 Features
- ✅ Flexible Filename Generation – Generate filenames dynamically using various strategies.
- 🎲 Multiple Strategies – Supports
random,uuid,timestamp,date,numbered,slug, andhash. - 🔧 Customizable Output – Specify filename, extension, and additional formatting options.
- 🎯 Laravel-Friendly – Designed to work seamlessly with Laravel's filesystem and configuration.
- 📂 Human-Readable & Unique Names – Ensures filenames are structured, collision-free, and easy to understand.
- ⚙️ Configurable Defaults – Define global settings in
config/onym.phpfor consistency across your application. - 🔌 Extensible & Developer-Friendly – Easily add custom filename strategies or modify existing ones.
Installation
You can install the package via composer:
composer require blaspsoft/onym
You can publish the config file with:
php artisan vendor:publish --tag="onym-config"
Usage
Available Strategies
Random Strategy
Generates a random string of characters for the filename.
Options:
length(int): The length of the random string- Default: 16
- Example:
['length' => 8]generates "a1b2c3d4.txt"
prefix(string): String to prepend to the filename- Default: ''
- Example:
['prefix' => 'temp_']generates "temp_a1b2c3d4.txt"
suffix(string): String to append before the extension- Default: ''
- Example:
['suffix' => '_draft']generates "a1b2c3d4_draft.txt"
use Blaspsoft\Onym\Facades\Onym; // Generate an 8-character random filename with prefix and suffix Onym::make(strategy: 'random', options: [ 'length' => 8, 'prefix' => 'temp_', 'suffix' => '_draft' ]); // Result: "temp_a1b2c3d4_draft.txt" // You can also use the random method directly Onym::random(string $extension, ?array $options = [])
UUID Strategy
Generates a UUID v4 (universally unique identifier) for the filename.
Options:
prefix(string): String to prepend to the filename- Default: ''
- Example:
['prefix' => 'id_']generates "id_123e4567-e89b-12d3-a456-426614174000.txt"
suffix(string): String to append before the extension- Default: ''
- Example:
['suffix' => '_backup']generates "123e4567-e89b-12d3-a456-426614174000_backup.txt"
use Blaspsoft\Onym\Facades\Onym; // Generate a UUID filename with prefix and suffix Onym::make(strategy: 'uuid', options: [ 'prefix' => 'id_', 'suffix' => '_backup' ]); // Result: "id_123e4567-e89b-12d3-a456-426614174000_backup.txt" // You can also use the uuid method directly Onym::uuid(string $extension, ?array $options = [])
Timestamp Strategy
Adds a timestamp to the filename using PHP's DateTime formatting.
Options:
format(string): PHP DateTime format string- Default: 'Y-m-d_H-i-s'
- Common formats:
'Y-m-d_H-i-s'→ "2024-03-15_14-30-00"'YmdHis'→ "20240315143000"'U'→ Unix timestamp (e.g., "1710506400")
prefix(string): String to prepend to the filename- Default: ''
- Example:
['prefix' => 'log_']
suffix(string): String to append before the extension- Default: ''
- Example:
['suffix' => '_archive']
use Blaspsoft\Onym\Facades\Onym; // Using timestamp with prefix and suffix Onym::make('document', 'pdf', 'timestamp', [ 'format' => 'Y-m-d_H-i-s', 'prefix' => 'log_', 'suffix' => '_archive' ]); // Result: "log_2024-03-15_14-30-00_document_archive.pdf" // You can also use the timestamp method directly Onym::timestamp(string $defaultFilename, string $extension, ?array $options = [])
Date Strategy
Similar to timestamp but focused on date-only formats.
Options:
format(string): PHP DateTime format string- Default: 'Y-m-d'
- Common formats:
'Y-m-d'→ "2024-03-15"'Ymd'→ "20240315"'Y/m/d'→ "2024/03/15"
prefix(string): String to prepend to the filename- Default: ''
- Example:
['prefix' => 'dated_']
suffix(string): String to append before the extension- Default: ''
- Example:
['suffix' => '_version']
use Blaspsoft\Onym\Facades\Onym; // Using date with prefix and suffix Onym::make('document', 'pdf', 'date', [ 'format' => 'Y-m-d', 'prefix' => 'dated_', 'suffix' => '_version' ]); // Result: "dated_2024-03-15_document_version.pdf" // You can also use the date method directly Onym::date(string $defaultFilename, string $extension, ?array $options = [])
Numbered Strategy
Adds a number to the filename.
Options:
number(int): The number to append to the filename- Default: 1
- Example:
['number' => 5]
prefix(string): String to prepend to the filename- Default: ''
- Example:
['prefix' => 'rev_']
suffix(string): String to append before the extension- Default: ''
- Example:
['suffix' => '_final']
use Blaspsoft\Onym\Facades\Onym; // Adding numbers with prefix and suffix Onym::make('document', 'pdf', 'numbered', [ 'number' => 5, 'prefix' => 'rev_', 'suffix' => '_final' ]); // Result: "rev_document_5_final.pdf" // You can also use the numbered method directly Onym::numbered(string $defaultFilename, string $extension, ?array $options = [])
Slug Strategy
Converts the filename to a URL-friendly slug.
Options:
prefix(string): String to prepend to the filename- Default: ''
- Example:
['prefix' => 'post_']
suffix(string): String to append before the extension- Default: ''
- Example:
['suffix' => '_draft']
use Blaspsoft\Onym\Facades\Onym; // Converting strings to slugs with prefix and suffix Onym::make('My Document Name', 'pdf', 'slug', [ 'prefix' => 'post_', 'suffix' => '_draft' ]); // Result: "post_my-document-name_draft.pdf" // You can also use the slug method directly Onym::slug(string $defaultFilename, string $extension, ?array $options = [])
Hash Strategy
Generates a hash of the filename using various algorithms.
Options:
algorithm(string): The hashing algorithm to use- Default: 'md5'
- Available algorithms:
- 'md5' (32 characters)
- 'sha1' (40 characters)
- 'sha256' (64 characters)
- Any algorithm supported by PHP's
hash()function
prefix(string): String to prepend to the filename- Default: ''
- Example:
['prefix' => 'hash_']
suffix(string): String to append before the extension- Default: ''
- Example:
['suffix' => '_checksum']
use Blaspsoft\Onym\Facades\Onym; // Using hash with prefix and suffix Onym::make('document', 'pdf', 'hash', [ 'algorithm' => 'md5', 'prefix' => 'hash_', 'suffix' => '_checksum' ]); // Result: "hash_86985e105f79b95d6bc918fb45ec7727_checksum.pdf" // You can also use the hash method directly Onym::hash(string $defaultFilename, string $extension, ?array $options = [])
Global Configuration
You can set default values for all strategies in your config/onym.php file:
return [ // Default filename when none is provided 'default_filename' => 'file', // Default extension when none is provided 'default_extension' => 'txt', // Default strategy when none is specified 'strategy' => 'random', // Default options for all strategies 'options' => [ 'random' => [ 'length' => 16, 'prefix' => '', 'suffix' => '', ], 'timestamp' => [ 'format' => 'Y-m-d_H-i-s', 'prefix' => '', 'suffix' => '', ], 'date' => [ 'format' => 'Y-m-d', 'prefix' => '', 'suffix' => '', ], 'numbered' => [ 'number' => 1, 'separator' => '_', 'prefix' => '', 'suffix' => '', ], 'hash' => [ 'algorithm' => 'md5', 'length' => 16, 'prefix' => '', 'suffix' => '', ], ], ];
These defaults can be overridden on a per-call basis using the options parameter in the make() and in all strategy methods.
License
Blasp is open-sourced software licensed under the MIT license.
blaspsoft/onym 适用场景与选型建议
blaspsoft/onym 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 41.5k 次下载、GitHub Stars 达 122, 最近一次更新时间为 2025 年 03 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「blaspsoft」 「onym」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 blaspsoft/onym 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 blaspsoft/onym 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 blaspsoft/onym 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Blasp is a powerful and customisable profanity filter package for Laravel applications
Doxswap is a simple document conversion package for Laravel which uses LibreOffice to convert documents to a variety of formats.
SocialitePlus is a Laravel package that simplifies social authentication by extending Laravel Socialite. It provides predefined Google, Facebook, GitHub, and LinkedIn login options for seamless integration into Laravel 12 Vue and React Starter Kits
Token Forge brings Laravel Jetstream token management over to Laravel Breeze
A React & Inertia-powered API key management system for Laravel 12 React Starterkit, with secure token generation, revocation, and authentication.
A Vue & Inertia-powered API key management system for Laravel 12 Vue Starterkit, with secure token generation, revocation, and authentication.
统计信息
- 总下载量: 41.5k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 122
- 点击次数: 43
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-03-04