Create response.

@param null|array|MediaInterface $data
@param bool                      $iframe

@return Response
333054
private function createResponse($data, $iframe = false)
    {
        $serializer = SerializerBuilder::create()->build();

        if (is_array($data)) {
            foreach ($data as $k => $n) {
                if ($n instanceof MediaInterface) {
                    $data[$k] = $this->addInfosForFront($n);
                }
            }
        } else {
            if ($data instanceof MediaInterface) {
                $data = $this->addInfosForFront($data);
            }
        }

        if ($iframe) {
            return new Response(htmlentities($serializer->serialize($data, 'json')));
        } else {
            return new Response($serializer->serialize($data, 'json'));
        }
    }
168681
public static function clientException(ResponseInterface $response, $data)
    {
        $message = $response->getReasonPhrase();
        $code = $response->getStatusCode();
        $body = (string) $response->getBody();

        if (isset($data['meta'], $data['meta']['error_message'])) {
            $message = $data['meta']['error_message'];
        }
        if (isset($data['meta'], $data['meta']['code'])) {
            $code = $data['meta']['code'];
        }

        return new static($message, $code, $body);
    }
1353643
public static function CreateFromResponse(array $data)
    {
        if (array_key_exists("data", $data) && is_array($data["data"]))
        {
            $data = $data["data"];
        }
        $object_section = new self($data["name"]);
        $object_section->setDescription($data["description"]);

        if (!is_array($data["fields"]))
        {
            return $object_section;
        }
        foreach ($data["fields"] as $column => $fields)
        {
            if (!is_array($fields))
            {
                continue;
            }
            foreach ($fields as $field)
            {
                try
                {
                    $object_section->putFieldsInColumn($column, array(ObjectField::CreateFromResponse($field)));
                }
                catch (OntraportAPIException $e)
                {
                    // ignore the field if the data is malformed.
                }
            }
        }
        return $object_section;
    }
178866
protected function createResponse(PageInterface $page)
    {
        if ($page->getTarget()) {
            $page->addHeader('Location', $this->router->generate($page->getTarget()));
            $response = new Response('', 302, $page->getHeaders() ?: []);
        } else {
            $response = new Response('', 200, $page->getHeaders() ?: []);
        }

        return $response;
    }
1235501
protected function _buildIframe() {
		$source = $this->_stub['iframe-player'];
		$count = count($this->_match);

		for ($i = 1; $i <= $count; $i++) {
			$source = str_ireplace('$' . $i, $this->_match[$i - 1], $source);
		}

		//add custom params
		if ($this->_iframeParams) {
			$c = '?';
			if (strpos($source, '?') !== false) {
				$c = '&amp;';
			}
			$source .= $c . http_build_query($this->_iframeParams, '', '&amp;');
		}
		$attributes = '';
		//add custom attributes

		foreach ($this->_iframeAttributes as $key => $val) {
			//if === true, is an attribute without value
			//if === false, remove the attribute
			if ($val !== false) {
				$attributes .= ' ' . $key . ($val !== true ? '="' . $this->_esc($val) . '"' : '');
			}
		}

		// Transparent hack (http://groups.google.com/group/autoembed/browse_thread/thread/0ecdd9b898e12183)
		return sprintf('<iframe src="%s"%s></iframe>', $source, $attributes);
	}
878502
private function createResponse(array $unserialized, MessageFactoryInterface $messageFactory)
    {
        return $messageFactory->createResponse(
            $unserialized['status_code'],
            $unserialized['protocol_version'],
            $unserialized['headers'],
            $unserialized['body'],
            $unserialized['parameters']
        );
    }
135745
protected function createNewForm(Config $data, AdapterInterface $adapter)
    {
        $form = $this->createForm(ConfigFormType::class, $data, [
            'adapter' => $adapter,
            'action'  => $this->generateUrl(
                'integrated_channel_config_new',
                ['adapter' => $adapter->getManifest()->getName()]
            ),
            'method'  => 'POST',
        ]);

        $form->add('actions', ActionsType::class, ['buttons' => ['create', 'cancel']]);

        return $form;
    }
1299511
protected function respond($data, $status = Response::HTTP_OK, $headers = []) : JsonResponse
    {
        if ($data instanceof ElementInterface) {
            $data = new Document($data);
        }

        if ($data instanceof Document) {
            $data = $data->toArray();
        }

        return response()->json($data, $status, $headers)
            ->header('Content-Type', ApiRequestHandler::CONTENT_TYPE);
    }
1220690
public function createNew($data)
    {
        if ($data instanceof File) {
            /** @var $data File */
            $media = new Media();
            if (method_exists($data, 'getClientOriginalName')) {
                $media->setOriginalFilename($data->getClientOriginalName());
            } else {
                $media->setOriginalFilename($data->getFilename());
            }
            $media->setContent($data);

            $contentType = $this->mimeTypeGuesser->guess($media->getContent()->getPathname());
            $media->setContentType($contentType);

            return $media;
        }

        return null;
    }
480539
protected function __create(array $data, $index, $type, $id = null, array $parameters = []) {
        $parameters+=["api" => "create"];
        $api = strtolower($parameters["api"]) == "index" ? "index" : "create";
        unset($parameters["api"]);
        $result = $this->client->$api([
            'index' => $index,
            'type' => $type,
            'body' => $data] + ($id ? ['id' => $id] : []) + $parameters);
        if (array_key_exists('_shards', $result) && array_key_exists('failed', $result['_shards']) && $result['_shards']['failed'] > 0) {
            throw new Exception('Failed to create the document. Serialized results: ' + json_encode($result));
        } else {
            $result = $this->__find($result['_index'], $result['_type'], $result['_id']);
        }
        return $result;
    }
781290
public function create(array $data, MembershipInterface $author, ModelInterface $thread): PodiumResponse
    {
        /* @var $pollForm CategorisedFormInterface */
        $pollForm = $this->getForm();

        $pollForm->setAuthor($author);
        $pollForm->setThread($thread);

        if (!$pollForm->loadData($data)) {
            return PodiumResponse::error();
        }

        return $pollForm->create();
    }
660410
public function execute($data = null)
    {
        $this->controller->setResponse(new HtmlResponse(
            '',
            $data->response->getStatusCode(),
            $data->response->getHeaders()
        ));

        $result = $this->next->execute($data);

        $this->controller->setRedirect(null);

        return $result;
    }
484155
public function create($data, $productId = null)
    {
        if (isset($productId)) {
            return $this->client()->put($data, 'products/{productId}', ['productId' => $productId]);
        }

        return $this->client()->post($data, 'products');
    }
291097
public function create(array $data): PodiumResponse
    {
        /* @var $groupForm ModelFormInterface */
        $groupForm = $this->getForm();

        if (!$groupForm->loadData($data)) {
            return PodiumResponse::error();
        }

        return $groupForm->create();
    }
782928
public function process(DataObjectInterface $data = null)
    {
        if ( ! is_null($data)) {
            $this->data = $data;
        }

        $this->before();

        $this->doProcessing();

        $this->after();

        return $this->getResult();
    }
279450
public function respondWithData(array $data)
    {

        $responseData = $this->getResponseStructure(true, $data, '');
        $response = new JsonResponse($responseData, $this->getStatusCode(), $this->getHeaders());
        return $response;
    }
1342356
public static function createResponse($body, $mediaType = 'text/html', $code = 200)
    {
        return Factory::createResponse()
            ->withStatus($code)
            ->withHeader('Content-Type', $mediaType)
            ->withBody(Factory::createStream($body));
    }