PHPackages                             diezz/url-shortener - 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. diezz/url-shortener

ActiveCakephp-plugin

diezz/url-shortener
===================

UrlShortener plugin for CakePHP

0.1.2(8y ago)03MITPHPPHP &gt;=7.1

Since Nov 22Pushed 8y ago1 watchersCompare

[ Source](https://github.com/ww-stas/UrlShortener)[ Packagist](https://packagist.org/packages/diezz/url-shortener)[ RSS](/packages/diezz-url-shortener/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (3)Versions (4)Used By (0)

UrlShortener plugin for CakePHP
===============================

[](#urlshortener-plugin-for-cakephp)

This plugin allow to shorten long urls. For example you have a long url like this
`http://domain.com/events/follow?event_id=3D8e296a067a37563370ded05f5a3bf3ec&refer=IuyNqrcLQaqPhjzhFiCARg__.3600 .1282755600-761405628%26fb_sig_ss%3DigFqJKrhJZWGSRO`
This plugin can shorten this url to
`http://domain.com/NjdhMz`
and after user follow this short url plugin will redirect you to original url.

Installation
------------

[](#installation)

You can install this plugin into your CakePHP application using [composer](http://getcomposer.org).

The recommended way to install composer packages is:

```
composer require diezz/url-shortener

```

Note
----

[](#note)

This package has DataProviderInterface dependency which implementation is not provided. You should implement `DataProviderInterface` in your source and provide it in the App config file. You may use any external storage that you like: Redis, Mongo, MySql, files and so on. In order to prevent collisions `DataProviderInterface::put()` method should throw `UrlShortener\DuplicateKeyException` if presented key is not unique.

Configuration
-------------

[](#configuration)

Define next section in the App config file

```
'UrlShortener' => [
    // Requeried. Data Provider Implementation.
    // Full class name should be provided.
    'dataProveder' => YourImplementation::class,
    // Optional. Short url hash length. By default 6
    'urlLength' => 6,
    // Optional. Whether retry if catch DuplicateKeyException
    // By default false
    'retryOnDuplicate' => false,
    //Optioanal. Base url of short url.
    // If this param not set App.appBaseUrl will be used as baseUrl
    'baseUrl' => 'http://domain.com',
    // Optional. Short url path. By default null,
    // This value will be inserted between base url and short url hash
    // and short url will be looking like this http://domain.com/l/MnNQLC
    'shortUrlPath' => 'l',
]
```

at the end of `config/bootstrap.php` write next lines:

```
    Plugin::load('UrlShortener', ['bootstrap' => false, 'routes' => true]);
```

or just run

```
bin/cake plugin load UrlShortener

```

Usage
-----

[](#usage)

Create short url

```
    $urlShortener = new UrlShortener();
    $shortUrl = $urlShortener->shorten('https://domain.com/some_mega_supper_pupper_long_url');
    // $shortUlr = 'http://domain.com/l/MnNQLC'
```

You can set manually short url

```
    $shortUrl = $urlShortener->shorten('https://domain.com/some_mega_supper_pupper_long_url', 'one');
    // $shortUlr = 'http://domain.com/l/one'
```

Plugin is providing two methods for expanding full url.

```
    //expand full url in controller
    $fullUrl = $urlShortener->expandByRequest($this->request);

    //expand url anywhere
    $fullUrl = $urlShortener->expandByHash($shortUrlHash);
```

Plugin contain Facade class for convenient UrlShortener usage

```
    use UrlShortener/Facade as UrlShortener;

    //create short url
    $shortUrl = UrlShortener::shorten('https://domain.com/some_mega_supper_pupper_long_url');

    //expand full url
    $fullUrl = UrlShortener::expandByRequest($this->request);
```

Plugin have default short url hash generator but you may define custom generator by passing callback into `setHashGenerator` method.

```
$urlShortener = new UrlShortener();
$urlShortener->setHashGenerator(function($fullUrl) {
    return uniqid($fullUrl);
});
```

Other way to set user defined generator is to define it in the UrlShortener config

```
//Define some class in your sorce
class Generator {
    public static generate(string $fullUrl): string
    {
        return uniqid($fullUrl);
    }
}

//app config
'UrlShortener' => [
    ...
    'hashGenerator' => [Generator::class, 'generate']
]
```

**UrlShortener** support next events:

- `url.shortener.event.before.expand`
- `url.shortener.event.after.expand`
- `url.shortener.event.expand.fail`
- `url.shortener.event.before.shorten`
- `url.shortener.event.after.shorten`
- `url.shortener.event.shorten.fail`

You can set event listeners for each event for extending plugin functionality for example logging or counting hits.

```
EventManager::instance()->on(UrlShortener::EVENT_EXPAND_FAIL, function(Event $event) {
    $shortUrl = $event->data['shortUrl'];
    Log::write('error', 'Unable to expand url: ' . $shortUrl);
});
```

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity3

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~0 days

Total

3

Last Release

3095d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/62e53a479b35571b0568e744289f5b1d73ac04307e65460d5a4b4f0afa63da7e?d=identicon)[diezz](/maintainers/diezz)

---

Top Contributors

[![ww-stas](https://avatars.githubusercontent.com/u/4198465?v=4)](https://github.com/ww-stas "ww-stas (6 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/diezz-url-shortener/health.svg)

```
[![Health](https://phpackages.com/badges/diezz-url-shortener/health.svg)](https://phpackages.com/packages/diezz-url-shortener)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.6k509.9M17.0k](/packages/laravel-framework)[craftcms/cms

Craft CMS

3.6k3.6M2.6k](/packages/craftcms-cms)[danog/madelineproto

Async PHP client API for the telegram MTProto protocol.

3.4k855.0k18](/packages/danog-madelineproto)[league/uri-components

URI components manipulation library

31932.3M67](/packages/league-uri-components)[symfony/html-sanitizer

Provides an object-oriented API to sanitize untrusted HTML input for safe insertion into a document's DOM.

27932.2M63](/packages/symfony-html-sanitizer)[friendsofcake/cakepdf

CakePHP plugin for creating and/or rendering Pdfs, several Pdf engines supported.

3752.1M3](/packages/friendsofcake-cakepdf)

PHPackages © 2026

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