QCharts/DevApiBundle/Controller/ApiDirectoryController.php
public function registerAction(Request $request)
    {
        $options = [];
        $this->get("security.token_storage");
        $authChecker = $this->get('security.authorization_checker');
        $roles = $this->getParameter('qcharts.user_roles');

        if (!$authChecker->isGranted($roles["admin"]))
        {
            return new JsonResponse(ApiController::getNotValidCredentials());
        }

        try
        {
            $formFactory = $this->get("form.factory");
            $doctrine = $this->get("doctrine");
            $directory = new Directory();
            /** @var FormInterface $form */
            $form = $formFactory->create(new DirectoryType($doctrine), $directory);
            $form->submit($request->request->get($form->getName()));

            if ($form->isValid())
            {
                $directoryService = $this->get("qcharts.directory.directory_service");
                $directoryService->add($form);

                $options = [
                    "status"=>201,
                    "textStatus"=>"Directory created"
                ];

            }

        }
        catch (OverlappingException $e)
        {
            $options = [
                "status"=>$e->getCode(),
                "textStatus"=>$e->getMessage()
            ];
        }
        finally
        {
            return new JsonResponse($options);
        }
    }
public function registerAction(Request $request)
    {
        $options = [];
        $this->get("security.token_storage");
        $authChecker = $this->get('security.authorization_checker');
        $roles = $this->getParameter('qcharts.user_roles');

        if (!$authChecker->isGranted($roles["admin"]))
        {
            return new JsonResponse(ApiController::getNotValidCredentials());
        }

        try
        {
            $formFactory = $this->get("form.factory");
            $doctrine = $this->get("doctrine");
            $directory = new Directory();
            /** @var FormInterface $form */
            $form = $formFactory->create(new DirectoryType($doctrine), $directory);
            $form->submit($request->request->get($form->getName()));

            if ($form->isValid())
            {
                $directoryService = $this->get("qcharts.directory.directory_service");
                $directoryService->add($form);

                $options = [
                    "status"=>201,
                    "textStatus"=>"Directory created"
                ];

            }

        }
        catch (OverlappingException $e)
        {
            $options = [
                "status"=>$e->getCode(),
                "textStatus"=>$e->getMessage()
            ];
        }
        finally
        {
            return new JsonResponse($options);
        }
    }
@ApiDoc(
description = "Registers a directory at the given directory",
parameters = {
{
"name" = "register[name]",
"description" = "Name of the directory",
"required" = true,
"dataType" = "string"
},
{
"name" = "register[parent]",
"description" = "The parent Id",
"required" = false,
"dataType" = "integer"
}
},
statusCodes = {
201 = "Entity created"
}
)

@param Request $request
@return JsonResponse