PageRenderTime 34ms CodeModel.GetById 27ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

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