This bundle provides a service and twig extension for getting short urls like http://your.host/~short
PHP
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
Controller
DependencyInjection
Entity
Extensions Initial commit Jan 27, 2012
Resources
Service
Tests Added travis build config and it's status to readme Jan 30, 2013
.gitignore Fixed compatibility with latest symfony2 framework Jan 27, 2013
.travis.yml
BumzShortUrlBundle.php
LICENSE
README.md
composer.json
phpunit.xml.dist

README.md

ShortUrlBundle

This bundle provides a service and twig extension for getting short urls like http://your.host/~short

Build Status

Installation

Add this bundle to your project

Using the vendors script

Add the following lines in your deps file:

[BumzShortUrlBundle]
    git=git://github.com/biozshock/ShortUrlBundle.git
    target=bundles/Bumz/ShortUrlBundle

Run the vendors script:

$ php bin/vendors install

Using Git submodule

$ git submodule add git://github.com/biozshock/ShortUrlBundle.git vendor/bundles/Bumz/ShortUrlBundle

Add the Bumz namespace to your autoloader

<?php
// app/autoload.php

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

Add this bundle to your application's kernel

<?php
// app/AppKernel.php

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

Add bundle's routing

# /app/config/routing.yml
BumzShortUrlBundle:
    resource: "@BumzShortUrlBundle/Resources/config/routing.yml"
    prefix:   /

Examples

Short url in a controller

<?php

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'

        ...
    }
}

Get long url in controller

<?php

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'

        ...
    }
}

Get short url in a twig template

{{ 'http://example.com' | shortenUrl }}
{# this will output something like /~ShE #}