public function testCallInvalidAction() { $provider = $this->getMockBuilder('Vardius\\Bundle\\CrudBundle\\Data\\DataProviderInterface')->getMock(); $this->setExpectedException('Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException'); $controller = new CrudController($provider); $controller->callAction(null, new Request()); }
protected function getDoc(CrudController $controller, $actionKey, $options) { $section = ucfirst(ltrim($controller->getRoutePrefix(), '/')); $parameters = array_key_exists('parameters', $options) ? $options['parameters'] : []; $filters = $actionKey === 'list' ? $this->getFilters($section) : []; $form = $controller->getFormType(); $input = $form ? get_class($form) : ''; $config = ['resource' => true, 'section' => $section, 'description' => ucfirst($actionKey) . " action", 'statusCodes' => [200 => "OK", 201 => "Created", 202 => "Accepted", 203 => 'Non-Authoritative Information', 204 => 'No Content', 205 => 'Reset Content', 206 => 'Partial Content', 207 => 'Multi-Status', 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', 403 => 'Forbidden', 404 => 'Not Found', 405 => 'Method Not Allowed', 500 => 'Internal Server Error', 501 => 'Not Implemented', 502 => 'Bad Gateway', 503 => 'Service Unavailable', 504 => 'Gateway Timeout', 505 => 'HTTP Version Not Supported'], 'filters' => $filters, 'parameters' => $parameters]; $action = $controller->getAction($actionKey); $options = $action->getOptions(); if (array_key_exists('checkAccess', $options) && array_key_exists('attributes', $options['checkAccess'])) { $config['authentication'] = true; $config['authenticationRoles'] = $options['checkAccess']['attributes']; } if ($actionKey === 'add' || $actionKey === 'edit') { $config['input'] = $input; } return new ApiDoc($config); }
/** * @inheritDoc */ public function checkRole(CrudController $controller, $data = null) { $role = $this->options['checkAccess']; if (!empty($role)) { $attributes = []; if (array_key_exists('attributes', $role)) { $attributes = $role['attributes']; } $message = 'Access Denied.'; if (array_key_exists('message', $role)) { $message = (string) $role['message']; } if (!empty($attributes)) { $controller->checkAccess($attributes, $data, $message); } } }
/** * @param $routePrefix * @param $entityName * @param ListViewProviderInterface $listViewProvider * @param AbstractType $formType * @param CrudManagerInterface $crudManager * @param string $view * @param array|ActionsProvider $actions * * @throws \Exception * @return CrudController */ public function get($entityName, $routePrefix = '', ListViewProviderInterface $listViewProvider = null, AbstractType $formType = null, CrudManagerInterface $crudManager = null, $view = null, $actions = []) { $repo = $this->entityManager->getRepository($entityName); if ($repo === null) { throw new \Exception('CrudFactory: Invalid entity alias "' . $entityName . '"'); } $this->securityClassPool->addClass($repo->getClassName()); $dataProvider = new DataProvider($repo, $this->entityManager, $crudManager); $controller = new CrudController($dataProvider, $routePrefix, $listViewProvider, $formType, $view); $controller->setContainer($this->container); if ($actions instanceof ActionsProvider) { $controller->setActions($actions->getActions()); } elseif (!empty($actions)) { $controller->setActions(new ArrayCollection($actions)); } else { $controller->setActions($this->actions); } return $controller; }
/** * @inheritDoc */ public function getRefererUrl(CrudController $controller, Request $request, $params = []) : string { $referer = $request->headers->get('referer'); $baseUrl = $request->getBaseUrl(); $lastPath = substr($referer, strpos($referer, $baseUrl)); $lastPath = str_replace($baseUrl, '', $lastPath); $matcher = $controller->get('router')->getMatcher(); $parameters = $matcher->match($lastPath); $route = $parameters['_route']; return $controller->generateUrl($route, $params); }
/** * @return DataProviderInterface */ public function getDataProvider() : DataProviderInterface { return $this->controller->getDataProvider(); }
/** * @inheritDoc */ protected function getResponseHandler(CrudController $controller) { return $controller->get('vardius_admin.response.handler'); }
/** * @return ListView */ public function getListView() { return $this->controller->getListView(); }