andrzejkupczyk / url-shortener
A simple library to generate shortened URLs
Installs: 9 941
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 1
Requires
- php: ^7.4 || ^8.0
- andrzejkupczyk/ddd-generic-subdomain: ^1.0
- beberlei/assert: ^v3.2
- godruoyi/php-snowflake: ^1.0
- guzzlehttp/guzzle: ^7.2
Requires (Dev)
- illuminate/console: ^v8.27
- illuminate/support: ^v8.27
- phpspec/phpspec: ^7.0
- psalm/plugin-laravel: ^1.4
- squizlabs/php_codesniffer: ^3.5
- vimeo/psalm: ^4.1
README
A simple yet easily extendable library to generate shortened URLs using different providers.
Install
Via Composer
composer require andrzejkupczyk/url-shortener
Examples of use
Creating short URLs
$shortener = UrlShortener::bitly($apiUri, $apiKey); $link = $shortener->shorten(new Url('https://github.com/andrzejkupczyk/url-shortener')); print($link->shortUrl()); // http://bit.ly/2Dkm8SJ
Expanding shortened URLs
$shortener = UrlShortener::bitly($apiUri, $apiKey); $link = $shortener->expand(new Url('http://bit.ly/2Dkm8SJ')); print($link->longUrl()); // https://github.com/andrzejkupczyk/url-shortener
Supported providers
Laravel support
It is possible to use this package easily within a Laravel >=5.5 application (it is configured for discovery).
Artisan commands
url:expand {url} Expand short URL url:shorten {url} Shorten long URL
Configuration (not required)
Publish and modify the configuration file:
php artisan vendor:publish --provider="WebGarden\UrlShortener\LaravelServiceProvider"