Download the PHP package bocharsky-bw/file-naming-resolver without Composer
On this page you can find all versions of the php package bocharsky-bw/file-naming-resolver. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download bocharsky-bw/file-naming-resolver
More information about bocharsky-bw/file-naming-resolver
Files in bocharsky-bw/file-naming-resolver
Package file-naming-resolver
Short Description A lightweight library which helps to resolve a file/directory naming of uploaded files using various naming strategies.
License MIT
Homepage https://github.com/bocharsky-bw/FileNamingResolver
Informations about the package file-naming-resolver
FileNamingResolver
A lightweight library which helps to resolve a file/directory naming of uploaded files using various naming strategies.
This library solves only naming things and do nothing with any files or directories directly. If you are looking for some filesystem abstraction layer - looks closer to Gaufrette, symfony/filesystem or Flysystem libraries.
Contents
- Requirements
- Installation
- Usage
- FileInfo
- Strategy list
- AggregateNamingStrategy
- CallbackNamingStrategy
- ContentHashNamingStrategy
- DatetimeNamingStrategy
- HashNamingStrategy
- Example
- Contribution
Requirements
This library is standalone without any dependencies. To use it in your project ensure you correspond to the next requirements:
- PHP
5.3
or higher
Installation
The preferred way to install this package is to use Composer:
If you don't use Composer
- register this package in your autoloader manually
following PSR-4 autoloader standard or simply download this library and
require
the necessary files directly in your scripts:
Usage
First of all, before using file naming resolver, you should determine which naming
strategy to use. You can use different strategies out-of-the-box or easily create
your own one by implementing the NamingStrategyInterface
interface or extends the
AbstractNamingStrategy
class which already implemented it for you.
NOTE: In all examples hereinafter the
__DIR__
equals to/var/www/html/web
.
FileInfo
The FileNamingResolver\FileInfo
class extends \SplFileInfo
object. For more info
check the SplFileInfo. Below shown list of frequently used getters of this class:
Strategy list
AggregateNamingStrategy
This naming strategy allows to use as many naming strategies as you need at once. Its aggregate results. Each new result pathname based on the previous one.
To reverse applying order of strategies pass true
as second parameter to the
constructor of AggregateNamingStrategy
class:
CallbackNamingStrategy
This naming strategy allows create a custom naming logic using custom callbacks.
ContentHashNamingStrategy
The naming behavior of hash naming strategy looks like Twig naming of cached files.
NOTE: Be sure that source file really exist before using
ContentHashNamingStrategy
otherwise anInvalidArgumentException
will be thrown. You probably need to use aisFile()
method onFileInfo
object to be sure that file exists. It's necessary because this naming strategy try to hash a real file content.
DatetimeNamingStrategy
The naming behavior of datetime naming strategy looks like WordPress naming of uploaded media files.
HashNamingStrategy
The naming behavior of hash naming strategy looks like Twig naming of cached files.
Example
There is a full working example how to upload files with a simple HTML form and built-in PHP functions using FileNamingResolver library.
Contribution
Feel free to submit an Issue or create a Pull Request if you find a bug or just want to propose an improvement suggestion.
In order to propose a new feature, the best way is to submit an Issue and discuss it first.
Move UP