vendor/ibexa/core/src/lib/MVC/Symfony/Security/Authorization/Attribute.php line 30

Open in your IDE?
  1. <?php
  2. /**
  3.  * @copyright Copyright (C) Ibexa AS. All rights reserved.
  4.  * @license For full copyright and license information view LICENSE file distributed with this source code.
  5.  */
  6. namespace Ibexa\Core\MVC\Symfony\Security\Authorization;
  7. /**
  8.  * Authorization attribute class to be used with SecurityContextInterface::isGranted().
  9.  *
  10.  * $module represents the global scope you want to check access to (e.g. "content")
  11.  * $function represents the feature inside $module (e.g. "read")
  12.  * $limitations are optional limitations to check against (e.g. array( 'valueObject' => $contentInfo )).
  13.  *              Supported keys are "valueObject" and "targets".
  14.  *              "valueObject": ValueObject you want to check access to (e.g. ContentInfo)
  15.  *              "targets": Location, parent or "assignment" (e.g. Section) value object, or an array of the same
  16.  *
  17.  * Usage example:
  18.  * <code>
  19.  * use Ibexa\Core\MVC\Symfony\Security\Authorization\Attribute as AuthorizationAttribute;
  20.  *
  21.  * // From inside a controller
  22.  * // Will check if current user can assign a content to a section, $section being a Section value object.
  23.  * $hasAccess = $this->isGranted(
  24.  *     new AuthorizationAttribute( 'content', 'read', array( 'valueObject' => $contentInfo, 'targets' => $section ) )
  25.  * );
  26.  * </code>
  27.  */
  28. class Attribute
  29. {
  30.     /** @var string */
  31.     public $module;
  32.     /** @var string */
  33.     public $function;
  34.     /** @var array */
  35.     public $limitations;
  36.     public function __construct($module null$function null, array $limitations = [])
  37.     {
  38.         $this->module $module;
  39.         $this->function $function;
  40.         $this->limitations $limitations;
  41.     }
  42.     /**
  43.      * String representation so that it's understandable by basic voters.
  44.      *
  45.      * @return string
  46.      */
  47.     public function __toString()
  48.     {
  49.         return "EZ_ROLE_{$this->module}_{$this->function}";
  50.     }
  51. }
  52. class_alias(Attribute::class, 'eZ\Publish\Core\MVC\Symfony\Security\Authorization\Attribute');