fabstei/shorturl-bundle

This package is abandoned and no longer maintained. No replacement package was suggested.

Provides a Shorturl Service for your Symfony2 Project.

Installs: 2 480

Dependents: 0

Suggesters: 0

Security: 0

Stars: 12

Watchers: 4

Forks: 2

Open Issues: 2

Type:symfony-bundle

0.2.0 2014-01-20 12:10 UTC

This package is auto-updated.

Last update: 2022-04-22 12:23:31 UTC


README

SensioLabsInsight

Build Status

Note: This bundle is under development. Things will change and might break. Feedback is very welcome!

About

This Bundle allows you to

  • Generate short urls
  • Manage redirections from short to long urls

The bundle is based on the shorturl class by Jonathan Snook.

Installation

Using Composer, add to composer.json:

{
    "require": {
        "fabstei/shorturl-bundle": "0.2.0"
    }
}

Then install/update your vendors:

php composer.phar update

Add the bundle to your AppKernel.php:

new Fabstei\ShorturlBundle\FabsteiShorturlBundle(),

Update your doctrine database schema (doctrine:schema:update --force)

Import the routes from your routing.yml:

# Redirection from short to long urls
redirect:
    resource: "@FabsteiShorturlBundle/Resources/config/routing/redirect.yml"
    #hostname_pattern: example.com
    #prefix: /shorturls

# Shorturl management
shorturl:
    resource: "@FabsteiShorturlBundle/Resources/config/routing/url.yml"

The optional hostname pattern (new in Symfony 2.2) allows you to use a seperate domain for your short urls.

Configuration

The bundle provides sensible default values but one might want to customize the codeset used to generate unique tokens (used as short urls).

fabstei_shorturl:
    codeset: abcABC123-_! # Default: abcdefghijkmnopqrstuvwxyzABCDEFGHIJKLMNPQRSTUVWXYZ23456789

Usage

The bundle comes with two services:

It also provides a controller to handle redirections as well as a controller, views and forms to manage the redirections (by default accessible from /url-manager). Custom shorturls can be used to replace the default tokens (calculated from the redirection id). Furthermore, you may use _locale anywhere in the long urls you store, which is replaced by the current requests locale on redirection.

Both services are also accessible via cli commands:

php app/console fabstei:shorturl:add    # Add a long url, returns the short token
php app/console fabstei:shorturl:get    # Retrieve a long url associated with a token
php app/console fabstei:shorturl:update # Update the long url associated with a token
php app/console fabstei:shorturl:remove # Remove a redirection
php app/console fabstei:shorturl:list   # Get a list of all stored redirections

php app/console fabstei:token:codeset   # Get the codeset used to generate tokens
php app/console fabstei:token:encode    # Calculate a token from an integer
php app/console fabstei:token:decode    # Calculate the integer from a given token

TODO

  • Add proper tests
  • Improve general code quality

Dependencies

Credits