Filter for croping

@param Request $request
@param string $endpoint

@return JsonResponse
966943
public function filterAction(Request $request, $endpoint)
    {
        $form = $this->createForm(CropType::class);

        $form->handleRequest($request);

        // Form invalid. Exit.
        if (!$form->isValid()) {
            return $this->createErrorResponse(
                $this->get('translator')->trans('Invalid crop parameters')
            );
        }

        // Else process crop
        try {
            return new JsonResponse(
                $this->get('jb_fileuploader.croper')->crop($endpoint, $form->getData())
            );
        } catch (\Exception $e) {
            return $this->createErrorResponse($e->getMessage());
        }
    }
629975
public function parse(Request $request)
    {
        if ($request->has($this->name)) {
            $this->applied = true;
            $this->value   = filter_var($request->input($this->name), FILTER_VALIDATE_BOOLEAN);
        }
    }
223633
public static function createSerializer(Service $api, $endpoint)
    {
        static $mapping = [
            'json'      => 'Aws\Api\Serializer\JsonRpcSerializer',
            'query'     => 'Aws\Api\Serializer\QuerySerializer',
            'rest-json' => 'Aws\Api\Serializer\RestJsonSerializer',
            'rest-xml'  => 'Aws\Api\Serializer\RestXmlSerializer'
        ];

        $proto = $api->getProtocol();

        if (isset($mapping[$proto])) {
            return new $mapping[$proto]($api, $endpoint);
        }

        if ($proto == 'ec2') {
            return new QuerySerializer($api, $endpoint, new Ec2ParamBuilder());
        }

        throw new \UnexpectedValueException(
            'Unknown protocol: ' . $api->getProtocol()
        );
    }
1193408
public function export(Endpoint $endpoint, bool $json = false): string
    {
        $schema = $this->compiler->compile($endpoint);

        if ($json) {
            $result = GraphQL::executeQuery($schema, self::INTROSPECTION_QUERY);

            return json_encode($result->toArray(), JSON_PRETTY_PRINT);
        }

        return SchemaPrinter::doPrint($schema);
    }
179281
protected function sendRequest(
        $method,
        $endpoint,
        array $params = []
    ) {
        $request = $this->request($method, $endpoint, $params);

        return $this->lastResponse = $this->client->sendRequest($request);
    }
782125
public function getResponseTransformations($api, $endpoint)
    {
        return isset($this->responseTransformations[$api][$endpoint]) ?
            $this->responseTransformations[$api][$endpoint] : [];
    }
400324
public function send(string $method, string $endpoint, array $parameters = null)
    {
        /** @var string|array $parameters */
        $data = $this->processor->prepare($method, $parameters);

        switch ($method) {
            case 'get':
                return $this->adapter->get(
                    $this->getEndpoint() . '/' . trim($endpoint, '/') . trim($data, '/')
                );
            case 'post':
                return $this->adapter->post(
                    $this->getEndpoint() . '/' . trim($endpoint, '/'),
                    $data ?? []
                );
        }
    }
332031
protected function request(string $method, string $endpoint, $json = null)
    {
        $uri = $this->buildUri($endpoint);
        $options = $json != null ? ['json' => $json] : [];

        try {
            $response = $this->client->request($method, $uri, $options);
        } catch (ClientException $exception) {
            throw $this->determineException($exception);
        }

        $body = (string) $response->getBody();

        return $this->jsonValidator($body) ? json_decode($body, true) : $body;
    }
30501
public function imageUploadAction(Request $request)
    {
        $image = new ImageField();
        /* @var $form Form */
        $form = $this->createForm(new UploadImage(), $image);
        $form->handleRequest($request);

        if (!$form->isValid()) {
            $errors = $form->getErrors();

            return new JsonResponse(['error' => $this->get('translator')->trans($errors[0]->getMessage())], 404);
        }

        // try upload file
        try {
            $this->get('anime_db.downloader')->imageField($image);

            return new JsonResponse([
                'path' => $image->getFilename(),
                'image' => $image->getWebPath(),
            ]);
        } catch (\InvalidArgumentException $e) {
            return new JsonResponse(['error' => $this->get('translator')->trans($e->getMessage())], 404);
        }
    }
414413
public function cropAction ()
    {
        $this->validateRequest();
        
        $imageManager = $this->container->get('thrace_media.imagemanager');
        $name = $this->getRequest()->get('name');
        $options = array();
        
        $options['x'] = $this->getRequest()->get('x', false);
        $options['y'] = $this->getRequest()->get('y', false);
        $options['w'] = $this->getRequest()->get('w', false);
        $options['h'] = $this->getRequest()->get('h', false);
        
        if (!$imageManager->crop($name, $options)){
            return new JsonResponse(array(
                'success' => false,
                'err_msg' => $this->container->get('translator')
                    ->trans('error.image_crop', array('name' => $name), 'ThraceMediaBundle')
            ));
        }
       
        $hash = $imageManager->checksumTemporaryFileByName($name);
        
        return new JsonResponse(array(
            'success' => true,
            'name'    => $name,
            'hash'    => $hash
        ));
    }
975053
function makeRequest(string $method, string $endpoint, array $options) {
        $request = new \CharlotteDunois\Yasmin\HTTP\APIRequest($this, $method, $endpoint, $options);
        return $this->add($request);
    }
138
public function schemaAction(Request $request)
    {
        $api = $this->decideApiAndEndpoint($request->getUri());
        $this->registerProxySources($api['apiName']);
        $this->apiLoader->addOptions($api);

        $schema = $this->apiLoader->getEndpointSchema(urldecode($api['endpoint']));
        $schema = $this->transformationHandler->transformSchema(
            $api['apiName'],
            $api['endpoint'],
            $schema,
            clone $schema
        );
        $response = new Response(json_encode($schema), 200);
        $response->headers->set('Content-Type', 'application/json');

        return $this->templating->renderResponse(
            'GravitonCoreBundle:Main:index.json.twig',
            array ('response' => $response->getContent()),
            $response
        );
    }
749443
public function request(Client $client, $endpoint, $options, $method = 'GET')
    {
        try {
            return $client->request($method, $endpoint, [
                'form_params' => $options,
            ]);
        } catch (ClientException $exception) {
            static::throwException(static::extractOriginalExceptionMessage($exception), $exception);
        }
    }
683656
public function delete(string $endPoint): string
    {
        $parsedEndPoint = self::parseEndPoint($endPoint);
        return $this->sendRequest($parsedEndPoint, "DELETE");
    }
1266543
public function imagesAction(Request $request)
    {
        $locator = $this->get('pattern_locator');
        $files = $locator->locate('*.gif', 'public/elementtypes', false);
        $prefix = $request->getBasePath().'/bundles/phlexibleelementtype/elementtypes/';

        foreach ($files as $file) {
            $data[basename($file)] = [
                'title' => basename($file),
                'url' => $prefix.basename($file),
            ];
        }

        ksort($data);
        $data = array_values($data);

        return new JsonResponse(['images' => $data]);
    }
211065
public function performContentApiRequest($endpoint, $payload)
    {
        $this->setupRequest($payload);
        $this->apiEndpoint = $endpoint;

        return $this->doDropboxApiContentRequest();
    }
863832
public function callEndpoint($endpoint, array $endpointParameters = [], $body = null, $method = HttpMethod::REQUEST_GET)
    {
        // Set the endpoint
        $this->setEndpoint($endpoint);
        // Set the parameters
        $this->setEndpointParameters($endpointParameters);
        // Set the body
        $this->setBody($body);
        // Set the HTTP method
        $this->setHttpMethod($method);
        // Call the endpoint
        $this->call();
        // return the result
        return $this->getResult();
    }