twodevs / url-shortener
This library helps you to generate shortlinks for long url using different URL Shorteners.
1.0.2
2015-04-17 23:39 UTC
Requires
- php: >=5.4.8
- egeloen/http-adapter: ~0.7.0
- league/url: ~3.0
- symfony/options-resolver: ~2.6
- twodevs/cache-interface: ~1.0
Requires (Dev)
- guzzlehttp/guzzle: ~5.0
- phpunit/phpunit: ~4.6
This package is auto-updated.
Last update: 2024-10-29 04:14:41 UTC
README
This library helps you to generate shortlinks for long url using different URL Shorteners.
Supportet URL Shortener
Installation
The preferred way to install this library is to use Composer.
$ composer require twodevs/url-shortener ~1.0
Choose a http client support by Ivory HttpAdapter
$ composer require guzzlehttp/guzzle ~5.0
General Usage
// Create a client $client = new \GuzzleHttp\Client(['defaults' => ['verify' => false]]); // Create the Adapter $adapter = new \Ivory\HttpAdapter\GuzzleHttpHttpAdapter($client); // Create BitlyShortener $shorter = new \TwoDevs\UrlShortener\Provider\BitlyProvider($adapter, ['access_token' => 'your-token'])); // Shorten a long url $shortUrl = $shorter->shorten('http://example.org'); // Expand a short url $longUrl = $shorter->expand($shortUrl); var_dump( (string) $shortUrl ); var_dump( (string) $longUrl );
Using chain provider
// Create a client $client = new \GuzzleHttp\Client(['defaults' => ['verify' => false]]); // Create the Adapter $adapter = new \Ivory\HttpAdapter\GuzzleHttpHttpAdapter($client); // Create ChainProvider and attach bitly, google shortener and Tiny-Url $shorter = new \TwoDevs\UrlShortener\Provider\ChainProvider(); $shorter->addProvider(new \TwoDevs\UrlShortener\Provider\BitlyProvider($adapter, ['access_token' => 'your-token'])); $shorter->addProvider(new \TwoDevs\UrlShortener\Provider\GoogleProvider($adapter, ['key' => 'your-key'])); $shorter->addProvider(new \TwoDevs\UrlShortener\Provider\OwlyProvider($adapter, ['key' => 'your-key'])); $shorter->addProvider(new \TwoDevs\UrlShortener\Provider\TinyUrlProvider($adapter)); $shorter->addProvider(new \TwoDevs\UrlShortener\Provider\IsgdProvider($adapter)); $shorter->addProvider(new \TwoDevs\UrlShortener\Provider\VgdUrlProvider($adapter)); // Shorten a long url $shortUrl = $shorter->shorten('http://example.org'); // Expand a short url $longUrl = $shorter->expand($shortUrl); var_dump( (string) $shortUrl ); var_dump( (string) $longUrl );
License
The TwoDevs UrlShortener is under the MIT license. For the full copyright and license information, please read the LICENSE file that was distributed with this source code.