Просмотр исходного кода

Merge pull request #4440 from greg0ire/fix_isp_violations

Fix isp violations
Jordi Sala Morales 7 лет назад
Родитель
Сommit
5513a8d427

+ 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);
+}

+ 11 - 311
Admin/AdminInterface.php

@@ -12,14 +12,11 @@
 namespace Sonata\AdminBundle\Admin;
 
 use Knp\Menu\FactoryInterface as MenuFactoryInterface;
-use Knp\Menu\ItemInterface;
 use Sonata\AdminBundle\Builder\DatagridBuilderInterface;
 use Sonata\AdminBundle\Builder\FormContractorInterface;
 use Sonata\AdminBundle\Builder\ListBuilderInterface;
 use Sonata\AdminBundle\Builder\RouteBuilderInterface;
 use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
-use Sonata\AdminBundle\Route\RouteCollection;
-use Sonata\AdminBundle\Route\RouteGeneratorInterface;
 use Sonata\AdminBundle\Security\Handler\SecurityHandlerInterface;
 use Sonata\AdminBundle\Translator\LabelTranslatorStrategyInterface;
 use Sonata\CoreBundle\Model\Metadata;
@@ -34,8 +31,18 @@ use Symfony\Component\Validator\ValidatorInterface as LegacyValidatorInterface;
 /**
  * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
  */
-interface AdminInterface
+interface AdminInterface extends AccessRegistryInterface, FieldDescriptionRegistryInterface, LifecycleHookProviderInterface, MenuBuilderInterface, ParentAdminInterface, UrlGeneratorInterface
 {
+    /**
+     * @param MenuFactoryInterface $menuFactory
+     */
+    public function setMenuFactory(MenuFactoryInterface $menuFactory);
+
+    /**
+     * @return MenuFactoryInterface
+     */
+    public function getMenuFactory();
+
     /**
      * @param FormContractorInterface $formContractor
      */
@@ -93,11 +100,6 @@ interface AdminInterface
      */
     public function setConfigurationPool(Pool $pool);
 
-    /**
-     * @param RouteGeneratorInterface $routeGenerator
-     */
-    public function setRouteGenerator(RouteGeneratorInterface $routeGenerator);
-
     /**
      * Returns subjectClass/class/subclass name managed
      * - subclass name if subclass parameter is defined
@@ -132,40 +134,6 @@ interface AdminInterface
      */
     public function getBaseControllerName();
 
-    /**
-     * Generates the object url with the given $name.
-     *
-     * @param string $name
-     * @param mixed  $object
-     * @param array  $parameters
-     * @param bool   $absolute
-     *
-     * @return string return a complete url
-     */
-    public function generateObjectUrl($name, $object, array $parameters = array(), $absolute = false);
-
-    /**
-     * Generates an url for the given parameters.
-     *
-     * @param string $name
-     * @param array  $parameters
-     * @param bool   $absolute
-     *
-     * @return string return a complete url
-     */
-    public function generateUrl($name, array $parameters = array(), $absolute = false);
-
-    /**
-     * Generates an url for the given parameters.
-     *
-     * @param string $name
-     * @param array  $parameters
-     * @param bool   $absolute
-     *
-     * @return array return url parts: 'route', 'routeParameters', 'routeAbsolute'
-     */
-    public function generateMenuUrl($name, array $parameters = array(), $absolute = false);
-
     /**
      * @return \Sonata\AdminBundle\Model\ModelManagerInterface
      */
@@ -188,22 +156,6 @@ interface AdminInterface
      */
     public function getFormBuilder();
 
-    /**
-     * Return FormFieldDescription.
-     *
-     * @param string $name
-     *
-     * @return FieldDescriptionInterface
-     */
-    public function getFormFieldDescription($name);
-
-    /**
-     * Build and return the collection of form FieldDescription.
-     *
-     * @return array collection of form FieldDescription
-     */
-    public function getFormFieldDescriptions();
-
     /**
      * Returns a form depend on the given $object.
      *
@@ -279,20 +231,6 @@ interface AdminInterface
      */
     public function trans($id, array $parameters = array(), $domain = null, $locale = null);
 
-    /**
-     * Returns the list of available urls.
-     *
-     * @return RouteCollection the list of available urls
-     */
-    public function getRoutes();
-
-    /**
-     * Return the parameter name used to represent the id in the url.
-     *
-     * @return string
-     */
-    public function getRouterIdParameter();
-
     /**
      * Returns the parameter representing request id, ie: id or childId.
      *
@@ -326,92 +264,6 @@ interface AdminInterface
      */
     // public function isCurrentRoute($name, $adminCode = null);
 
-    /**
-     * Returns true if the admin has a FieldDescription with the given $name.
-     *
-     * @param string $name
-     *
-     * @return bool
-     */
-    public function hasShowFieldDescription($name);
-
-    /**
-     * add a FieldDescription.
-     *
-     * @param string                    $name
-     * @param FieldDescriptionInterface $fieldDescription
-     */
-    public function addShowFieldDescription($name, FieldDescriptionInterface $fieldDescription);
-
-    /**
-     * Remove a ShowFieldDescription.
-     *
-     * @param string $name
-     */
-    public function removeShowFieldDescription($name);
-
-    /**
-     * add a list FieldDescription.
-     *
-     * @param string                    $name
-     * @param FieldDescriptionInterface $fieldDescription
-     */
-    public function addListFieldDescription($name, FieldDescriptionInterface $fieldDescription);
-
-    /**
-     * Remove a list FieldDescription.
-     *
-     * @param string $name
-     */
-    public function removeListFieldDescription($name);
-
-    /**
-     * Returns true if the filter FieldDescription exists.
-     *
-     * @param string $name
-     *
-     * @return bool
-     */
-    public function hasFilterFieldDescription($name);
-
-    /**
-     * add a filter FieldDescription.
-     *
-     * @param string                    $name
-     * @param FieldDescriptionInterface $fieldDescription
-     */
-    public function addFilterFieldDescription($name, FieldDescriptionInterface $fieldDescription);
-
-    /**
-     * Remove a filter FieldDescription.
-     *
-     * @param string $name
-     */
-    public function removeFilterFieldDescription($name);
-
-    /**
-     * Returns the filter FieldDescription collection.
-     *
-     * @return FieldDescriptionInterface[]
-     */
-    public function getFilterFieldDescriptions();
-
-    /**
-     * Returns a filter FieldDescription.
-     *
-     * @param string $name
-     *
-     * @return FieldDescriptionInterface|null
-     */
-    public function getFilterFieldDescription($name);
-
-    /**
-     * Returns a list depend on the given $object.
-     *
-     * @return FieldDescriptionCollection
-     */
-    public function getList();
-
     /**
      * @param SecurityHandlerInterface $securityHandler
      */
@@ -430,13 +282,6 @@ interface AdminInterface
      */
     public function isGranted($name, $object = null);
 
-    /**
-     * @param mixed $entity
-     *
-     * @return string a string representation of the id that is save to use in an url
-     */
-    public function getUrlsafeIdentifier($entity);
-
     /**
      * @param mixed $entity
      *
@@ -500,16 +345,6 @@ interface AdminInterface
      */
     public function getExtensions();
 
-    /**
-     * @param \Knp\Menu\FactoryInterface $menuFactory
-     */
-    public function setMenuFactory(MenuFactoryInterface $menuFactory);
-
-    /**
-     * @return \Knp\Menu\FactoryInterface
-     */
-    public function getMenuFactory();
-
     /**
      * @param RouteBuilderInterface $routeBuilder
      */
@@ -546,38 +381,6 @@ interface AdminInterface
      */
     public function supportsPreviewMode();
 
-    /**
-     * add an Admin child to the current one.
-     *
-     * @param AdminInterface $child
-     */
-    public function addChild(AdminInterface $child);
-
-    /**
-     * Returns true or false if an Admin child exists for the given $code.
-     *
-     * @param string $code Admin code
-     *
-     * @return bool True if child exist, false otherwise
-     */
-    public function hasChild($code);
-
-    /**
-     * Returns an collection of admin children.
-     *
-     * @return array list of Admin children
-     */
-    public function getChildren();
-
-    /**
-     * Returns an admin child with the given $code.
-     *
-     * @param string $code
-     *
-     * @return AdminInterface|null
-     */
-    public function getChild($code);
-
     /**
      * @return mixed a new object instance
      */
@@ -653,61 +456,6 @@ interface AdminInterface
 
     public function configure();
 
-    /**
-     * @param mixed $object
-     *
-     * @return mixed
-     */
-    public function update($object);
-
-    /**
-     * @param mixed $object
-     *
-     * @return mixed
-     */
-    public function create($object);
-
-    /**
-     * @param mixed $object
-     */
-    public function delete($object);
-
-    //TODO: uncomment this method for 4.0
-    //    /**
-    //     * @param mixed $object
-    //     */
-    //    public function preValidate($object);
-
-    /**
-     * @param mixed $object
-     */
-    public function preUpdate($object);
-
-    /**
-     * @param mixed $object
-     */
-    public function postUpdate($object);
-
-    /**
-     * @param mixed $object
-     */
-    public function prePersist($object);
-
-    /**
-     * @param mixed $object
-     */
-    public function postPersist($object);
-
-    /**
-     * @param mixed $object
-     */
-    public function preRemove($object);
-
-    /**
-     * @param mixed $object
-     */
-    public function postRemove($object);
-
     /**
      * Call before the batch action, allow you to alter the query and the idx.
      *
@@ -963,28 +711,6 @@ interface AdminInterface
      */
     public function getTranslationLabel($label, $context = '', $type = '');
 
-    /**
-     * NEXT_MAJOR: remove this method.
-     *
-     * @param string         $action
-     * @param AdminInterface $childAdmin
-     *
-     * @return ItemInterface|bool
-     *
-     * @deprecated Use buildTabMenu instead
-     */
-    public function buildSideMenu($action, AdminInterface $childAdmin = null);
-
-    /**
-     * Build the tab menu related to the current action.
-     *
-     * @param string         $action
-     * @param AdminInterface $childAdmin
-     *
-     * @return ItemInterface|bool
-     */
-    public function buildTabMenu($action, AdminInterface $childAdmin = null);
-
     /**
      * @param $object
      *
@@ -1009,21 +735,6 @@ interface AdminInterface
      */
     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
      *
@@ -1033,17 +744,6 @@ interface AdminInterface
      */
     // 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.

+ 122 - 0
Admin/FieldDescriptionRegistryInterface.php

@@ -0,0 +1,122 @@
+<?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;
+
+/**
+ * Implementations should provide arrays of FieldDescriptionInterface instances.
+ *
+ * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ */
+interface FieldDescriptionRegistryInterface
+{
+    /**
+     * Return FormFieldDescription.
+     *
+     * @param string $name
+     *
+     * @return FieldDescriptionInterface
+     */
+    public function getFormFieldDescription($name);
+
+    /**
+     * Build and return the collection of form FieldDescription.
+     *
+     * @return FieldDescriptionInterface[] collection of form FieldDescription
+     */
+    public function getFormFieldDescriptions();
+
+    /**
+     * Returns true if the admin has a FieldDescription with the given $name.
+     *
+     * @param string $name
+     *
+     * @return bool
+     */
+    public function hasShowFieldDescription($name);
+
+    /**
+     * Adds a FieldDescription.
+     *
+     * @param string                    $name
+     * @param FieldDescriptionInterface $fieldDescription
+     */
+    public function addShowFieldDescription($name, FieldDescriptionInterface $fieldDescription);
+
+    /**
+     * Removes a ShowFieldDescription.
+     *
+     * @param string $name
+     */
+    public function removeShowFieldDescription($name);
+
+    /**
+     * Adds a list FieldDescription.
+     *
+     * @param string                    $name
+     * @param FieldDescriptionInterface $fieldDescription
+     */
+    public function addListFieldDescription($name, FieldDescriptionInterface $fieldDescription);
+
+    /**
+     * Removes a list FieldDescription.
+     *
+     * @param string $name
+     */
+    public function removeListFieldDescription($name);
+
+    /**
+     * Returns a list depend on the given $object.
+     *
+     * @return FieldDescriptionCollection
+     */
+    public function getList();
+
+    /**
+     * Returns true if the filter FieldDescription exists.
+     *
+     * @param string $name
+     *
+     * @return bool
+     */
+    public function hasFilterFieldDescription($name);
+
+    /**
+     * Adds a filter FieldDescription.
+     *
+     * @param string                    $name
+     * @param FieldDescriptionInterface $fieldDescription
+     */
+    public function addFilterFieldDescription($name, FieldDescriptionInterface $fieldDescription);
+
+    /**
+     * Removes a filter FieldDescription.
+     *
+     * @param string $name
+     */
+    public function removeFilterFieldDescription($name);
+
+    /**
+     * Returns the filter FieldDescription collection.
+     *
+     * @return FieldDescriptionInterface[]
+     */
+    public function getFilterFieldDescriptions();
+
+    /**
+     * Returns a filter FieldDescription.
+     *
+     * @param string $name
+     *
+     * @return FieldDescriptionInterface|null
+     */
+    public function getFilterFieldDescription($name);
+}

+ 82 - 0
Admin/LifecycleHookProviderInterface.php

@@ -0,0 +1,82 @@
+<?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;
+
+/**
+ * This interface can be implemented to provide hooks that will be called
+ * during the lifecycle of the object.
+ *
+ * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ */
+interface LifecycleHookProviderInterface
+{
+    /**
+     * This method should call preUpdate, do the update, and call postUpdate.
+     *
+     * @param object $object
+     *
+     * @return object
+     */
+    public function update($object);
+
+    /**
+     * This method should call prePersist, do the creation, and call postPersist.
+     *
+     * @param object $object
+     *
+     * @return object
+     */
+    public function create($object);
+
+    /**
+     * This method should call preRemove, do the removal, and call postRemove.
+     *
+     * @param object $object
+     */
+    public function delete($object);
+
+    //NEXT_MAJOR: uncomment this method for 4.0
+    //    /**
+    //     * @param object $object
+    //     */
+    //    public function preValidate($object);
+
+    /**
+     * @param object $object
+     */
+    public function preUpdate($object);
+
+    /**
+     * @param object $object
+     */
+    public function postUpdate($object);
+
+    /**
+     * @param object $object
+     */
+    public function prePersist($object);
+
+    /**
+     * @param object $object
+     */
+    public function postPersist($object);
+
+    /**
+     * @param object $object
+     */
+    public function preRemove($object);
+
+    /**
+     * @param object $object
+     */
+    public function postRemove($object);
+}

+ 44 - 0
Admin/MenuBuilderInterface.php

@@ -0,0 +1,44 @@
+<?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;
+
+use Knp\Menu\ItemInterface;
+
+/**
+ * This interface can be implemented by admins that need to build menus.
+ *
+ * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ */
+interface MenuBuilderInterface
+{
+    /**
+     * NEXT_MAJOR: remove this method.
+     *
+     * @param string         $action
+     * @param AdminInterface $childAdmin
+     *
+     * @return ItemInterface|bool
+     *
+     * @deprecated Use buildTabMenu instead
+     */
+    public function buildSideMenu($action, AdminInterface $childAdmin = null);
+
+    /**
+     * Build the tab menu related to the current action.
+     *
+     * @param string         $action
+     * @param AdminInterface $childAdmin
+     *
+     * @return ItemInterface|bool
+     */
+    public function buildTabMenu($action, AdminInterface $childAdmin = null);
+}

+ 54 - 0
Admin/ParentAdminInterface.php

@@ -0,0 +1,54 @@
+<?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;
+
+/**
+ * This interface can be used to implement an admin that can have children
+ * admins, meaning admin that correspond to objects with a relationship with
+ * the object managed by this admin.
+ *
+ * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ */
+interface ParentAdminInterface
+{
+    /**
+     * add an Admin child to the current one.
+     *
+     * @param AdminInterface $child
+     */
+    public function addChild(AdminInterface $child);
+
+    /**
+     * Returns true or false if an Admin child exists for the given $code.
+     *
+     * @param string $code Admin code
+     *
+     * @return bool True if child exist, false otherwise
+     */
+    public function hasChild($code);
+
+    /**
+     * Returns an collection of admin children.
+     *
+     * @return array list of Admin children
+     */
+    public function getChildren();
+
+    /**
+     * Returns an admin child with the given $code.
+     *
+     * @param string $code
+     *
+     * @return AdminInterface|null
+     */
+    public function getChild($code);
+}

+ 82 - 0
Admin/UrlGeneratorInterface.php

@@ -0,0 +1,82 @@
+<?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;
+
+use Sonata\AdminBundle\Route\RouteGeneratorInterface;
+
+/**
+ * Contains url generation logic related to an admin.
+ *
+ * @author Thomas Rabaix <thomas.rabaix@sonata-project.org>
+ */
+interface UrlGeneratorInterface
+{
+    /**
+     * Returns the list of available urls.
+     *
+     * @return RouteCollection the list of available urls
+     */
+    public function getRoutes();
+
+    /**
+     * Return the parameter name used to represent the id in the url.
+     *
+     * @return string
+     */
+    public function getRouterIdParameter();
+
+    /**
+     * @param RouteGeneratorInterface $routeGenerator
+     */
+    public function setRouteGenerator(RouteGeneratorInterface $routeGenerator);
+
+    /**
+     * Generates the object url with the given $name.
+     *
+     * @param string $name
+     * @param mixed  $object
+     * @param array  $parameters
+     * @param bool   $absolute
+     *
+     * @return string return a complete url
+     */
+    public function generateObjectUrl($name, $object, array $parameters = array(), $absolute = false);
+
+    /**
+     * Generates a url for the given parameters.
+     *
+     * @param string $name
+     * @param array  $parameters
+     * @param bool   $absolute
+     *
+     * @return string return a complete url
+     */
+    public function generateUrl($name, array $parameters = array(), $absolute = false);
+
+    /**
+     * Generates a url for the given parameters.
+     *
+     * @param string $name
+     * @param array  $parameters
+     * @param bool   $absolute
+     *
+     * @return array return url parts: 'route', 'routeParameters', 'routeAbsolute'
+     */
+    public function generateMenuUrl($name, array $parameters = array(), $absolute = false);
+
+    /**
+     * @param mixed $entity
+     *
+     * @return string a string representation of the id that is safe to use in a url
+     */
+    public function getUrlsafeIdentifier($entity);
+}

+ 3 - 3
Model/ModelManagerInterface.php

@@ -138,14 +138,14 @@ interface ModelManagerInterface
     public function getNormalizedIdentifier($model);
 
     /**
-     * Get the identifiers as a string that is save to use in an url.
+     * Get the identifiers as a string that is safe to use in a url.
      *
      * This is similar to getNormalizedIdentifier but guarantees an id that can
-     * be used in an URL.
+     * be used in a URL.
      *
      * @param object $model
      *
-     * @return string string representation of the id that is save to use in an url
+     * @return string string representation of the id that is safe to use in a url
      */
     public function getUrlsafeIdentifier($model);
 

+ 2 - 2
Twig/Extension/SonataAdminExtension.php

@@ -364,12 +364,12 @@ EOT;
     }
 
     /**
-     * Get the identifiers as a string that is save to use in an url.
+     * Get the identifiers as a string that is safe to use in a url.
      *
      * @param object         $model
      * @param AdminInterface $admin
      *
-     * @return string string representation of the id that is save to use in an url
+     * @return string string representation of the id that is safe to use in a url
      */
     public function getUrlsafeIdentifier($model, AdminInterface $admin = null)
     {