Database
in package
implements
UrlShortenerInterface
Local database-driven URL shortener.
Tags
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
$baseUrl
protected
string
$baseUrl
$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
$salt
protected
string
$salt
$service
protected
ShortlinksServiceInterface
$service
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
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)