Collections

Introduction

Collections are standard Phalcon Collections enriched with Access Control and advanced Endpoint Configuration. Collections can be used to register default endpoints, for more complex implementations look at Resources.

use PhalconRest\Api;
use PhalconRest\Collection;
use PhalconRest\Endpoint;

$api = new Api;

$api->collection(Collection::factory('/export')
    ->name('Export')
    ->handler(ExportController::class)
    ->allow(\UserRoles::USER)
    ->endpoint(Endpoint::get('/documentation.json', 'documentation'))
    ->endpoint(Endpoint::get('/postman.json', 'postman'));
);

Extend

Extend from ExportCollection from PhalconRest\Api\Collection

use PhalconRest\Api\Collection;

class ExportCollection extends Collection
{
    protected function initialize()
    {
        $this
            ->name('Export')
            ->handler(ExportController::class)
            ->allow(\UserRoles::USER)
            ->endpoint(Endpoint::get('/documentation.json', 'documentation'))
            ->endpoint(Endpoint::get('/postman.json', 'postman'));
    }
}

Register collection on $api

$api = new \PhalconRest\Api;

$api->collection(new ExportCollection('/export'));

Method Listing

name()

Name will be used as a quick description for documenting this collection. See more on Documentation Generation.

getName()

Returns the name that has been set.

description()

Description will be used as a detailed description for documenting this collection.

getDescription()

Returns the description that has been set.

getEndpoints()

Returns all mounted endpoints on this collection.

getEndpoint()

Returns endpoints by it's name if does exists.

postedDataMethod()

Set the postedDataMethod, defaults to PostedDataMethods::AUTO

getPostedDataMethod()

Returns the postedDataMethod.

expectsPostData()

Sets the posted data method to PostedDataMethods::POST

expectsJsonData()

Sets the posted data method to PostedDataMethods::JSON_BODY

allow()

Allow one or multiple roles for this collection.

deny()

Deny one or multiple roles for this collection.

getAllowedRoles()

Returns the roles that have been allowed.

getDeniedRoles()

Returns the roles that have been denied.

getAclRules()

Return build aclRules based on the roles that have been allowed and denied by its respective methods allow() and deny().