diff --git a/lib/API/JSON/API.php b/lib/API/JSON/API.php index 5f9ec15bc6..2cf82a8cb9 100644 --- a/lib/API/JSON/API.php +++ b/lib/API/JSON/API.php @@ -4,10 +4,12 @@ namespace MailPoet\API\JSON; use MailPoet\Config\AccessControl; use MailPoet\Settings\SettingsController; use MailPoet\Subscription\Captcha; +use MailPoet\Tracy\ApiPanel\ApiPanel; use MailPoetVendor\Psr\Container\ContainerInterface; use MailPoet\Util\Helpers; use MailPoet\Util\Security; use MailPoet\WP\Functions as WPFunctions; +use Tracy\Debugger; if (!defined('ABSPATH')) exit; @@ -164,6 +166,10 @@ class API { throw new \Exception(__('Invalid API endpoint method.', 'mailpoet')); } + if (class_exists(Debugger::class)) { + ApiPanel::init($endpoint, $this->_request_method, $this->_request_data); + } + // check the accessibility of the requested endpoint's action // by default, an endpoint's action is considered "private" if (!$this->validatePermissions($this->_request_method, $endpoint->permissions)) { diff --git a/lib/Tracy/ApiPanel/ApiPanel.php b/lib/Tracy/ApiPanel/ApiPanel.php new file mode 100644 index 0000000000..a2c35b5f22 --- /dev/null +++ b/lib/Tracy/ApiPanel/ApiPanel.php @@ -0,0 +1,51 @@ +endpoint = $endpoint; + $this->request_method = $request_method; + $this->request_data = $request_data; + $this->endpoint_reflection = new ReflectionClass($endpoint); + } + + function getTab() { + $img = ''; + return $img . '' . $this->getEndpointName() . ''; + } + + function getPanel() { + ob_start(); + require __DIR__ . '/api-panel.phtml'; + return ob_get_clean(); + } + + static function init($endpoint, $request_method, $request_data) { + Debugger::getBar()->addPanel(new static($endpoint, $request_method, $request_data)); + } + + private function getEndpointName() { + return $this->endpoint_reflection->getShortName() . '::' . $this->request_method . '()'; + } +} diff --git a/lib/Tracy/ApiPanel/api-panel.phtml b/lib/Tracy/ApiPanel/api-panel.phtml new file mode 100644 index 0000000000..9ad085480e --- /dev/null +++ b/lib/Tracy/ApiPanel/api-panel.phtml @@ -0,0 +1,40 @@ + +

API call

+ + + + + + + + + +
Endpoint
endpoint_reflection->getName() ?>
Method
request_method . '()' ?>
+ +request_data)): ?> +
+

Data

+
+ + + + + + request_data as $name => $value): ?> + + + + + +
NameValue
+
+