PhalconRest\Api::getMatchedEndpoint PHP Method

getMatchedEndpoint() public method

public getMatchedEndpoint ( ) : ApiEndpoint | null
return PhalconRest\Api\ApiEndpoint | null The matched endpoint
    public function getMatchedEndpoint()
    {
        $collectionIdentifier = $this->getMatchedRouteNamePart('collection');
        $endpointIdentifier = $this->getMatchedRouteNamePart('endpoint');
        if (!$endpointIdentifier) {
            return null;
        }
        $fullIdentifier = $collectionIdentifier . ' ' . $endpointIdentifier;
        return array_key_exists($fullIdentifier, $this->endpointsByIdentifier) ? $this->endpointsByIdentifier[$fullIdentifier] : 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);
     }
 }