File: /home/globfdxw/public_html/wp-content/plugins/wpforms-pdf/src/API/API.php
<?php
namespace WPFormsPDF\API;
use WPFormsPDF\API\Http\Request;
/**
* API class.
*
* @since 1.0.0
*/
class API {
/**
* Request instance.
*
* @since 1.0.0
*
* @var Request
*/
protected $request;
/**
* Constructor.
*
* @since 1.0.0
*/
public function __construct() {
$this->request = new Request();
}
/**
* Generate PDF.
*
* @since 1.0.0
*
* @param string $html HTML markup.
* @param array $options Optional. PDF generation options. Default empty array.
* @param array $images Optional. Images data. Default empty array.
* @param array $extra Optional. Extra data. Default empty array.
*
* @return string|array PDF content or error data.
*/
public function generate_pdf( string $html, array $options, array $images = [], array $extra = [] ) {
$args = [
'html' => $html,
'options' => $options,
'images' => $images,
'extra' => $extra,
];
$endpoint = '/generate';
$response = $this->request->post( $endpoint, $args );
if ( $response->has_errors() ) {
$error_data = $response->get_error_data();
wpforms_pdf()->helpers->log(
[
'message' => $response->get_log_message( $error_data ),
'base_url' => $this->request->get_request_base_url(),
'endpoint' => $endpoint,
'error_data' => $error_data,
'response' => $response,
'args' => $args,
],
'error'
);
return $error_data;
}
return $response->get_body();
}
}