Routing/ElasticsearchLoader.php
private function processRestRoute(
        $collection,
        $document,
        $endpoint,
        $version = 'v1'
    ) {

        $defaults = [
            '_documentId' => null,
            '_endpoint' => $endpoint,
            '_version' => $version,
            'repository' => $endpoint['repository'],
        ];

        $pattern = $version . '/' . sprintf('%s/{documentId}', strtolower($document));

        if ($endpoint['batch']) {
            foreach ([Request::METHOD_PUT, Request::METHOD_POST, Request::METHOD_DELETE] as $method) {
                $defaults['_controller'] = 'ONGRApiBundle:Batch:' . ucfirst(strtolower($method));
                $batchPattern = $version . '/' . sprintf('%s', strtolower($document)) . '/_batch';
                $name = strtolower(sprintf('ongr_api_%s_%s_%s', $version, $document, $method));
                $collection->add($name . '_batch', new Route(
                    $batchPattern,
                    $defaults,
                    [],
                    [],
                    "",
                    [],
                    [$method]
                ));
            }
        }

        $name = strtolower(sprintf('ongr_api_%s_%s_all', $version, $document));
        $defaults['_controller'] = 'ONGRApiBundle:GetAll:getAll';
        $postPattern = $version . '/' . sprintf('%s', strtolower($document)).'/_all';
        $collection->add($name, new Route($postPattern, $defaults, [], [], "", [], [Request::METHOD_GET]));

        foreach ($endpoint['methods'] as $method) {
            $name = strtolower(sprintf('ongr_api_%s_%s_%s', $version, $document, $method));
            $defaults['_controller'] = sprintf('ONGRApiBundle:Rest:%s', strtolower($method));

            if ($method == Request::METHOD_POST) {
                $postPattern = $version . '/' . sprintf('%s', strtolower($document));
                $collection->add($name . '_wi', new Route($postPattern, $defaults, [], [], "", [], [$method]));
            }

            $collection->add($name, new Route($pattern, $defaults, [], [], "", [], [$method]));

            if ($endpoint['variants']) {
                $defaults['_controller'] = sprintf('ONGRApiBundle:Variant:%s', strtolower($method));

                if ($method == Request::METHOD_POST || $method == Request::METHOD_GET) {
                    $variantPattern = $pattern . '/_variant';
                    $collection->add(
                        $name . '_variant_wi',
                        new Route($variantPattern, $defaults, [], [], "", [], [$method])
                    );
                }

                $variantPattern = $pattern . '/_variant/{variantId}';
                $collection->add($name . '_variant', new Route($variantPattern, $defaults, [], [], "", [], [$method]));
            }
        }
    }
private function processRestRoute(
        $collection,
        $document,
        $endpoint,
        $version = 'v1'
    ) {

        $defaults = [
            '_documentId' => null,
            '_endpoint' => $endpoint,
            '_version' => $version,
            'repository' => $endpoint['repository'],
        ];

        $pattern = $version . '/' . sprintf('%s/{documentId}', strtolower($document));

        if ($endpoint['batch']) {
            foreach ([Request::METHOD_PUT, Request::METHOD_POST, Request::METHOD_DELETE] as $method) {
                $defaults['_controller'] = 'ONGRApiBundle:Batch:' . ucfirst(strtolower($method));
                $batchPattern = $version . '/' . sprintf('%s', strtolower($document)) . '/_batch';
                $name = strtolower(sprintf('ongr_api_%s_%s_%s', $version, $document, $method));
                $collection->add($name . '_batch', new Route(
                    $batchPattern,
                    $defaults,
                    [],
                    [],
                    "",
                    [],
                    [$method]
                ));
            }
        }

        $name = strtolower(sprintf('ongr_api_%s_%s_all', $version, $document));
        $defaults['_controller'] = 'ONGRApiBundle:GetAll:getAll';
        $postPattern = $version . '/' . sprintf('%s', strtolower($document)).'/_all';
        $collection->add($name, new Route($postPattern, $defaults, [], [], "", [], [Request::METHOD_GET]));

        foreach ($endpoint['methods'] as $method) {
            $name = strtolower(sprintf('ongr_api_%s_%s_%s', $version, $document, $method));
            $defaults['_controller'] = sprintf('ONGRApiBundle:Rest:%s', strtolower($method));

            if ($method == Request::METHOD_POST) {
                $postPattern = $version . '/' . sprintf('%s', strtolower($document));
                $collection->add($name . '_wi', new Route($postPattern, $defaults, [], [], "", [], [$method]));
            }

            $collection->add($name, new Route($pattern, $defaults, [], [], "", [], [$method]));

            if ($endpoint['variants']) {
                $defaults['_controller'] = sprintf('ONGRApiBundle:Variant:%s', strtolower($method));

                if ($method == Request::METHOD_POST || $method == Request::METHOD_GET) {
                    $variantPattern = $pattern . '/_variant';
                    $collection->add(
                        $name . '_variant_wi',
                        new Route($variantPattern, $defaults, [], [], "", [], [$method])
                    );
                }

                $variantPattern = $pattern . '/_variant/{variantId}';
                $collection->add($name . '_variant', new Route($variantPattern, $defaults, [], [], "", [], [$method]));
            }
        }
    }
Create route for REST action

@param RouteCollection $collection
@param string $document
@param array $endpoint
@param string $version