Redirector
Redirect manager, (*1)
, (*2)
This package provides you with a simple tool to redirect users. You can easily manage everything., (*3)
Installation
Via Composer, (*4)
$ composer require freeq/redirector
Using
Use package everywhere you need. The best way to manage your redirections is to run it in Observer or other event listener. You should store redirections after saving to the database, drop them from store after removing database record. Every redirect object should implement Redirectable
contract., (*5)
Create manager
Make instance of your redirections manager. It allows you to store/delete/flush/get data., (*6)
use Freeq\Redirector\Manager;
$redirect_object = Redirect::findById(1); // must implement Redirectable!
// Using file driver.
$storage = new FileStorage('/path/to/store/them');
$storage->setRedirect($redirect_object);
$manager = new Manager($storage);
// Using redis driver.
$storage = new RedisStorage(new Predis\Client());
$storage->setRedirect($redirect_object);
$manager = new Manager($storage);
// Otherwise u can use StorageFactory.
// $type is storage name (file or redis)
// $source is path for FileStorage or Predis Client for RedisStorage
$storage = StorageFactory::build($type, $source);
$storage->setRedirect($redirect_object);
$manager = new Manager($storage);
Manage Redirectable object
Store object, (*7)
$manager->store();
Drop it, (*8)
$manager->delete();
Flush everything, (*9)
$manager->flush();
Start redirection for given route, (*10)
$manager->forward('my_route');
Classes
-
Freeq\Redirector\Manager
- allows you to manage.
-
Freeq\Redirector\StorageFactory
- is creating concrete class depending of passed 'type' to the manager constructor.
-
Freeq\Redirector\Storages\FileStorage
- driver which allows you to store redirections as mini files.
-
Freeq\Redirector\Storages\RedisStorage
- driver which allows you to store redirections as redis records.
Redirectable methods
Your object which implements Freeq\Redirector\Contracts\Redirectable
needs methods:
- routeFrom()
- which route should be redirected.
- routeTo()
- where did you want to go by your redirection (eg. https://github.com).
- statusHttp()
- redirect using specific http statuses (301 or 302).
- hash()
- hash is string similar to hashed routeFrom() by md5. It's redis key or filename.
- expireAt()
- returns date to expire your redirection., (*11)
Contributing
Please see contributing.md for details., (*12)