Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

refactored Presenter::checkRequirements

  • Loading branch information...
commit 81f3abef465e4d3e9076947f0ecfa49aeb04d878 1 parent 4f397ea
@juzna authored
View
10 Nette/Application/UI/Presenter.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**/
View
18 Nette/Application/UI/PresenterComponent.php
@@ -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.
Please sign in to comment.
Something went wrong with that request. Please try again.