PHP code example of tomkyle / kurzelinks

1. Go to this page and download the library: Download tomkyle/kurzelinks library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

tomkyle / kurzelinks example snippets


use tomkyle\KurzeLinks\GuzzleKurzeLinks;

$api = 'https://kurzelinks.de/api';
$key = 'your_api_key';
$kurzeLinks = new GuzzleKurzeLinks($api, $key);

$shortUrl = $kurzeLinks->create('https://example.com');
echo $shortUrl;  // Outputs the shortened URL

use tomkyle\KurzeLinks\GuzzleKurzeLinks;
use tomkyle\KurzeLinks\RateLimitKurzeLinks;

$api = 'https://kurzelinks.de/api';
$key = 'your_api_key';
$innerKurzeLinks = new GuzzleKurzeLinks($api, $key);
$rateLimitedKurzeLinks = new RateLimitKurzeLinks($innerKurzeLinks, 4000); // 4000ms sleep

$shortUrl = $rateLimitedKurzeLinks->create('https://example.com');
echo $shortUrl;  // Outputs the shortened URL

use tomkyle\KurzeLinks\GuzzleKurzeLinks;
use tomkyle\KurzeLinks\Psr6CacheKurzeLinks;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;

$api = 'https://kurzelinks.de/api';
$key = 'your_api_key';
$innerKurzeLinks = new GuzzleKurzeLinks($api, $key);
$cachePool = new FilesystemAdapter();

$cachedKurzeLinks = new Psr6CacheKurzeLinks($innerKurzeLinks, $cachePool);

$shortUrl = $cachedKurzeLinks->create('https://example.com');
echo $shortUrl;  // Outputs the shortened URL, possibly from cache

use tomkyle\KurzeLinks\PassthroughKurzeLinks;

$passthroughKurzeLinks = new PassthroughKurzeLinks();

$shortUrl = $passthroughKurzeLinks->create('https://example.com');
echo $shortUrl;  // Outputs the original URL: https://example.com

use tomkyle\KurzeLinks\CallableKurzeLinks;
use tomkyle\KurzeLinks\GuzzleKurzeLinks;

$api = 'https://kurzelinks.de/api';
$key = 'your_api_key';
$innerKurzeLinks = new GuzzleKurzeLinks($api, $key);
$callableKurzeLinks = new CallableKurzeLinks($innerKurzeLinks);

// Use as callable
$shortUrl = $callableKurzeLinks('https://example.com');
echo $shortUrl;  // Outputs the shortened URL

// Use create method directly
$shortUrl = $callableKurzeLinks->create('https://example.com');
echo $shortUrl;  // Outputs the shortened URL

use tomkyle\KurzeLinks\KurzeLinksInterface;

class MyKurzeLinks implements KurzeLinksInterface
{
    public function create(string $url): string
    {
        // Your implementation here
    }
}