public function addGroup(EventInterface $event) {
        $accessControl = $event->getAccessControl();
        if (!($accessControl instanceof MutableAdapterInterface)) {
            throw new ResourceException('Access control adapter is immutable', 405);
        }

        $request = $event->getRequest();
        $route = $request->getRoute();
        $groupName = $route->get('group');

        $group = $accessControl->getGroup($groupName);
        $groupExists = !empty($group);

        $resources = json_decode($request->getContent(), true);

        if (!is_array($resources)) {
            throw new ResourceException('Invalid data. Array of resource strings is expected', 400);
        }

        foreach ($resources as $resource) {
            if (!is_string($resource)) {
               throw new ResourceException('Invalid value in the resources array. Only strings are allowed', 400);
            }
        }

        if ($groupExists) {
            $accessControl->updateResourceGroup($groupName, $resources);
        } else {
            $accessControl->addResourceGroup($groupName, $resources);
        }

        $response = $event->getResponse();
        $response->setStatusCode($groupExists ? 200 : 201);
    }
public function addGroup(EventInterface $event) {
        $accessControl = $event->getAccessControl();
        if (!($accessControl instanceof MutableAdapterInterface)) {
            throw new ResourceException('Access control adapter is immutable', 405);
        }

        $request = $event->getRequest();
        $route = $request->getRoute();
        $groupName = $route->get('group');

        $group = $accessControl->getGroup($groupName);
        $groupExists = !empty($group);

        $resources = json_decode($request->getContent(), true);

        if (!is_array($resources)) {
            throw new ResourceException('Invalid data. Array of resource strings is expected', 400);
        }

        foreach ($resources as $resource) {
            if (!is_string($resource)) {
               throw new ResourceException('Invalid value in the resources array. Only strings are allowed', 400);
            }
        }

        if ($groupExists) {
            $accessControl->updateResourceGroup($groupName, $resources);
        } else {
            $accessControl->addResourceGroup($groupName, $resources);
        }

        $response = $event->getResponse();
        $response->setStatusCode($groupExists ? 200 : 201);
    }
public function addGroup ( EventInterface $ event ) { $ accessControl = $ event -> getAccessControl ( ) ; if ( ! ( $ accessControl instanceof MutableAdapterInterface ) ) { throw new ResourceException ( 'Access control adapter is immutable' , 405 ) ; } $ request = $ event -> getRequest ( ) ; $ route = $ request -> getRoute ( ) ; $ groupName = $ route -> get ( 'group' ) ; $ group = $ accessControl -> getGroup ( $ groupName ) ; $ groupExists = ! empty ( $ group ) ; $ resources = json_decode ( $ request -> getContent ( ) , true ) ; if ( ! is_array ( $ resources ) ) { throw new ResourceException ( 'Invalid data. Array of resource strings is expected' , 400 ) ; } foreach ( $ resources as $ resource ) { if ( ! is_string ( $ resource ) ) { throw new ResourceException ( 'Invalid value in the resources array. Only strings are allowed' , 400 ) ; } } if ( $ groupExists ) { $ accessControl -> updateResourceGroup ( $ groupName , $ resources ) ; } else { $ accessControl -> addResourceGroup ( $ groupName , $ resources ) ; } $ response = $ event -> getResponse ( ) ; $ response -> setStatusCode ( $ groupExists ? 200 : 201 ) ; }
Add resources to a group

@param EventInterface $event The current event
Add resources to a group