Skip to content

Instantly share code, notes, and snippets.

@PJK
Forked from PJK/gist:981359
Created May 19, 2011 18:07
Show Gist options
  • Save PJK/981363 to your computer and use it in GitHub Desktop.
Save PJK/981363 to your computer and use it in GitHub Desktop.
<?php
/**
* @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;
}
}
}
<?php
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