Download the PHP package emarref/namer without Composer
On this page you can find all versions of the php package emarref/namer. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download emarref/namer
More information about emarref/namer
Files in emarref/namer
Package namer
Short Description A simple library for determining whether or not a given name is available for use, and generating a new name based on a strategy if it is not.
License MIT
Homepage https://github.com/emarref/namer
Informations about the package namer
Namer
This is a simple library for determining whether or not a given name is available for use, and generating a new name based on a strategy if it is not.
For example, when saving a file to a filesystem, use the Namer to determine an available filename to use that will not clash with other files on the filesystem.
Install
Composer
Add the following configuration to your composer.json file.
then run php ./composer.phar update emarref/namer
.
Usage
The detector is optional, but must be passed as the second argument to the Namer#getName()
method if it is omitted when instantiating the namer. This is useful when your namer is configured in your DI container, but you need to use a different detector. For example:
Using the Symfony2 Dependency Injection Container
You can then use the namer by accessing the namer
service in the container.
Strategies
The strategy is the class that generates a new name, based on an iteration index. It must implement the interface Emarref\Namer\Strategy\StrategyInterface
. There are currently two strategies available for use. HashStrategy
and SuffixStrategy
.
HashStrategy
Returns a hashed representation of the name concatenated with the index. sha1
and md5
are supported.
SuffixStrategy
A simple strategy that returns the name untouched on iteration 0, returns the name with suffix appended on iteration 1, and returns the name with suffix and iteration appended thereafter.
e.g. Name, Name copy, Name copy 2, Name copy 3 etc
The Suffix can also be inserted before the file extension using SuffixStrategy::setIgnoreExtension(false)
.
Detectors
The detector is the class that determines whether or not a name is available to use. A detector must implement the interface Emarref\Namer\Detector\DetectorInterface
. There are currently two simple detectors available for use. ArrayDetector
and FilesystemDetector
.
ArrayDetector
Detects the existence of a value in an array.
FilesystemDetector
Detects the existence of a file on a filesystem.
GaufretteDetector
Detects the existence of a file using a Gaufrette Adapter, e.g. Gaufrette\Adapter\Local