ZF\Apigility\Admin\Controller\InputFilterController::indexAction PHP Метод

indexAction() публичный Метод

public indexAction ( )
    public function indexAction()
    {
        $event = $this->getEvent();
        $routeMatch = $event->getRouteMatch();
        $route = $this->deriveRouteName($routeMatch->getMatchedRouteName());
        $request = $this->getRequest();
        $module = $this->params()->fromRoute('name', false);
        $controller = $this->params()->fromRoute('controller_service_name', false);
        $inputFilterName = $this->params()->fromRoute('input_filter_name', false);
        if (!$module || !$this->model->moduleExists($module)) {
            return new ApiProblemResponse(new ApiProblem(404, 'The module specified does not exist'));
        }
        if (!$controller || !$this->model->controllerExists($module, $controller)) {
            return new ApiProblemResponse(new ApiProblem(404, 'The controller specified does not exist'));
        }
        switch ($request->getMethod()) {
            case $request::METHOD_GET:
                $result = $this->model->fetch($module, $controller, $inputFilterName);
                if (false === $result) {
                    return new ApiProblemResponse(new ApiProblem(404, 'The input filter specified does not exist'));
                }
                if ($result instanceof InputFilterCollection) {
                    $result = new HalCollection($result);
                    $result->setCollectionName('input_filter');
                    $result->getLinks()->add(Link::factory(['rel' => 'self', 'route' => ['name' => $route, 'params' => ['name' => $module, 'controller_service_name' => str_replace('\\', '-', $controller)]]]));
                    $result->setEntityRoute($route);
                    break;
                }
                $name = $result['input_filter_name'];
                $result = new HalEntity($result, $name);
                $this->injectEntitySelfLink($result->getLinks(), $route, $module, $controller, $name);
                break;
            case $request::METHOD_POST:
                if ($inputFilterName) {
                    return new ApiProblemResponse(new ApiProblem(400, 'POST requests are not allowed to individual input filters'));
                }
                // Intentionally not breaking, as remainder of logic remains the same as PUT
            // Intentionally not breaking, as remainder of logic remains the same as PUT
            case $request::METHOD_PUT:
                $inputFilter = $this->bodyParams();
                $result = $this->model->update($module, $controller, $inputFilter);
                if (!$result) {
                    return new ApiProblemResponse(new ApiProblem(500, 'There was an unexpected error updating the input filter;' . ' please verify the module and controller specified are valid'));
                }
                $name = $result['input_filter_name'];
                $result = new HalEntity($result, $name);
                $this->injectEntitySelfLink($result->getLinks(), $route, $module, $controller, $name);
                break;
            case $request::METHOD_DELETE:
                if (empty($inputFilterName)) {
                    return new ApiProblemResponse(new ApiProblem(400, 'The input filter name has not been specified'));
                }
                $result = $this->model->remove($module, $controller, $inputFilterName);
                if (!$result) {
                    return new ApiProblemResponse(new ApiProblem(404, 'The input filter specified does not exist'));
                }
                return $this->getResponse()->setStatusCode(204);
        }
        $e = $this->getEvent();
        $e->setParam('ZFContentNegotiationFallback', 'HalJson');
        return new ViewModel(['payload' => $result]);
    }