本文整理匯總了PHP中Sonata\AdminBundle\Admin\AdminInterface::isGranted方法的典型用法代碼示例。如果您正苦於以下問題:PHP AdminInterface::isGranted方法的具體用法?PHP AdminInterface::isGranted怎麽用?PHP AdminInterface::isGranted使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Sonata\AdminBundle\Admin\AdminInterface
的用法示例。
在下文中一共展示了AdminInterface::isGranted方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: aclAction
/**
* Returns the Response object associated to the acl action.
*
* @param int|string|null $id
*
* @return Response|RedirectResponse
*
* @throws AccessDeniedException If access is not granted.
* @throws NotFoundHttpException If the object does not exist or the ACL is not enabled
*/
public function aclAction($id = null)
{
if (!$this->admin->isAclEnabled()) {
throw new NotFoundHttpException('ACL are not enabled for this admin');
}
$id = $this->get('request')->get($this->admin->getIdParameter());
$object = $this->admin->getObject($id);
if (!$object) {
throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
}
if (false === $this->admin->isGranted('MASTER', $object)) {
throw new AccessDeniedException();
}
$this->admin->setSubject($object);
$aclUsers = $this->getAclUsers();
$adminObjectAclManipulator = $this->get('sonata.admin.object.manipulator.acl.admin');
$adminObjectAclData = new AdminObjectAclData($this->admin, $object, $aclUsers, $adminObjectAclManipulator->getMaskBuilderClass());
$form = $adminObjectAclManipulator->createForm($adminObjectAclData);
$request = $this->getRequest();
if ($request->getMethod() === 'POST') {
$form->submit($request);
if ($form->isValid()) {
$adminObjectAclManipulator->updateAcl($adminObjectAclData);
$this->addFlash('sonata_flash_success', 'flash_acl_edit_success');
return new RedirectResponse($this->admin->generateObjectUrl('acl', $object));
}
}
return $this->render($this->admin->getTemplate('acl'), array('action' => 'acl', 'permissions' => $adminObjectAclData->getUserPermissions(), 'object' => $object, 'users' => $aclUsers, 'form' => $form->createView()));
}
示例2: redirectTo
/**
* Redirect the user depend on this choice.
*
* @param object $object
* @param Request $request
*
* @return RedirectResponse
*/
protected function redirectTo($object)
{
$request = $this->getRequest();
$url = false;
if (null !== $request->get('btn_update_and_list')) {
$url = $this->admin->generateUrl('list');
}
if (null !== $request->get('btn_create_and_list')) {
$url = $this->admin->generateUrl('list');
}
if (null !== $request->get('btn_create_and_create')) {
$params = array();
if ($this->admin->hasActiveSubClass()) {
$params['subclass'] = $request->get('subclass');
}
$url = $this->admin->generateUrl('create', $params);
}
if ($this->getRestMethod() === 'DELETE') {
$url = $this->admin->generateUrl('list');
}
if (!$url) {
foreach (array('edit', 'show') as $route) {
if ($this->admin->hasRoute($route) && $this->admin->isGranted(strtoupper($route), $object)) {
$url = $this->admin->generateObjectUrl($route, $object);
break;
}
}
}
if (!$url) {
$url = $this->admin->generateUrl('list');
}
return new RedirectResponse($url);
}
示例3: showAction
/**
* return the Response object associated to the view action
*
* @return \Symfony\Component\HttpFoundation\Response
*/
public function showAction($id)
{
if (false === $this->admin->isGranted('SHOW')) {
throw new AccessDeniedException();
}
$object = $this->admin->getObject($this->get('request')->get($this->admin->getIdParameter()));
if (!$object) {
throw new NotFoundHttpException(sprintf('unable to find the object with id : %s', $id));
}
$this->admin->setSubject($object);
// build the show list
$elements = $this->admin->getShow();
return $this->render($this->admin->getShowTemplate(), array(
'action' => 'show',
'object' => $object,
'elements' => $this->admin->getShow(),
'admin' => $this->admin,
'base_template' => $this->getBaseTemplate(),
));
}
示例4: exportAction
/**
* @param \Symfony\Component\HttpFoundation\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function exportAction(Request $request)
{
if (false === $this->admin->isGranted('EXPORT')) {
throw new AccessDeniedException();
}
$format = $request->get('format');
$filename = sprintf('export_%s_%s.%s', strtolower(substr($this->admin->getClass(), strripos($this->admin->getClass(), '\\') + 1)), date('Y_m_d_H_i_s', strtotime('now')), $format);
return $this->get('sonata.admin.exporter')->getResponse($format, $filename, $this->admin->getDataSourceIterator());
}
示例5: exportAction
/**
* @param \Symfony\Component\HttpFoundation\Request $request
* @return \Symfony\Component\HttpFoundation\Response
*/
public function exportAction(Request $request)
{
if (false === $this->admin->isGranted('EXPORT')) {
throw new AccessDeniedException();
}
$format = $request->get('format');
$allowedExportFormats = (array) $this->admin->getExportFormats();
if (!in_array($format, $allowedExportFormats)) {
throw new \RuntimeException(sprintf('Export in format `%s` is not allowed for class: `%s`. Allowed formats are: `%s`', $format, $this->admin->getClass(), implode(', ', $allowedExportFormats)));
}
$filename = sprintf('export_%s_%s.%s', strtolower(substr($this->admin->getClass(), strripos($this->admin->getClass(), '\\') + 1)), date('Y_m_d_H_i_s', strtotime('now')), $format);
return $this->get('sonata.admin.exporter')->getResponse($format, $filename, $this->admin->getDataSourceIterator());
}
示例6: isOwner
/**
* Tests if the current user as the OWNER right.
*
* @return bool
*/
public function isOwner()
{
// Only a owner can set MASTER and OWNER ACL
return $this->admin->isGranted('OWNER', $this->object);
}