Permalink
Browse files

refactored Presenter::checkRequirements

  • Loading branch information...
1 parent 4f397ea commit 81f3abef465e4d3e9076947f0ecfa49aeb04d878 @juzna committed Mar 17, 2012
Showing with 22 additions and 6 deletions.
  1. +6 −4 Nette/Application/UI/Presenter.php
  2. +16 −2 Nette/Application/UI/PresenterComponent.php
@@ -168,7 +168,7 @@ public function run(Application\Request $request)
$this->setParent($this->getParent(), $request->getPresenterName());
$this->initGlobalParameters();
- $this->checkRequirements($this->getReflection());
+ $this->ensureRequirements($this->getReflection());
$this->startup();
if (!$this->startupCheck) {
$class = $this->getReflection()->getMethod('startup')->getDeclaringClass()->getName();
@@ -273,16 +273,18 @@ protected function shutdown($response)
/**
* Checks authorization.
- * @return void
+ * @param Nette\Reflection\ClassType|Nette\Reflection\Method $element
+ * @return bool
*/
public function checkRequirements($element)
{
$user = (array) $element->getAnnotation('User');
if (in_array('loggedIn', $user) && !$this->getUser()->isLoggedIn()) {
- throw new Application\ForbiddenRequestException;
+ return FALSE;
}
- }
+ return TRUE;
+ }
/********************* signal handling ****************d*g**/
@@ -95,7 +95,7 @@ protected function tryCall($method, array $params)
if ($rc->hasMethod($method)) {
$rm = $rc->getMethod($method);
if ($rm->isPublic() && !$rm->isAbstract() && !$rm->isStatic()) {
- $this->checkRequirements($rm);
+ $this->ensureRequirements($rm);
$rm->invokeArgs($this, $rc->combineArgs($rm, $params));
return TRUE;
}
@@ -107,13 +107,27 @@ protected function tryCall($method, array $params)
/**
* Checks for requirements such as authorization.
- * @return void
+ * @param Nette\Reflection\ClassType|Nette\Reflection\Method $element
+ * @return bool
*/
public function checkRequirements($element)
{
+ return TRUE;
}
+ /**
+ * Checks authorization and throws if requirements not met.
+ * @param Nette\Reflection\ClassType|Nette\Reflection\Method $element
+ * @return void
+ */
+ public function ensureRequirements($element)
+ {
+ if (!$this->checkRequirements($element)) {
+ throw new Nette\Application\ForbiddenRequestException;
+ }
+ }
+
/**
* Access to reflection.

0 comments on commit 81f3abe

Please sign in to comment.