app = $app; } /** * @return User */ public function getAuthenticatedUser() { return $this->app['authentication']->getUser(); } public function render($view, array $parameters = [], Response $response = null) { /** @var \Twig_Environment $twig */ $twig = $this->app['twig']; if ($response instanceof StreamedResponse) { $response->setCallback(function () use ($twig, $view, $parameters) { $twig->display($view, $parameters); }); return $response; } if (null === $response) { $response = new Response(); } $response->setContent($twig->render($view, $parameters)); return $response; } /** * @param string $method * @param mixed $formType * @param array $options * @param mixed $data * @return FormInterface */ public function createApiForm($method = 'POST', $formType = 'form', array $options = [], $data = null) { return $this->app['form.factory']->createNamed( 'data', $formType, $data, array_merge(['method' => $method, 'csrf_protection' => false], $options) ); } /** * @param string $method * @param mixed $formType * @param array $options * @param mixed $data * @return FormBuilderInterface */ public function createApiFormBuilder($method = 'POST', $formType = 'form', array $options = [], $data = null) { return $this->app['form.factory']->createNamedBuilder( 'data', $formType, $data, array_merge(['method' => $method, 'csrf_protection' => false], $options) ); } /** * @param mixed $attributes * @param mixed $object * @return bool */ public function isGranted($attributes, $object = null) { /** @var AuthorizationChecker $authorizationChecker */ $authorizationChecker = $this->app['phraseanet.authorization_checker']; return $authorizationChecker->isGranted($attributes, $object); } }