arirah-shortener / url-shortener

URL shortener service with popular URL shortener provider


URL shortener

URL shortener package have ability to support different URL shortener providers.


Install composer dependencies with docker run --rm -v $(pwd):/app composer install

You can also run make command like make init

Run examples docker run --rm -v $(pwd):/app -w /app php:cli php examples/bitly.php

Docker phpunit tests command : docker run --rm -v $(pwd):/app -w /app php:cli php ./vendor/bin/phpunit tests/urlTest

Use the package manager composer ( to install URL shortener.

composer require arirah-shortener/url-shortener:dev-master



Currently we have two providers bitly and tinyurl more will be added soon.


In your file use like this , you must have to set provider instance :

$shortener =  new UrlShortener(new \ArirahShortener\UrlShortener\TinyUrl());

For bitly you need to set API access_token

$shortener =  new UrlShortener(new \ArirahShortener\UrlShortener\Bitly('f7bb93c3ae74d10db0de48e9e038f13000e07d05'));

Currently we have two provider bitly and tiny url. Default provider is tinyurl.
For you have to set access token from bitly account
No access_token ? dont worry it automatically switch to tinyurl provider.

Example :

try {
    $access_token = new ArirahShortener\UrlShortener\AccessToken('f7bb93c3ae74d10db0de48e9e038f13000e07d05');
    $shortener =  new UrlShortener(new ArirahShortener\UrlShortener\Bitly($access_token));
    echo (string) $shortener->shorten('');
} catch (Exception $e) {
    echo $e->getMessage() ;

# TinyURL
try {
    $shortener =  new UrlShortener();
    echo (string) $shortener->shorten('');
} catch (Exception $e) {
    echo $e->getMessage() ;

Return :


Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.