Skip to content
/ event Public

DO NOT USE rixxi/redirector is better replacement. Fails to solve $presenter->redirect([$code, ], $destination[, $arguments]) for you in civilized manner

License

Notifications You must be signed in to change notification settings

rixxi/event

Folders and files

NameName
Last commit message
Last commit date

Latest commit

5b1387b · Jun 18, 2014

History

2 Commits
Jan 15, 2014
Jun 18, 2014
Jan 15, 2014
Jan 15, 2014

Repository files navigation

This pattern introduces more complexity and issues then it solves. Use Nette events with rixxi/redirector instead, it is more robust and simpler solution then custom event classes.

Discontinued support - You can use it, but you have been warned.

KISS pattern for solving most of the onEvent problems using basket with some code (IEvent).

Solves $presenter->redirect([$code, ], $destination[, $arguments]) for you in civilized manner

<?php

use Rixxi\Event\IEvent;
use Rixxi\Event\IRedirect;
use Rixxi\Event\Redirect as RedirectTrait;

class ShitHappensEvent implements IEvent, IRedirect
{

  use RedirectTrait;

}

class Service extends Nette\Object
{

  public $onShitHappens = [];


  public function __construct(Rixxi\Event\Redirector $redirector)
  {
    $this->redirector = $redirector;
  }
  
  
  public function makeShitHappen()
  {
    $this->onShitHappens($event = ShitHappensEvent);
    $this->redirector->handle($event);
  }

}


// register extension and let DI do its magic

$service = new Service();

$service->onShitHappen[] = function (ShitHappensEvent $e) {
  if (/* some important condition */) {
    $e->redirect('Presenter:action', [ 'arguments ' ]);
  }
};

$service->onShitHappen[] = function () {
  echo 'Default $presenter->redirect(...) would kill request before I can write something. So grateful!';
};

// you can easily add default redirection
$service->onShitHappen[] = Rixxi\Event\Helper::defaultRedirect('Homepage:default');

$service->makeShitHappen();
// shit will happen and then redirection too

About

DO NOT USE rixxi/redirector is better replacement. Fails to solve $presenter->redirect([$code, ], $destination[, $arguments]) for you in civilized manner

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages