mirror of
				https://github.com/elyby/oauth2-server.git
				synced 2025-05-31 14:12:07 +05:30 
			
		
		
		
	Getter and setter for the payload and ability to pass options to json_encode
This commit is contained in:
		@@ -33,6 +33,11 @@ class OAuthServerException extends \Exception
 | 
			
		||||
     */
 | 
			
		||||
    private $redirectUri;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @var  array
 | 
			
		||||
     */
 | 
			
		||||
    private $payload;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Throw a new exception.
 | 
			
		||||
     *
 | 
			
		||||
@@ -50,6 +55,33 @@ class OAuthServerException extends \Exception
 | 
			
		||||
        $this->errorType = $errorType;
 | 
			
		||||
        $this->hint = $hint;
 | 
			
		||||
        $this->redirectUri = $redirectUri;
 | 
			
		||||
        $this->payload = [
 | 
			
		||||
            'error'   => $errorType,
 | 
			
		||||
            'message' => $message,
 | 
			
		||||
        ];
 | 
			
		||||
        if ($hint !== null) {
 | 
			
		||||
            $this->payload['hint'] = $hint;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Returns the current payload.
 | 
			
		||||
     *
 | 
			
		||||
     * @return array
 | 
			
		||||
     */
 | 
			
		||||
    public function getPayload()
 | 
			
		||||
    {
 | 
			
		||||
        return $this->payload;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Updates the current payload.
 | 
			
		||||
     *
 | 
			
		||||
     * @param array $payload
 | 
			
		||||
     */
 | 
			
		||||
    public function setPayload(array $payload)
 | 
			
		||||
    {
 | 
			
		||||
        $this->payload = $payload;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@@ -205,21 +237,15 @@ class OAuthServerException extends \Exception
 | 
			
		||||
     *
 | 
			
		||||
     * @param ResponseInterface $response
 | 
			
		||||
     * @param bool              $useFragment True if errors should be in the URI fragment instead of query string
 | 
			
		||||
     * @param int                $jsonOptions options passed to json_encode
 | 
			
		||||
     *
 | 
			
		||||
     * @return ResponseInterface
 | 
			
		||||
     */
 | 
			
		||||
    public function generateHttpResponse(ResponseInterface $response, $useFragment = false)
 | 
			
		||||
    public function generateHttpResponse(ResponseInterface $response, $useFragment = false, $jsonOptions = 0)
 | 
			
		||||
    {
 | 
			
		||||
        $headers = $this->getHttpHeaders();
 | 
			
		||||
 | 
			
		||||
        $payload = [
 | 
			
		||||
            'error'   => $this->getErrorType(),
 | 
			
		||||
            'message' => $this->getMessage(),
 | 
			
		||||
        ];
 | 
			
		||||
 | 
			
		||||
        if ($this->hint !== null) {
 | 
			
		||||
            $payload['hint'] = $this->hint;
 | 
			
		||||
        }
 | 
			
		||||
        $payload = $this->getPayload();
 | 
			
		||||
 | 
			
		||||
        if ($this->redirectUri !== null) {
 | 
			
		||||
            if ($useFragment === true) {
 | 
			
		||||
@@ -235,7 +261,7 @@ class OAuthServerException extends \Exception
 | 
			
		||||
            $response = $response->withHeader($header, $content);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        $response->getBody()->write(json_encode($payload));
 | 
			
		||||
        $response->getBody()->write(json_encode($payload, $jsonOptions));
 | 
			
		||||
 | 
			
		||||
        return $response->withStatus($this->getHttpStatusCode());
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user