Skip to content

Instantly share code, notes, and snippets.

@radmiraal
Created August 20, 2012 10:29
Show Gist options
  • Save radmiraal/3402932 to your computer and use it in GitHub Desktop.
Save radmiraal/3402932 to your computer and use it in GitHub Desktop.
/**
* renders <f:then> child if the role could be found in the security context,
* otherwise renders <f:else> child.
*
* @param string $role The role
* @param string $packageKey PackageKey of the package defining the role
* @return string the rendered string
* @api
*/
public function render($role, $packageKey = NULL) {
if ($role !== 'Everybody' && $role !== 'Anonymous' && !strpos($role, '.')) {
if ($packageKey === NULL) {
$role = $this->controllerContext->getRequest()->getControllerPackageKey() . '.' . $role;
} else {
$role = $packageKey . '.' . $role;
}
}
if ($this->securityContext->hasRole($role)) {
return $this->renderThenChild();
} else {
return $this->renderElseChild();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment