PHPackages                             emarref/namer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. emarref/namer

AbandonedArchivedLibrary

emarref/namer
=============

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.

0.6(11y ago)3107.2k1MITPHP

Since May 7Pushed 10y ago1 watchersCompare

[ Source](https://github.com/emarref/namer)[ Packagist](https://packagist.org/packages/emarref/namer)[ Docs](https://github.com/emarref/namer)[ RSS](/packages/emarref-namer/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (1)Dependencies (2)Versions (7)Used By (0)

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.

[![Scrutinizer Code Quality](https://camo.githubusercontent.com/03b7b46c3708c04154ba340bfc50d307539bf80f16e1f89f6e0ee35135fa3fdf/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f656d61727265662f6e616d65722f6261646765732f7175616c6974792d73636f72652e706e673f733d37663431333238363735393866636665353964366637363731333437666463643434643632356133)](https://scrutinizer-ci.com/g/emarref/namer/)[![Code Coverage](https://camo.githubusercontent.com/aa10f2634fc28a1ab6bad500c10f0f95e07b331b10de735501c9909271666b12/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f656d61727265662f6e616d65722f6261646765732f636f7665726167652e706e673f733d32616331313139353634363739633438363632623163313861663738653037386333353462386162)](https://scrutinizer-ci.com/g/emarref/namer/)[![Build Status](https://camo.githubusercontent.com/843c4b0c395035b4d3083a73bad1f0ed669f36e76f0ee1f55dddef92184772f9/68747470733a2f2f7472617669732d63692e6f72672f656d61727265662f6e616d65722e737667)](https://travis-ci.org/emarref/namer)[![SensioLabsInsight](https://camo.githubusercontent.com/3f3c0575ce4e929c688978cc9293d0214533e6ec4fb1645d9468ff836ae98e23/68747470733a2f2f696e73696768742e73656e73696f6c6162732e636f6d2f70726f6a656374732f32626138316434372d353163322d343933302d616562612d3861396561623666663638352f6d696e692e706e67)](https://insight.sensiolabs.com/projects/2ba81d47-51c2-4930-aeba-8a9eab6ff685)

Install
-------

[](#install)

### Composer

[](#composer)

Add the following configuration to your composer.json file.

```
[...]
    "require": {
       "emarref/namer": "dev-master"
   }
[...]
```

then run `php ./composer.phar update emarref/namer`.

Usage
-----

[](#usage)

```
$strategy = new Emarref\Namer\Strategy\SuffixStrategy();
$detector = new Emarref\Namer\Detector\ArrayDetector(['Taken', 'Taken copy']);
$namer    = new Emarref\Namer\Namer($strategy, $detector);
echo $namer->getName('Taken'); // Will return "Taken copy 2"
```

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:

```
$namer            = $this->get('default_namer');
$unavailableNames = $repository->getUnavailableNames();
$detector         = new Emarref\Namer\Detector\ArrayDetector($unavailableNames);
echo $namer->getName('Taken', $detector);
```

### Using the Symfony2 Dependency Injection Container

[](#using-the-symfony2-dependency-injection-container)

```
parameters:
    namer.default.limit:                    100

    namer.strategy.suffix.suffix:           copy
    namer.strategy.suffix.incremental:      true
    namer.strategy.suffix.ignore_extension: true

    namer.detector.filesystem.path:         /var/www/website/web/uploads

services:
    namer.strategy.suffix:
        class:  Emarref\Namer\Strategy\SuffixStrategy
        public: false
        arguments:
            - %namer.strategy.suffix.suffix%
            - %namer.strategy.suffix.incremental%
            - %namer.strategy.suffix.ignore_extension%

    namer.detector.filesystem:
        class:  Emarref\Namer\Detector\FilesystemDetector
        public: false
        arguments:
            - %namer.detector.filesystem.path%

    namer.default:
        class:  Emarref\Namer\Namer
        public: false
        arguments:
            - @namer.strategy.suffix
            - @namer.detector.filesystem
            - %namer.default.limit%

    namer:
        alias: namer.default
```

You can then use the namer by accessing the `namer` service in the container.

### Strategies

[](#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

[](#hashstrategy)

Returns a hashed representation of the name concatenated with the index. `sha1` and `md5` are supported.

#### SuffixStrategy

[](#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

[](#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

[](#arraydetector)

Detects the existence of a value in an array.

#### FilesystemDetector

[](#filesystemdetector)

Detects the existence of a file on a filesystem.

#### GaufretteDetector

[](#gaufrettedetector)

Detects the existence of a file using a [Gaufrette](https://github.com/KnpLabs/Gaufrette) Adapter, e.g. `Gaufrette\Adapter\Local`

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity57

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 88.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~19 days

Total

6

Last Release

4295d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/c5854d7f23e12434f4eef7d4a3745f7a8776150ae66e633ea5b533c0a8b2b5cb?d=identicon)[emarref](/maintainers/emarref)

---

Top Contributors

[![emarref](https://avatars.githubusercontent.com/u/556594?v=4)](https://github.com/emarref "emarref (47 commits)")[![SamFleming](https://avatars.githubusercontent.com/u/573318?v=4)](https://github.com/SamFleming "SamFleming (6 commits)")

---

Tags

namingnamer

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/emarref-namer/health.svg)

```
[![Health](https://phpackages.com/badges/emarref-namer/health.svg)](https://phpackages.com/packages/emarref-namer)
```

###  Alternatives

[bocharsky-bw/file-naming-resolver

A lightweight library which helps to resolve a file/directory naming of uploaded files using various naming strategies.

1134.9k](/packages/bocharsky-bw-file-naming-resolver)[dragon-code/laravel-route-names

Automatic generation of route names

259.2k1](/packages/dragon-code-laravel-route-names)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
