PhalconRest\Api::getMatchedCollection PHP Method

getMatchedCollection() public method

public getMatchedCollection ( ) : ApiCollection | null
return PhalconRest\Api\ApiCollection | null The matched collection
    public function getMatchedCollection()
    {
        $collectionIdentifier = $this->getMatchedRouteNamePart('collection');
        if (!$collectionIdentifier) {
            return null;
        }
        return array_key_exists($collectionIdentifier, $this->collectionsByIdentifier) ? $this->collectionsByIdentifier[$collectionIdentifier] : null;
    }

Usage Example

 public function beforeExecuteRoute(Event $event, Api $api)
 {
     $collection = $api->getMatchedCollection();
     $endpoint = $api->getMatchedEndpoint();
     if (!$collection || !$endpoint) {
         return;
     }
     $allowed = $this->acl->isAllowed($this->userService->getRole(), $collection->getIdentifier(), $endpoint->getIdentifier());
     if (!$allowed) {
         throw new Exception(ErrorCodes::ACCESS_DENIED);
     }
 }