PHP code example of adspray / short-url-bundle

1. Go to this page and download the library: Download adspray/short-url-bundle 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/ */

    

adspray / short-url-bundle example snippets



// app/autoload.php

$loader->registerNamespaces(array(
    'Bumz' => __DIR__.'/../vendor/bundles',
    // your other namespaces
));


// app/AppKernel.php

public function registerBundles()
{
    return array(
        // ...
        new Bumz\ShortUrlBundle\BumzShortUrlBundle(),
        // ...
    );
}



use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class UsersController extends Controller
{
    public function getUserProfileShortAction()
    {

        ...

        $longUrl = $this->get('bumz_short_url.shortener')->shorten('http://example.com');
        // $longUrl = '/~ShE'

        ...
    }
}



use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class UsersController extends Controller
{
    public function getUserProfileShortAction()
    {

        ...

        $shortUrl = 'aUty';
        $longUrl = $this->get('bumz_short_url.shortener')->getLong($shortUrl);
        // $longUrl = 'http://example.com'

        ...
    }
}
bash
$ php bin/vendors install