src/Controller/CrudController.php
public function getRemap($sMethod, array $aData = [])
    {
        $oUri       = Factory::service('Uri');
        $oHttpCodes = Factory::service('HttpCodes');
        if ($oUri->segment(4)) {

            //  Test that there's not an explicit method defined for this
            $sMethod = 'get' . ucfirst($oUri->segment(4));
            if (method_exists($this, $sMethod)) {
                return $this->$sMethod();
            }

            $oItem = $this->lookUpResource($aData);
            if (!$oItem) {
                throw new ApiException(
                    'Resource not found',
                    $oHttpCodes::STATUS_NOT_FOUND
                );
            }

            $this->userCan(static::ACTION_READ, $oItem);
            $oResponse = Factory::factory('ApiResponse', 'nails/module-api');

            //  If there's a submethod defined, call that
            $sSubMethod = $oUri->segment(5);
            if ($sSubMethod && method_exists($this, $sSubMethod)) {
                $oResponse->setData($this->$sSubMethod($oItem));
            } elseif ($sSubMethod && !method_exists($this, $sSubMethod)) {
                throw new ApiException(
                    '"' . $sSubMethod . '" is not a valid subresource',
                    $oHttpCodes::STATUS_NOT_FOUND
                );
            } else {
                $oResponse->setData($this->formatObject($oItem));
            }

        } else {

            $this->userCan(static::ACTION_READ);

            $oInput = Factory::service('Input');
            $aData  = array_merge(static::CONFIG_LOOKUP_DATA, $aData);

            //  Paging
            $iPage = (int) $oInput->get(static::CONFIG_PAGE_PARAM) ?: 1;
            $iPage = $iPage < 0 ? $iPage * -1 : $iPage;

            //  Searching
            if ($oInput->get(static::CONFIG_SEARCH_PARAM)) {
                $aData['keywords'] = $oInput->get(static::CONFIG_SEARCH_PARAM);
            }

            // Requesting specific IDs
            if ($oInput->get(static::CONFIG_IDS_PARAM)) {
                $aData['where_in'] = [
                    [$this->oModel->getcolumn('id'), explode(',', $oInput->get(static::CONFIG_IDS_PARAM))],
                ];
            }

            $iTotal   = $this->oModel->countAll($aData);
            $aResults = array_map(
                [$this, 'formatObject'],
                $this->oModel->getAll(
                    $iPage,
                    static::CONFIG_PER_PAGE,
                    $aData
                )
            );

            $oResponse = Factory::factory('ApiResponse', 'nails/module-api')
                ->setData($aResults)
                ->setMeta([
                    'pagination' => [
                        'page'     => $iPage,
                        'per_page' => static::CONFIG_PER_PAGE,
                        'total'    => $iTotal,
                        'previous' => $this->buildUrl($iTotal, $iPage, -1),
                        'next'     => $this->buildUrl($iTotal, $iPage, 1),
                    ],
                ]);
        }

        return $oResponse;
    }
public function getRemap($sMethod, array $aData = [])
    {
        $oUri       = Factory::service('Uri');
        $oHttpCodes = Factory::service('HttpCodes');
        if ($oUri->segment(4)) {

            //  Test that there's not an explicit method defined for this
            $sMethod = 'get' . ucfirst($oUri->segment(4));
            if (method_exists($this, $sMethod)) {
                return $this->$sMethod();
            }

            $oItem = $this->lookUpResource($aData);
            if (!$oItem) {
                throw new ApiException(
                    'Resource not found',
                    $oHttpCodes::STATUS_NOT_FOUND
                );
            }

            $this->userCan(static::ACTION_READ, $oItem);
            $oResponse = Factory::factory('ApiResponse', 'nails/module-api');

            //  If there's a submethod defined, call that
            $sSubMethod = $oUri->segment(5);
            if ($sSubMethod && method_exists($this, $sSubMethod)) {
                $oResponse->setData($this->$sSubMethod($oItem));
            } elseif ($sSubMethod && !method_exists($this, $sSubMethod)) {
                throw new ApiException(
                    '"' . $sSubMethod . '" is not a valid subresource',
                    $oHttpCodes::STATUS_NOT_FOUND
                );
            } else {
                $oResponse->setData($this->formatObject($oItem));
            }

        } else {

            $this->userCan(static::ACTION_READ);

            $oInput = Factory::service('Input');
            $aData  = array_merge(static::CONFIG_LOOKUP_DATA, $aData);

            //  Paging
            $iPage = (int) $oInput->get(static::CONFIG_PAGE_PARAM) ?: 1;
            $iPage = $iPage < 0 ? $iPage * -1 : $iPage;

            //  Searching
            if ($oInput->get(static::CONFIG_SEARCH_PARAM)) {
                $aData['keywords'] = $oInput->get(static::CONFIG_SEARCH_PARAM);
            }

            // Requesting specific IDs
            if ($oInput->get(static::CONFIG_IDS_PARAM)) {
                $aData['where_in'] = [
                    [$this->oModel->getcolumn('id'), explode(',', $oInput->get(static::CONFIG_IDS_PARAM))],
                ];
            }

            $iTotal   = $this->oModel->countAll($aData);
            $aResults = array_map(
                [$this, 'formatObject'],
                $this->oModel->getAll(
                    $iPage,
                    static::CONFIG_PER_PAGE,
                    $aData
                )
            );

            $oResponse = Factory::factory('ApiResponse', 'nails/module-api')
                ->setData($aResults)
                ->setMeta([
                    'pagination' => [
                        'page'     => $iPage,
                        'per_page' => static::CONFIG_PER_PAGE,
                        'total'    => $iTotal,
                        'previous' => $this->buildUrl($iTotal, $iPage, -1),
                        'next'     => $this->buildUrl($iTotal, $iPage, 1),
                    ],
                ]);
        }

        return $oResponse;
    }
Handles GET requests

@param string $sMethod The method being called
@param array  $aData   Any data to apply to the requests

@return ApiResponse
@throws ApiException
@throws FactoryException