Make an API response from an existing Illuminate response.

@param \Illuminate\Http\Response $old

@return \Dingo\Api\Http\Response
514233
public static function makeFromExisting(IlluminateResponse $old)
    {
        $new = static::create($old->getOriginalContent(), $old->getStatusCode());

        $new->headers = $old->headers;

        return $new;
    }
590899
public function convertInfuseResponse(Response $res)
    {
        $response = new SymfonyResponse($res->getBody(), $res->getCode(), $res->headers());

        // transfer cookies
        foreach ($res->cookies() as $name => $params) {
            list($value, $expire, $path, $domain, $secure, $httponly) = $params;
            $cookie = new Cookie($name, $value, $expire, $path, $domain, $secure, $httponly);
            $response->headers->setCookie($cookie);
        }

        return $response;
    }
1335458
private function resultToResponse($result) : Response
  {
    switch (true) {
      // Response object
      case $result instanceof Response:
        return $result;
      // String -> transform to response
      case is_string($result) || is_numeric($result):
        return new Response($result);
      // Uri -> transform to redirect response
      case $result instanceof Uri:
        return new RedirectResponse($uri);
      // Array -> transform to json response
      case is_array($result) || is_object($result):
        return new JsonResponse($result);
      default:
        throw new \InvalidArgumentException('Invalid route handler return value');
    }
  }
1351086
public function handleHttpResponse(Response $response)
    {
        if ($this->newFormatModeEnabled) {
            $newResponse = $this->newFormattingService->formatResponse($response->getRaw());

            if ($newResponse->hasError()) {
                $error = $newResponse->getError();
                throw new Neo4jException(sprintf(
                    $error->getCode(),
                    $error->getMessage(),
                    Neo4jException::fromCode($error->getCode())
                ));
            }

            return $newResponse;
        }

        $this->checkResponseErrors($response->getBody());
        if ($this->autoFormatResponse) {
            $formatted = $this->formatResponse($response->getBody());
            $response->setResult($formatted->getResult());
            $response->setRows($formatted->geRows());
        }

        return $response;
    }
961344
public static function create($response)
    {
        if (is_array($response)) {
            return new Response($response[0], $response[1]);
        } elseif (is_int($response)) {
            return new Response($response);
        } elseif (is_string($response)) {
            return new Response(200, $response);
        } elseif ($response instanceof Response) {
            return $response;
        }
        return new Response;
    }
379587
public function activate($versionNumber, $oldVersionNumber = '')
    {
        // Add the assets
        $assetManager = $this->framework->getInstance('\\Zepi\\Web\\General\\Manager\\AssetManager');
        $assetManager->addAsset(AssetManager::CSS, 'bootstrap', 'vendor/twitter/bootstrap/dist/css/bootstrap.css');
        $assetManager->addAsset(AssetManager::CSS, 'bootstrap-theme', 'vendor/twitter/bootstrap/dist/css/bootstrap-theme.css', array('bootstrap'));
        $assetManager->addAsset(AssetManager::CSS, 'materialdesignicons', 'vendor/mervick/material-design-icons/css/material-icons.css');
        $assetManager->addAsset(AssetManager::CSS, 'zt-base', $this->directory . '/assets/css/base.css', array('bootstrap-theme'));
        $assetManager->addAsset(AssetManager::CSS, 'zt-theme', $this->directory . '/assets/css/theme.css', array('zt-base'));
        $assetManager->addAsset(AssetManager::CSS, 'zt-elements', $this->directory . '/assets/css/elements.css', array('zt-base'));
        $assetManager->addAsset(AssetManager::CSS, 'zt-form', $this->directory . '/assets/css/form.css', array('zt-base'));
        $assetManager->addAsset(AssetManager::CSS, 'zt-print', $this->directory . '/assets/css/print.css', array('zt-base'));
        
        $assetManager->addAsset(AssetManager::JS, 'modernizr', 'vendor/components/modernizr/modernizr.js');
        $assetManager->addAsset(AssetManager::JS, 'jquery', 'vendor/components/jquery/jquery.min.js');
        $assetManager->addAsset(AssetManager::JS, 'bootstrap', 'vendor/twitter/bootstrap/dist/js/bootstrap.min.js', array('jquery'));
        $assetManager->addAsset(AssetManager::JS, 'zt-main', $this->directory . '/assets/js/main.js', array('jquery'));
        
        $assetManager->addAsset(AssetManager::IMAGE, 'logo', $this->directory . '/assets/images/logo.svg');
        $assetManager->addAsset(AssetManager::IMAGE, 'logo-mail', $this->directory . '/assets/images/logo-mail.jpg');
        
        // Add the templates
        $templatesManager = $this->framework->getInstance('\\Zepi\\Web\\General\\Manager\\TemplatesManager');
        $templatesManager->addTemplate('\\Zepi\\Web\\ThemeZt\\Templates\\Header', $this->directory . '/templates/overall/Header.phtml');
        $templatesManager->addTemplate('\\Zepi\\Web\\ThemeZt\\Templates\\Footer', $this->directory . '/templates/overall/Footer.phtml');
        $templatesManager->addTemplate('\\Zepi\\Web\\ThemeZt\\Templates\\NavItemRoot', $this->directory . '/templates/snippets/NavItemRoot.phtml');
        $templatesManager->addTemplate('\\Zepi\\Web\\ThemeZt\\Templates\\NavItemSubmenu', $this->directory . '/templates/snippets/NavItemSubmenu.phtml');
        $templatesManager->addTemplate('\\Zepi\\Web\\ThemeZt\\Templates\\Mail\\Header', $this->directory . '/templates/mail/Header.phtml');
        $templatesManager->addTemplate('\\Zepi\\Web\\ThemeZt\\Templates\\Mail\\Footer', $this->directory . '/templates/mail/Footer.phtml');
        
        // Add the settings
        $configurationManager = $this->framework->getInstance('\\Zepi\\Core\\Utils\\Manager\\ConfigurationManager');
        $configurationManager->addSettingIfNotSet('web.defaultPage', '/');
        $configurationManager->saveConfigurationFile();
    }
1055433
protected function toIlluminateResponse($response, Exception $e)
    {
        if ($response instanceof SymfonyRedirectResponse) {
            $response = new RedirectResponse(
                $response->getTargetUrl(), $response->getStatusCode(), $response->headers->all()
            );
        } else {
            $response = new Response(
                $response->getContent(), $response->getStatusCode(), $response->headers->all()
            );
        }

        return $response->withException($e);
    }
971430
public function activate($versionNumber, $oldVersionNumber = '')
    {
        $runtimeManager = $this->framework->getRuntimeManager();
        $runtimeManager->addFilterHandler('\\Zepi\\Core\\AccessControl\\Filter\\AccessLevelManager\\RemoveAccessLevel', '\\Zepi\\Core\\AccessControl\\FilterHandler\\RevokePermissionsForRemovedAccessLevel');
        $runtimeManager->addFilterHandler('\\Zepi\\Turbo\\Filter\\VerifyEventName', '\\Zepi\\Core\\AccessControl\\FilterHandler\\CheckEventAccessForSession');
        
        $runtimeManager->addEventHandler('\\Zepi\\Core\\AccessControl\\Event\\RedirectRequestWithoutSession', '\\Zepi\\Core\\AccessControl\\EventHandler\\RedirectRequestWithoutSession');
        $runtimeManager->addEventHandler('\\Zepi\\Core\\AccessControl\\Event\\DisplayNoAccessMessage', '\\Zepi\\Core\\AccessControl\\EventHandler\\DisplayNoAccessMessage');
        
        // Data Sources
        $dataSourceManager = $this->framework->getDataSourceManager();
        $dataSourceManager->addDataSource(
            '\\Zepi\\Core\\AccessControl\\DataSource\\AccessEntitiesDataSourceInterface',
            '\\Zepi\\DataSource\\Doctrine',
            '\\Zepi\\Core\\AccessControl\\DataSource\\AccessEntitiesDataSourceDoctrine'
        );
        
        $dataSourceManager->addDataSource(
            '\\Zepi\\Core\\AccessControl\\DataSource\\PermissionsDataSourceInterface',
            '\\Zepi\\DataSource\\Doctrine',
            '\\Zepi\\Core\\AccessControl\\DataSource\\PermissionsDataSourceDoctrine'
        );
        
        // Access Levels
        $accessLevelsManager = $this->framework->getInstance('\\Zepi\\Core\\AccessControl\\Manager\\AccessLevelManager');
        $accessLevelsManager->addAccessLevel(new \Zepi\Core\AccessControl\Entity\AccessLevel(
            '\\Global\\*',
            'Global Super User',
            'Super user privileges. Can do everything.',
            '\\Zepi\\Core\\AccessControl'
        ));
        
        $accessLevelsManager->addAccessLevel(new \Zepi\Core\AccessControl\Entity\AccessLevel(
            '\\Global\\Disabled',
            'Disabled User',
            'A disabled user. Can do nothing, not even login.',
            '\\Zepi\\Core\\AccessControl'
        ));
        
        $accessLevelsManager->addAccessLevel(new \Zepi\Core\AccessControl\Entity\AccessLevel(
            '\\Global\\Active',
            'Active User',
            'A active user. Can login and change the user password.',
            '\\Zepi\\Core\\AccessControl'
        ));
    }
794672
private function createResponse(GuzzleResponse $response)
    {
        $body = $response->getBody();

        return $this->responseFactory->createResponse(
            $response->getStatusCode(),
            null,
            $response->getHeaders(),
            isset($body) ? $body->detach() : null,
            $response->getProtocolVersion()
        );
    }
320386
public static function merge(array $old, array $new)
    {
        foreach ($new as $key => $value) {
            if (isset($old[$key]) && is_array($old[$key]) && is_array($value)) {
                $old[$key] = self::merge($old[$key], $value);
            } else {
                $old[$key] = $value;
            }
        }

        return $old;
    }
1268382
protected function buildResponse()
    {
        $response = new Response();
        if ($this->viewCache === true) {
            $response->setPublic();

            if ($this->ttlCache === true) {
                $response->setSharedMaxAge(
                    $this->defaultTtl
                );
            }

            // Make the response vary against Cookie header ensures that an HTTP
            // reverse proxy caches the different possible variations of the
            // response as it can depend on user role for instance. X-User-Hash cannot
            // be used since the website toolbar can have Owner( Self ) Policy Limitation.
            $response->setVary('Cookie');
        }

        return $response;
    }
281370
public function mapResponse($success, $response)
    {
        return (new Response())->setRaw($response)->map([
            'isRedirect'    => false,
            'success'       => true,
            'reference'     => null,
            'message'       => null,
            'test'          => false,
            'authorization' => null,
            'status'        => $response['status'],
            'errorCode'     => false,
            'type'          => $response['type'],
        ]);
    }
781450
public function fromResponse($response)
    {
        $this->page        = $response->list_info->page;
        $this->num_pages   = $response->list_info->num_pages;
        $this->num_results = $response->list_info->num_results;
        $this->page_size   = $response->list_info->page_size;

        property_exists($response, $this->list_type) && $this->setCollection($response->{$this->list_type});

        return $this;
    }
824918
public function revive()
    {
        if ($this->isStale !== true) {
            return $this;
        }
        
        $response = clone $this;
        
        $response->status = $this->createGlobalResponseStatus($this->status)
            ->withProtocolVersion($this->getProtocolVersion());
        $response->headers = $this->createGlobalResponseHeaders($this->getHeaders());
        
        if ($response->body instanceof OutputBufferStream) {
            $response->body->useGlobally();
        }
        
        $response->isStale = false;
        
        return $response;
    }
972891
public function mergeAttributes( $old, $new ) {
		$attributes = [
			'methods' => $this->mergeMethodsAttribute(
				(array) Arr::get( $old, 'methods', [] ),
				(array) Arr::get( $new, 'methods', [] )
			),

			'condition' => $this->mergeConditionAttribute(
				Arr::get( $old, 'condition', null ),
				Arr::get( $new, 'condition', null )
			),

			'middleware' => $this->mergeMiddlewareAttribute(
				(array) Arr::get( $old, 'middleware', [] ),
				(array) Arr::get( $new, 'middleware', [] )
			),

			'namespace' => $this->mergeNamespaceAttribute(
				Arr::get( $old, 'namespace', '' ),
				Arr::get( $new, 'namespace', '' )
			),

			'handler' => $this->mergeHandlerAttribute(
				Arr::get( $old, 'handler', '' ),
				Arr::get( $new, 'handler', '' )
			),

			'query' => $this->mergeQueryAttribute(
				Arr::get( $old, 'query', null ),
				Arr::get( $new, 'query', null )
			),
		];

		return $attributes;
	}
870282
private function decorateResponse(Response $response)
    {
        if ($response instanceof Http\Response) {
            return $response;
        }

        return new Http\Response($response);
    }
1206963
public function fromIncomingResponse(RequestInterface $originalRequest, ResponseInterface $response = null)
    {
        $span = $originalRequest->getHeader('X-B3-SpanId');
        $trace = $originalRequest->getHeader('X-B3-TraceId');

        if (empty($span) || empty($trace)) {
            throw new \InvalidArgumentException('Unable to find the original request properties');
        }

        return new Span(
            Identifier::fromString($span),
            $this->getName($originalRequest),
            Identifier::fromString($trace),
            [
                new Annotation(Annotation::CLIENT_RECEIVE, $this->clock->microseconds(), $this->endpointResolver->resolve()),
            ],
            [
                new BinaryAnnotation('http.status', $response !== null ? $response->getStatusCode() : 0, BinaryAnnotation::TYPE_INTEGER_16),
            ]
        );
    }