@param Request\Anime\AnimeStatsRequest $request

@return Model\Anime\AnimeStats
@throws BadResponseException
@throws ParserException
194687
public function getAnimeStats(Request\Anime\AnimeStatsRequest $request): Model\Anime\AnimeStats
    {
        $crawler = $this->ghoutte->request('GET', $request->getPath());
        try {
            $parser = new Parser\Anime\AnimeStatsParser($crawler);

            return $parser->getModel();
        } catch (\Exception $e) {
            throw ParserException::fromRequest($request, $e);
        }
    }
1021938
protected function doRequest($request)
    {
        if ($this->getRouter() === null) {
            throw new \BadMethodCallException("Router not set");
        }
        
        $this->reset(); // Reset before each HTTP request
        
        $psrRequest = $this->getRequestConvertor()->convert($request, $this->getBaseRequest());
        
        $router = $this->getRouter();
        $psrResponse = $router->handle($psrRequest, $this->getBaseResponse());
        
        return $this->getResponseConvertor()->convert($psrResponse);
    }
198202
public function indexAction(Request $request, $token)
    {
        // Token validation
        if ($this->getToken() !== $token) {
            throw new BadRequestHttpException('Token mismatch');
        }

        $data = $this->extractData($request);

        if(!$data){
            throw new BadRequestHttpException('Malformatted or missing data');
        }

        if(isset($data['event'])){
            $data = array($data);
        }
        /*
            Please note that the event types in the collection can be mixed.
            We group together all the events of the last second for the same webhook url.
        */
        // NOTE: use a better dispatcher such as rabbitMQ if you have a huge amount of events (sent, open, click can be a lot...)
        $dispatcher = $this->getDispatcher();

        foreach ($data as $key => $callbackData) {
            $type = $callbackData['event'];
            switch ($type) {
                case 'sent':
                    $dispatcher->dispatch(CallbackEvent::EVENT_SENT, new CallbackEvent($callbackData));
                    break;
                case 'open':
                    $dispatcher->dispatch(CallbackEvent::EVENT_OPEN, new CallbackEvent($callbackData));
                    break;
                case 'click':
                    $dispatcher->dispatch(CallbackEvent::EVENT_CLICK, new CallbackEvent($callbackData));
                    break;
                case 'bounce':
                    $dispatcher->dispatch(CallbackEvent::EVENT_BOUNCE, new CallbackEvent($callbackData));
                    break;
                case 'spam':
                    $dispatcher->dispatch(CallbackEvent::EVENT_SPAM, new CallbackEvent($callbackData));
                    break;
                case 'blocked':
                    $dispatcher->dispatch(CallbackEvent::EVENT_BLOCKED, new CallbackEvent($callbackData));
                    break;
                case 'unsub':
                    $dispatcher->dispatch(CallbackEvent::EVENT_UNSUB, new CallbackEvent($callbackData));
                    break;
                default:
                    throw new BadRequestHttpException('Type mismatch');
                    break;
            }
        }

        return $this->prepareResponse(200);
    }
389525
private function validateCreateRequest(Request $request)
    {
        if ($request->getContent() === '') {
            throw new BadRequestHttpException('Empty JSON data', null, 1500559729);
        }
        if (empty($request->get('login_name')) || empty($request->get('password'))) {
            throw new BadRequestHttpException('Incomplete credentials', null, 1500562647);
        }
    }
451392
public function ajaxIndexAction(Request $request): Response
    {
        if (!$request->isXmlHttpRequest()) {
            return $this->redirectToAction('index');
        }
        
        $attributeGroupId = (int)$request->request->get('id');
        $attributeGroup   = $this->getManager()->findAttributeGroup($attributeGroupId);
        
        return $this->jsonResponse([
            'attributes' => $this->getManager()->getRepository()->getAttributeSet($attributeGroup),
        ]);
    }
547839
public function cgetAction(Request $request)
    {
        try {
            /** @var ListRestHelperInterface $listRestHelper */
            $listRestHelper = $this->get('sulu_core.list_rest_helper');
            $securityChecker = $this->get('sulu_security.security_checker');

            $flat = $this->getBooleanRequestParameter($request, 'flat', false);
            $depth = $request->get('depth', 0);
            $parentId = $request->get('parentId', null);
            $limit = $request->get('limit', null);
            $offset = $this->getOffset($request, $limit);
            $search = $listRestHelper->getSearchPattern();
            $sortBy = $request->get('sortBy');
            $sortOrder = $request->get('sortOrder', 'ASC');
            $includeRoot = $this->getBooleanRequestParameter($request, 'includeRoot', false, false);
            $collectionManager = $this->getCollectionManager();

            if ('root' === $parentId) {
                $includeRoot = false;
                $parentId = null;
            }

            if ($flat) {
                $collections = $collectionManager->get(
                    $this->getRequestParameter($request, 'locale', true),
                    [
                        'depth' => $depth,
                        'parent' => $parentId,
                    ],
                    $limit,
                    $offset,
                    null !== $sortBy ? [$sortBy => $sortOrder] : []
                );
            } else {
                $collections = $collectionManager->getTree(
                    $this->getRequestParameter($request, 'locale', true),
                    $offset,
                    $limit,
                    $search,
                    $depth,
                    null !== $sortBy ? [$sortBy => $sortOrder] : [],
                    $securityChecker->hasPermission('sulu.media.system_collections', 'view')
                );
            }

            if ($includeRoot && !$parentId) {
                $collections = [
                    new RootCollection(
                        $this->get('translator')->trans('sulu_media.all_collections', [], 'admin'),
                        $collections
                    ),
                ];
            }

            $all = $collectionManager->getCount();

            $list = new ListRepresentation(
                $collections,
                self::$entityKey,
                'get_collections',
                $request->query->all(),
                $listRestHelper->getPage(),
                $listRestHelper->getLimit(),
                $all
            );

            $view = $this->view($list, 200);
        } catch (CollectionNotFoundException $cnf) {
            $view = $this->view($cnf->toArray(), 404);
        } catch (MediaException $me) {
            $view = $this->view($me->toArray(), 400);
        }

        return $this->handleView($view);
    }
595846
public function parse($request)
    {
        try {
            $parameters = Json::decode($request->getBody()->__toString(), $this->asArray);
            return $parameters === null ? [] : $parameters;
        } catch (InvalidArgumentException $e) {
            if ($this->throwException) {
                throw new BadRequestHttpException('Invalid JSON data in request body: ' . $e->getMessage());
            }

            return [];
        }
    }
360871
public function indexAction(Request $request)
    {
        $response = $this->getCacheTimeKeeper()->getResponse();
        // response was not modified for this request
        if ($response->isNotModified($request)) {
            return $response;
        }

        // update for Windows XP does not work
        $can_update = strpos(php_uname('v'), 'Windows XP') === false;

        $plugin = $request->request->get('plugin');
        $action = $this->getAction($plugin);

        // delete or install package
        switch ($action) {
            case 'delete':
                $this->get('anime_db.manipulator.composer')->removePackage($plugin['delete']);
                $plugin = $this->getPlugin('plugin/'.$plugin['delete'].'/');
                break;
            case 'install':
                $this->get('anime_db.manipulator.composer')
                    ->addPackage($plugin['install']['package'], $plugin['install']['version']);
                $plugin = $this->getPlugin('plugin/'.$plugin['install']['package'].'/');
                break;
        }

        return $this->render('AnimeDbCatalogBundle:Update:index.html.twig', [
            'can_update' => $can_update,
            'doc' => !$can_update ? $this->get('anime_db.api.client')->getSiteUrl(self::GUIDE_LINK) : '',
            'referer' => $request->headers->get('referer'),
            'plugin' => $action ? $plugin : [],
            'action' => $action,
        ], $response);
    }
1002934
public function addAction(Request $request)
    {
        $storage = new Storage();

        /* @var $form Form */
        $form = $this->createForm(new StorageForm(), $storage);

        if ($request->getMethod() == 'POST') {
            $form->handleRequest($request);
            if ($form->isValid()) {
                $em = $this->getDoctrine()->getManager();
                $em->persist($storage);
                $em->flush();

                return $this->redirect($this->generateUrl('storage_list'));
            }
        }

        return $this->render('AnimeDbCatalogBundle:Storage:add.html.twig', [
            'form' => $form->createView(),
            'guide' => $this->get('anime_db.api.client')->getSiteUrl(self::GUIDE_LINK),
        ]);
    }
1093775
public function indexAction(Request $request)
    {
        $response = $this->getCacheTimeKeeper()->getResponse('AnimeDbAppBundle:Notice');
        // response was not modified for this request
        if ($response->isNotModified($request)) {
            return $response;
        }

        $rep = $this->getRepository();
        $change_form = $this->createForm(new ChangeNotice())->handleRequest($request);
        if ($change_form->isValid() && ($notices = $change_form->getData()['notices'])) {
            switch ($change_form->getData()['action']) {
                case ChangeNotice::ACTION_SET_STATUS_SHOWN:
                    $rep->setStatus($notices->toArray(), Notice::STATUS_SHOWN);
                    break;
                case ChangeNotice::ACTION_SET_STATUS_CLOSED:
                    $rep->setStatus($notices->toArray(), Notice::STATUS_CLOSED);
                    break;
                case ChangeNotice::ACTION_REMOVE:
                    $rep->remove($notices->toArray());
            }

            return $this->redirect($this->generateUrl('notice_list'));
        }

        return $this->render('AnimeDbCatalogBundle:Notice:index.html.twig', [
            'has_notices' => $rep->count(),
        ], $response);
    }
85769
public function searchFillerAction(Request $request)
    {
        /* @var $chain ChainFiller */
        $chain = $this->get('anime_db.plugin.filler');
        $response = $this->getResponseFromChain($chain);

        // response was not modified for this request
        if ($response->isNotModified($request)) {
            return $response;
        }

        $entity = new SearchFiller($chain);
        /* @var $form Form */
        $form = $this->createForm(new SearchFillerForm(), $entity)->handleRequest($request);
        if ($form->isValid()) {
            return $this->redirect($entity->getFiller()->getLinkForFill($entity->getUrl()));
        }

        return $this->render('AnimeDbCatalogBundle:Fill:search_filler.html.twig', [
            'form' => $form->createView(),
        ], $response);
    }
347723
public function allAction(Request $request)
    {
        $model = $this->getModel();

        $content = $this->restUtils->serialize($model->findAll($request));

        $response = $this->getResponse()
            ->setStatusCode(Response::HTTP_OK)
            ->setContent($content);

        return $response;
    }
1368490
public static function fromParser(AnimeStatsParser $parser): AnimeStats
    {
        $instance = new self();
        $instance->watching = $parser->getWatching();
        $instance->completed = $parser->getCompleted();
        $instance->onHold = $parser->getOnHold();
        $instance->dropped = $parser->getDropped();
        $instance->planToWatch = $parser->getPlanToWatch();
        $instance->total = $parser->getTotal();
        $instance->scores = $parser->getScores();

        return $instance;
    }
969023
public function toResponse($request)
    {
        if (!empty($this->resource)) {
            return $this->resource->response($request)->setStatusCode($this->status())->withHeaders($this->headers);
        }

        ///
        $data = [
            'status_code' => $this->getStatusCode(),
            'message' => $this->getContent(),
        ];

        if (!empty($this->meta)) {
            $data['meta'] = $this->meta;
        }

        if ($this->debug && !empty($this->debugData)) {
            $data['debug'] = $this->debugData;
        }

        return response()->json($data, $this->status())->withHeaders($this->headers);
    }
1363081
public function listJsonAction(Request $request)
    {
        $totalEntities = $this->countTotal();
                
        $offset = intval($request->get('iDisplayStart'));
        $limit = intval($request->get('iDisplayLength'));
        $sortColumn = intval($request->get('iSortCol_0'));
        $sortDirection = $request->get('sSortDir_0');
        $search = $request->get('sSearch');
        $echo = intval($request->get('sEcho'));
        
        $entities = $this->findAllForDataTables($search, $sortColumn, $sortDirection, null, $request->getLocale());
        
        $totalFilteredEntities = count($entities->getScalarResult());

        // paginate
        $entities->setFirstResult($offset)
            ->setMaxResults($limit);

        $data = $entities->getResult();


        $response = array(
            'iTotalRecords'         => $totalEntities,
            'iTotalDisplayRecords'  => $totalFilteredEntities,
            'sEcho'                 => $echo,
            'aaData'                => $data
        );
        

        return new JsonResponse($response);
    }
1080998
public function whatYouWantAction(Request $request)
    {
        // app already installed
        if ($this->container->getParameter('anime_db.catalog.installed')) {
            return $this->redirect($this->generateUrl('home'));
        }

        $response = $this->getCacheTimeKeeper()->getResponse();
        // response was not modified for this request
        if ($response->isNotModified($request)) {
            return $response;
        }

        if ($request->isMethod('POST')) {
            $storage = $this->getRepository()->getLast();
            $this->get('event_dispatcher')->dispatch(StoreEvents::INSTALL_SAMPLES, new SamplesInstall($storage));

            return $this->redirect($this->generateUrl('install_end_skip', ['from' => 'install_sample']));
        }

        return $this->render('AnimeDbCatalogBundle:Install:what_you_want.html.twig', [
            'guide' => $this->get('anime_db.api.client')->getSiteUrl(self::GUIDE_LINK_SCAN),
        ], $response);
    }
960111
public function putDraftCollectionAction(Request $request)
    {
        $result = [];
        foreach ($request->request->all() as $data) {
            if (!isset($data['type']) || !isset($data['uid'])) {
                throw new BadRequestHttpException("type and/or uid is missing.");
            }

            try {
                $content = $this->updateClassContentDraft($data['type'], $data['uid'], $data);
                $result[] = [
                    'uid'        => $content->getUid(),
                    'type'       => $content->getContentType(),
                    'statusCode' => 200,
                    'message'    => 'OK',
                ];
            } catch (AccessDeniedException $e) {
                $result[] = [
                    'uid'        => $data['uid'],
                    'type'       => $data['type'],
                    'statusCode' => 401,
                    'message'    => $e->getMessage(),
                ];
            } catch (\Exception $e) {
                $result[] = [
                    'uid'        => $data['uid'],
                    'type'       => $data['type'],
                    'statusCode' => 500,
                    'message'    => $e->getMessage(),
                ];
            }
        }

        $this->getEntityManager()->flush();

        return $this->createJsonResponse($result);
    }