PHP code example of mremi / url-shortener-bundle

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

    

mremi / url-shortener-bundle example snippets




$linkManager   = $container->get('mremi_url_shortener.link_manager');
$chainProvider = $container->get('mremi_url_shortener.chain_provider');

$link = $linkManager->create();
$link->setLongUrl('http://www.google.com');

$chainProvider->getProvider('bitly')->shorten($link);

$chainProvider->getProvider('google')->expand($link);



$linkManager = $container->get('mremi_url_shortener.link_manager');

$shortened = $linkManager->findOneByProviderAndShortUrl('bitly', 'http://bit.ly/ze6poY');

$expanded = $linkManager->findOneByProviderAndLongUrl('google', 'http://www.google.com');
bash
php composer.phar 
 php

// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...
        new Mremi\UrlShortenerBundle\MremiUrlShortenerBundle(),
    );
}
 php

// src/Acme/UrlShortenerBundle/Entity/Link.php

namespace Acme\UrlShortenerBundle\Entity;

use Mremi\UrlShortenerBundle\Entity\Link as BaseLink;

class Link extends BaseLink
{
    /**
     * @var integer
     */
    protected $id;
}
 php

// app/DoctrineMigrations/VersionYYYYMMDDHHIISS.php

namespace Application\Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration,
    Doctrine\DBAL\Schema\Schema;

class VersionYYYYMMDDHHIISS extends AbstractMigration
{
    public function up(Schema $schema)
    {
        // customize index size as you want...
        $this->addSql("CREATE INDEX idx_url_shortener_link_long_url ON link (long_url(20))");
    }

    public function down(Schema $schema)
    {
        $this->addSql("DROP INDEX idx_url_shortener_link_long_url ON link;");
    }