PHP code example of northern-lights / polr-client

1. Go to this page and download the library: Download northern-lights/polr-client 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/ */

    

northern-lights / polr-client example snippets

 php


namespace NorthernLights\Client\Polr\Example;

use NorthernLights\Client\Polr\ApiClient;
use NorthernLights\Client\Polr\Config\Config;
use NorthernLights\Client\Polr\Response\ShortenResponseInterface;


/**
 * Initialize API client and pass $config to it (DI)
 * @var ApiClient $api
 */
$api = new ApiClient();

/**
 * Shorten the long URL.
 * @var ShortenResponseInterface $response
 */
$response = $api->shorten('https://www.polrproject.org');

// Check if API request was successful. Remains true as long as HTTP status code equals 200 OK
if (!$response->wasSuccessful()) {
    echo 'There was an error querying the api' . PHP_EOL;
    exit(1);
}

echo 'Short URL is ' . $response->getShortUrl() . PHP_EOL;
 bash
$ composer php-lint