Skip to content

Instantly share code, notes, and snippets.

@PJK
Created May 19, 2011 18:06
Show Gist options
  • Save PJK/981359 to your computer and use it in GitHub Desktop.
Save PJK/981359 to your computer and use it in GitHub Desktop.
/**
* @author Pavel Kalvoda
*/
abstract class BasePresenter extends Nette\Application\Presenter
{
protected function getAutosaveableProperties() {
$props = $this->getReflection()->getProperties();
$props = array_filter($props, function($prop) {
return $prop->hasAnnotation('autosave');
}
);
foreach ($props as $prop) {
$name = $prop->getName();
$res[$name] = $this->$name;
}
return $res;
}
protected function restoreState(array $state) {
foreach ($state as $name=>$value) {
$this->$name = $value;
}
}
}
public function shutdown($response) {
Nette\Environment::getSession('game')->data = $this->getAutosaveableProperties();
parent::shutdown();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment