chomenko/presenter-factory-listener

There is no license information available for the latest version (dev-master) of this package.

PresenterFactory listener from Nette framework

dev-master 2019-07-15 08:08 UTC

This package is auto-updated.

Last update: 2024-10-15 19:15:48 UTC


README

Temporary solution.

This extension allows you to extend presenter factory

Required

Install

composer require chomenko/presenter-factory-listener

Configure

in config.neon

extensions:
	events: Kdyby\Events\DI\EventsExtension
	presenterFactoryListener: Chomenko\PresenterFactoryListener\DI\PresenterFactoryListenerExtension

Use

Events

  • onGetPresenter
  • onFormatPresenterClass
  • onUnFormatPresenterClass
<?php
namespace App\Listener;

use Kdyby\Events\Subscriber;
use Chomenko\PresenterFactoryListener\EventArgsGetPresenter;
use Chomenko\PresenterFactoryListener\PresenterFactory as ExtendPresenter;

class PresenterFactory implements Subscriber
{
	/**
	 * @return array
	 */
	public function getSubscribedEvents()
	{
		return [
			ExtendPresenter::class . "::onGetPresenter" => "onGetPresenter",
		];
	}

	/**
	 * @param EventArgsGetPresenter $eventArgs
	 */
	public function onGetPresenter(EventArgsGetPresenter $eventArgs)
	{
		$presenter = $eventArgs->getName();
		$exp = explode(":", $presenter);
		if (isset($exp[0]) && $exp[0] == "Special") { //specialModule
			$eventArgs->setPresenter("special class name"); //special class
		}
	}
}