ExtendedApiCollection.php 1.15 KB
<?php
/**
 * Created by PhpStorm.
 * User: Alex Savenko
 * Date: 14.02.2017
 * Time: 16:32
 */

namespace App\Mvc;


use PhalconApi\Constants\HttpMethods;
use PhalconRest\Api\ApiCollection;

class ExtendedApiCollection extends ApiCollection {

    public function endpoint(ExtendedApiEndpoint $endpoint)
    {
        $this->endpointsByName[$endpoint->getName()] = $endpoint;

        switch ($endpoint->getHttpMethod()) {

            case HttpMethods::GET:

                $this->get($endpoint->getPath(), $endpoint->getHandlerMethod(), $this->createRouteName($endpoint));
                break;

            case HttpMethods::POST:

                $this->post($endpoint->getPath(), $endpoint->getHandlerMethod(), $this->createRouteName($endpoint));
                break;

            case HttpMethods::PUT:

                $this->put($endpoint->getPath(), $endpoint->getHandlerMethod(), $this->createRouteName($endpoint));
                break;

            case HttpMethods::DELETE:

                $this->delete($endpoint->getPath(), $endpoint->getHandlerMethod(), $this->createRouteName($endpoint));
                break;
        }

        return $this;
    }

}