You are here

class RestPermissions in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/rest/src/RestPermissions.php \Drupal\rest\RestPermissions

Provides rest module permissions.

Hierarchy

Expanded class hierarchy of RestPermissions

File

core/modules/rest/src/RestPermissions.php, line 18
Contains \Drupal\rest\RestPermissions.

Namespace

Drupal\rest
View source
class RestPermissions implements ContainerInjectionInterface {

  /**
   * The rest resource plugin manager.
   *
   * @var \Drupal\rest\Plugin\Type\ResourcePluginManager
   */
  protected $restPluginManager;

  /**
   * The config factory.
   *
   * @var \Drupal\Core\Config\ConfigFactoryInterface
   */
  protected $configFactory;

  /**
   * Constructs a new RestPermissions instance.
   *
   * @param \Drupal\rest\Plugin\Type\ResourcePluginManager $rest_plugin_manager
   *   The rest resource plugin manager.
   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
   *   The config factory.
   */
  public function __construct(ResourcePluginManager $rest_plugin_manager, ConfigFactoryInterface $config_factory) {
    $this->restPluginManager = $rest_plugin_manager;
    $this->configFactory = $config_factory;
  }

  /**
   * {@inheritdoc}
   */
  public static function create(ContainerInterface $container) {
    return new static($container
      ->get('plugin.manager.rest'), $container
      ->get('config.factory'));
  }

  /**
   * Returns an array of REST permissions.
   *
   * @return array
   */
  public function permissions() {
    $permissions = [];
    $resources = $this->configFactory
      ->get('rest.settings')
      ->get('resources');
    if ($resources && ($enabled = array_intersect_key($this->restPluginManager
      ->getDefinitions(), $resources))) {
      foreach ($enabled as $key => $resource) {
        $plugin = $this->restPluginManager
          ->getInstance([
          'id' => $key,
        ]);
        $permissions = array_merge($permissions, $plugin
          ->permissions());
      }
    }
    return $permissions;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
RestPermissions::$configFactory protected property The config factory.
RestPermissions::$restPluginManager protected property The rest resource plugin manager.
RestPermissions::create public static function Instantiates a new instance of this class. Overrides ContainerInjectionInterface::create
RestPermissions::permissions public function Returns an array of REST permissions.
RestPermissions::__construct public function Constructs a new RestPermissions instance.