/administrator/components/com_widgetkit/vendor/yootheme/framework/src/User/AccessListener.php

https://gitlab.com/vnsoftdev/amms · PHP · 30 lines · 22 code · 5 blank · 3 comment · 1 complexity · 385ceb84ba65058d7a4a19434321e02f MD5 · raw file

  1. <?php
  2. namespace YOOtheme\Framework\User;
  3. use YOOtheme\Framework\Event\EventSubscriberInterface;
  4. use YOOtheme\Framework\Routing\Exception\HttpException;
  5. class AccessListener implements EventSubscriberInterface
  6. {
  7. public function onRequest($event, $app)
  8. {
  9. $access = (array) $event['request']->attributes->get('access');
  10. foreach ($access as $permission) {
  11. if (!$app['user']->hasPermission($permission)) {
  12. throw new HttpException(403, 'Insufficient User Rights.');
  13. }
  14. }
  15. }
  16. /**
  17. * {@inheritdoc}
  18. */
  19. public static function getSubscribedEvents()
  20. {
  21. return array(
  22. 'request' => array('onRequest', -10)
  23. );
  24. }
  25. }