Download the PHP package mattmezza/shrtnr without Composer
On this page you can find all versions of the php package mattmezza/shrtnr. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mattmezza/shrtnr
More information about mattmezza/shrtnr
Files in mattmezza/shrtnr
Package shrtnr
Short Description Your super simple and fast private goo·gl/bit·ly system, privately hosted wherever you want, completely frontend agnostic.
License MIT
Informations about the package shrtnr
shrtnr
Your super simple and fast private goo·gl/bit·ly system, privately hosted wherever you want, completely frontend agnostic.
Installation
composer require mattmezza/shrtnr
- define the env variables needed and set up the DB (check below)
Usage
The Shrtnr
class offers a very simple API:
shrtn(string $from, string $ip = null) : string
-> Given a URI gives back the destination URL of the rule matching with thefrom
field (or throws aNoRuleException
if no rule is associated with the passed URI)
Can be used like this (in this example we forward the query string to the destination URL):
Admin usage
To add, edit, remove and search for clicks and rules you can check out the DAOs Clicks
and Rules
that are exposing a couple of methods for CRUD ops.
DB
shrtnr
connects to the DB using three ENV variables DB
which is the DSN (e.g. mysql:host=127.0.0.1;dbname=shrtnr
), DB_USER
and DB_PASS
respectively for the db user and password.
The DB itself should be built as follows:
Entities
shrtnr
works with two main entities: Rule
and Click
.
Rule
It is the rule that instructs the system what to do for a specific URI. It has info about the matching URI and the destination URL. It also has a field user_id
that should report an id of the user who created the rule (can be either a string or a numeric id).
Click
It represents an applied rule, it is created when somebody goes to the URI and gets redirected to the matching destination. It reports info about the IP address and references the applied rule.
Development
git clone https://github.com/mattmezza/shrtnr.git
cd shrtnr
- define the
DB
,DB_USER
,DB_PASS
env variable composer migrate
composer test