Skip to content

Instantly share code, notes, and snippets.

@JanTvrdik
Created August 19, 2010 13:13
Show Gist options
  • Save JanTvrdik/537838 to your computer and use it in GitHub Desktop.
Save JanTvrdik/537838 to your computer and use it in GitHub Desktop.
ReplicatingContainer
<?php
class FooPresenter extends BasePresenter
{
protected function createComponentFooContainer()
{
$container = new ReplicatingContainer();
$container->factoryCallback = callback($this, 'editFormFactory');
return $container;
}
protected function editFormFactory($container, $name)
{
return new EditForm($container, $name);
}
}
<?php
/**
* Magický, komponenty na požádání tvořící kontejner
*
* @author Jan Tvrdík
*/
class ReplicatingContainer extends Nette\ComponentContainer
{
/** @var callback */
public $factoryCallback;
/**
* Magická továrna na komponenty
*
* @author Jan Tvrdík
* @param string
* @return object
*/
protected function createComponent($name)
{
$callback = $this->factoryCallback;
return $callback($this, $name);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment