ublaboo/presenter-component

This package is abandoned and no longer maintained. No replacement package was suggested.

Annotation-boosted component factory for Nette framework

v1.0.1 2016-07-02 15:22 UTC

This package is not auto-updated.

Last update: 2017-04-11 17:39:22 UTC


README

Build Status Latest Stable Version License Total Downloads Gitter

PresenterComponent

Tired from writing component factories? There is a solution!

1, Suppose, you have a form factory class:

namespace App\Forms;

use Nette;

class ProductFormFactory extends Nette\Object
{

	public function create()
	{
		$form = new Nette\Application\UI\Form;

		$form->onSuccess = [$this, 'succeeded'];

		return $form;
	}


	public function succeeded($form, $values)
	{
		# Your onSuccess code
	}

}

Than insted of:

namespace App\Prsenters;

use App;

class HomepagePresenter extends Nette\Application\UI\Presenter;
{

	/**
	 * @var App\Forms\ProductFormFactory
	 * @inject
	 */
	public $productFormFactory;


	public function createComponentProductForm()
	{
		return $this->productFormFactory->create();
	}

}

you can create form factory with annotation:

namespace App\Prsenters;

use App,
	Ublaboo\PresenterComponent\PresenterComponentTrait;

class HomepagePresenter extends Nette\Application\UI\Presenter;
{

	use PresenterComponentTrait;

	/**
	 * @var App\Forms\ProductFormFactory
	 * @inject
	 * @component productForm:create
	 */
	public $productFormFactory;

}

2, Passing variables to component factory class

namespace App\Prsenters;

use App,
	Ublaboo\PresenterComponent\PresenterComponentTrait;

class HomepagePresenter extends Nette\Application\UI\Presenter;
{

	public $id;

	use PresenterComponentTrait;

	/**
	 * @var App\Forms\ProductFormFactory
	 * @inject
	 * @component productForm:create
	 * @componentArgs id, user
	 */
	public $productFormFactory;

}

3, Form callbacks (onSuccess, onError, ..)

namespace App\Prsenters;

use App,
	Ublaboo\PresenterComponent\PresenterComponentTrait;

class HomepagePresenter extends Nette\Application\UI\Presenter;
{

	public $id;

	use PresenterComponentTrait;

	/**
	 * @var App\Forms\ProductFormFactory
	 * @inject
	 * @component productForm:create
	 * @componentArgs id, user
	 * @componentCallback onSuccess:succeeded
	 * @componentCallback onValidate:validate
	 * @componentCallback onError:formError
	 */
	public $productFormFactory;


	public function succeeded($form, $values)
	{

	}


	public function validate($form, $values)
	{
		
	}


	public function formError($form)
	{
		
	}

}