adeb6600 / url-shortener
URL shortening the easy way.
Requires
- php: >=5.4.0
- illuminate/config: ~5.0
- illuminate/support: 5.0.*
- symfony/finder: ~2.6
- vinelab/http: 1.2.*
Requires (Dev)
- mockery/mockery: 0.9.*
- phpunit/phpunit: 4.3.*
- symfony/var-dumper: ~2.6
This package is not auto-updated.
Last update: 2024-12-11 20:03:25 UTC
README
vinelab/url-shortener
is a PHP framework agnostic Package that makes it easy to shorten your URL's, with your favourite URL Shortening provider such as (Bit.ly, Goo.gl, Ow.ly).
The URL Shortening Providers are online services that takes long URLs and squeezes them into fewer characters to make the link easier to share, tweet, or send by email.
The package requires PHP 5.4+ and comes bundled with a Laravel 5 Facade and a Service Provider to simplify the optional framework integration and follows the FIG standard PSR-4 to ensure a high level of interoperability between shared PHP code and is fully unit-tested.
Highlights
- Supportes Bit.ly
Installation
The recommended way to install this package is via Composer
.
Via Composer
A. Run this composer command:
composer require vinelab/url-shortener:*
B. Or manually add the package to your composer.json
and run composer update
.
{ "require": { "vinelab/url-shortener": "*" } }
Integrations
url-shortener
is framework agnostic and as such can be integrated easily natively or with your favorite framework.
Laravel:
The url-shortener
package has optional support for Laravel 5 and it comes bundled with a Service Provider for easier integration.
After you have installed the package correctly, just follow the instructions.
.1. Register the service provider in your config/app.php
:
'providers' => array( ... 'Vinelab\UrlShortener\UrlShortenerServiceProvider' ),
The service provider will automatically alias the Vinelab\UrlShortener\Shorten
class, so you can easily use the Shorten
facade anywhere in your app.
.2. Publish the configuration file:
php artisan vendor:publish --provider ='Vinelab\UrlShortener\UrlShortenerServiceProvider'
Configuration
.1. Open url-shortener.php
and select your default provider:
'default' => 'bitly',
.2. Then add your provider token:
'bitly' => [ 'domain' => 'https://api-ssl.bitly.com', 'endpoint' => '/v3/shorten', 'token' => 'YOUR-TOKEN-HERE', ],
Note: It's very recommended to not add your token (any sensetive data) to the config file instead reference it to a .env
variable.
And to do so:
-
replace the
'token' => 'YOUR-TOKEN-HERE',
with'token' => env('BITLY_TOKEN'),
-
open your
.env
file and add the token variable there with the token value:BITLY_TOKEN=YOUR-TOKEN-HERE
. -
add the variable
BITLY_TOKEN=
to the.env.example
for other developers.
Usage
With Laravel:
The easiest way is to use it is by the Shorten
facade.
$long_url = 'http://testing.tst/something/12345/something-else/54321'; $short_url = Shorten\Shorten::url($long_url); // returns the short version of the long_url as a string
Test
To run the tests, run the following command from the project folder.
$ ./vendor/bin/phpunit
Contributing
Support new provider
To add support for a new URL shortening provider:
- write a driver for your URL Shortener service.
check the
Bitly
driverVinelab\UrlShortener\Drivers\Bitly
class. - add you driver configuration to the config file.
- write tests for your drvier.
- update the
README
file - check out the Contribution Guide for general details.
Support
Security
If you discover any security related issues, please email mahmoud@vinelab.com instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.