public function addRules(EventInterface $event) {
        $accessControl = $event->getAccessControl();

        if (!($accessControl instanceof MutableAdapterInterface)) {
            throw new ResourceException('Access control adapter is immutable', 405);
        }

        $request = $event->getRequest();
        $publicKey = $request->getRoute()->get('publickey');
        $data = json_decode($request->getContent(), true);

        if (!is_array($data)) {
            throw new InvalidArgumentException('No access rule data provided', 400);
        }

        // If a single rule was provided, wrap it in an array
        if (!count($data) || !isset($data[0])) {
            $data = [$data];
        }

        $accessControl = $event->getAccessControl();

        // Perform rule validation
        foreach ($data as $rule) {
            $this->validateRule($event, $rule);
        }

        // Insert the rules
        foreach ($data as $rule) {
            $accessControl->addAccessRule($publicKey, $rule);
        }
    }
public function addRules(EventInterface $event) {
        $accessControl = $event->getAccessControl();

        if (!($accessControl instanceof MutableAdapterInterface)) {
            throw new ResourceException('Access control adapter is immutable', 405);
        }

        $request = $event->getRequest();
        $publicKey = $request->getRoute()->get('publickey');
        $data = json_decode($request->getContent(), true);

        if (!is_array($data)) {
            throw new InvalidArgumentException('No access rule data provided', 400);
        }

        // If a single rule was provided, wrap it in an array
        if (!count($data) || !isset($data[0])) {
            $data = [$data];
        }

        $accessControl = $event->getAccessControl();

        // Perform rule validation
        foreach ($data as $rule) {
            $this->validateRule($event, $rule);
        }

        // Insert the rules
        foreach ($data as $rule) {
            $accessControl->addAccessRule($publicKey, $rule);
        }
    }
public function addRules ( EventInterface $ event ) { $ accessControl = $ event -> getAccessControl ( ) ; if ( ! ( $ accessControl instanceof MutableAdapterInterface ) ) { throw new ResourceException ( 'Access control adapter is immutable' , 405 ) ; } $ request = $ event -> getRequest ( ) ; $ publicKey = $ request -> getRoute ( ) -> get ( 'publickey' ) ; $ data = json_decode ( $ request -> getContent ( ) , true ) ; if ( ! is_array ( $ data ) ) { throw new InvalidArgumentException ( 'No access rule data provided' , 400 ) ; } // If a single rule was provided, wrap it in an array if ( ! count ( $ data ) || ! isset ( $ data [ 0 ] ) ) { $ data = [ $ data ] ; } $ accessControl = $ event -> getAccessControl ( ) ; // Perform rule validation foreach ( $ data as $ rule ) { $ this -> validateRule ( $ event , $ rule ) ; } // Insert the rules foreach ( $ data as $ rule ) { $ accessControl -> addAccessRule ( $ publicKey , $ rule ) ; } }
Add access rules for the specified public key

@param EventInterface $event The current event
Add access rules for the specified public key