Pārlūkot izejas kodu

Move access-related methods to their own interface

Grégoire Paris 7 gadi atpakaļ
vecāks
revīzija
4c6fbb3868

+ 46 - 0
Admin/AccessRegistryInterface.php

@@ -0,0 +1,46 @@
+<?php
+
+/*
+ * This file is part of the Sonata Project package.
+ *
+ * (c) Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Sonata\AdminBundle\Admin;
+
+/**
+ * Tells if the current user has access to a given action.
+ *
+ * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ */
+interface AccessRegistryInterface
+{
+    /**
+     * Return the controller access mapping.
+     *
+     * @return array
+     */
+    public function getAccessMapping();
+
+    /**
+     * Hook to handle access authorization.
+     *
+     * @param string $action
+     * @param object $object
+     */
+    public function checkAccess($action, $object = null);
+
+    /*
+     * Hook to handle access authorization, without throwing an exception.
+     *
+     * @param string $action
+     * @param object $object
+     *
+     * @return bool
+     * TODO: uncomment this method for next major release
+     */
+     // public function hasAccess($action, $object = null);
+}

+ 1 - 27
Admin/AdminInterface.php

@@ -30,7 +30,7 @@ use Symfony\Component\Validator\ValidatorInterface as LegacyValidatorInterface;
 /**
  * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  */
-interface AdminInterface extends FieldDescriptionRegistryInterface, LifecycleHookProviderInterface, MenuBuilderInterface, ParentAdminInterface, UrlGeneratorInterface
+interface AdminInterface extends AccessRegistryInterface, FieldDescriptionRegistryInterface, LifecycleHookProviderInterface, MenuBuilderInterface, ParentAdminInterface, UrlGeneratorInterface
 {
     /**
      * @param FormContractorInterface $formContractor
@@ -724,21 +724,6 @@ interface AdminInterface extends FieldDescriptionRegistryInterface, LifecycleHoo
      */
     public function getListMode();
 
-    /**
-     * Return the controller access mapping.
-     *
-     * @return array
-     */
-    public function getAccessMapping();
-
-    /**
-     * Hook to handle access authorization.
-     *
-     * @param string $action
-     * @param object $object
-     */
-    public function checkAccess($action, $object = null);
-
     /*
      * Configure buttons for an action
      *
@@ -748,17 +733,6 @@ interface AdminInterface extends FieldDescriptionRegistryInterface, LifecycleHoo
      */
     // public function configureActionButtons($action, $object = null);
 
-//    TODO: uncomment this method for next major release
-//    /**
-//     * Hook to handle access authorization, without throw Exception
-//     *
-//     * @param string $action
-//     * @param object $object
-//     *
-//     * @return bool
-//     */
-//    public function hasAccess($action, $object = null);
-
     //TODO: uncomment this method for 4.0
     /*
      * Returns the result link for an object.

+ 5 - 5
Admin/LifecycleHookProviderInterface.php

@@ -44,11 +44,11 @@ interface LifecycleHookProviderInterface
      */
     public function delete($object);
 
-//NEXT_MAJOR: uncomment this method for 4.0
-//    /**
-//     * @param object $object
-//     */
-//    public function preValidate($object);
+    //NEXT_MAJOR: uncomment this method for 4.0
+    //    /**
+    //     * @param object $object
+    //     */
+    //    public function preValidate($object);
 
     /**
      * @param object $object