VuFind API Documentation

Database
in package
implements UrlShortenerInterface

Local database-driven URL shortener.

Tags
category

VuFind

author

Demian Katz demian.katz@villanova.edu

author

Cornelius Amzar cornelius.amzar@bsz-bw.de

license

http://opensource.org/licenses/gpl-2.0.php GNU General Public License

link

Wiki

Interfaces, Classes, Traits and Enums

UrlShortenerInterface
URL shortener interface.

Table of Contents

$baseUrl  : string
$hashAlgorithm  : string
$maxHashLength  : int
The maximum allowed hash length (tied to the width of the database hash column); if we can't generate a unique hash under this length, something has gone very wrong.
$preferredHashLength  : int
When using a hash algorithm other than base62, the preferred number of characters to use from the hash in the URL (more may be used for disambiguation when necessary).
$salt  : string
$service  : ShortlinksServiceInterface
__construct()  : mixed
Constructor
resolve()  : string
Resolve URL from Database via id.
shorten()  : string
Generate & store shortened URL in Database.
getBase62Hash()  : string
Generate a short hash using the base62 algorithm (and write a row to the database).
getGenericHash()  : string
Generate a short hash using the configured algorithm (and write a row to the database if the link is new).
getShortHash()  : string
Given a URL, create a database entry (if necessary) and return the hash value for inclusion in the short URL.
saveAndShortenHash()  : string
Support method for getGenericHash(): do the work of picking a short version of the hash and writing to the database as needed.

Properties

$hashAlgorithm

protected string $hashAlgorithm = 'md5'

$maxHashLength

The maximum allowed hash length (tied to the width of the database hash column); if we can't generate a unique hash under this length, something has gone very wrong.

protected int $maxHashLength = 32

$preferredHashLength

When using a hash algorithm other than base62, the preferred number of characters to use from the hash in the URL (more may be used for disambiguation when necessary).

protected int $preferredHashLength = 9

Methods

__construct()

Constructor

public __construct(string $baseUrl, ShortlinksServiceInterface $service, string $salt[, string $hashAlgorithm = 'md5' ]) : mixed
Parameters
$baseUrl : string

Base URL of current VuFind site

$service : ShortlinksServiceInterface

Shortlinks database service

$salt : string

HMacKey from config

$hashAlgorithm : string = 'md5'

Hash algorithm to use

Return values
mixed

resolve()

Resolve URL from Database via id.

public resolve(string $input) : string
Parameters
$input : string

hash

Tags
throws
Exception
Return values
string

shorten()

Generate & store shortened URL in Database.

public shorten(string $url) : string
Parameters
$url : string

URL

Return values
string

getBase62Hash()

Generate a short hash using the base62 algorithm (and write a row to the database).

protected getBase62Hash(string $path) : string
Parameters
$path : string

Path to store in database

Return values
string

getGenericHash()

Generate a short hash using the configured algorithm (and write a row to the database if the link is new).

protected getGenericHash(string $path) : string
Parameters
$path : string

Path to store in database

Return values
string

getShortHash()

Given a URL, create a database entry (if necessary) and return the hash value for inclusion in the short URL.

protected getShortHash(string $url) : string
Parameters
$url : string

URL

Return values
string

saveAndShortenHash()

Support method for getGenericHash(): do the work of picking a short version of the hash and writing to the database as needed.

protected saveAndShortenHash(string $path, string $hash, int $length) : string
Parameters
$path : string

Path to store in database

$hash : string

Hash of $path (generated in getGenericHash)

$length : int

Minimum number of characters from hash to use for lookups (may be increased to enforce uniqueness)

Tags
throws
Exception
Return values
string

Search results