Componette

Componette

rixxi

rixxi / redirector

Redirecting via presenter is so 2000 and late!

download-cloud-line composer require rixxi/redirector

Cure for $presenter->redirect([$code, ], $destination[, $arguments]) in middle of events.

  • You don't have to include application or presenter into listener just redirector.
  • All attached listeners are executed. Assuming they don't kill app or throw exceptions.
  • Guaranteed first point of possible redirection in whole system.
  • Easier redirection testing.

Assuming you use it across whole system.

Setup

Install

composer install rixxi/redirector

Configure

extensions:
	- Rixxi\Redirector\DI\RedirectorExtension

Enable support in presenter

<?php

use Rixxi\Application\UI\Presenter\EnableRedirector;


class BasePresenter extends Nette\Application\UI\Presenter
{
	use EnableRedirector;
}

Defines BasePresenter::beforeRender and asks for injection of redirector.

Then you are free to do this

<?php

class ExamplePresenter extends BasePresenter
{

	/** @var \Service @ inject */
	public $service;


	public function actionDefault()
	{
		$this->service->onError[] = function () { // redirect back on error
			$this->redirector->redirect('this'); // if you used $presenter->redirect here next events would not execute
		};
		
		$this->service->onError[] = function () { // say something to admin
			$this->reporter->say('I might be sick!');
		};
	}

}

Now imagine whole ekosystem of plugins around idea of distribution and (late) delegation.

No release at this moment. Try to create first one.

price-tag-2-line

Badges

guide-fill

Dependencies

php (>=5.3.1)
Componette Componette felix@nette.org