Passes AccessControl to JSON API via constructor parameter
Removes passing AccessControl to individual API endpoints
This commit is contained in:
@@ -1,11 +1,14 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\API;
|
namespace MailPoet\API;
|
||||||
|
|
||||||
|
use MailPoet\Config\AccessControl;
|
||||||
|
|
||||||
if(!defined('ABSPATH')) exit;
|
if(!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
class API {
|
class API {
|
||||||
static function JSON() {
|
static function JSON() {
|
||||||
return new \MailPoet\API\JSON\API();
|
$access_control = new AccessControl();
|
||||||
|
return new \MailPoet\API\JSON\API($access_control);
|
||||||
}
|
}
|
||||||
|
|
||||||
static function MP($version) {
|
static function MP($version) {
|
||||||
|
@@ -22,8 +22,8 @@ class API {
|
|||||||
private $access_control;
|
private $access_control;
|
||||||
const CURRENT_VERSION = 'v1';
|
const CURRENT_VERSION = 'v1';
|
||||||
|
|
||||||
function __construct() {
|
function __construct(AccessControl $access_control) {
|
||||||
$this->access_control = new AccessControl();
|
$this->access_control = $access_control;
|
||||||
foreach($this->_available_api_versions as $available_api_version) {
|
foreach($this->_available_api_versions as $available_api_version) {
|
||||||
$this->addEndpointNamespace(
|
$this->addEndpointNamespace(
|
||||||
sprintf('%s\%s', __NAMESPACE__, $available_api_version),
|
sprintf('%s\%s', __NAMESPACE__, $available_api_version),
|
||||||
@@ -128,7 +128,7 @@ class API {
|
|||||||
throw new \Exception(__('Invalid API endpoint.', 'mailpoet'));
|
throw new \Exception(__('Invalid API endpoint.', 'mailpoet'));
|
||||||
}
|
}
|
||||||
|
|
||||||
$endpoint = new $this->_request_endpoint_class($this->access_control);
|
$endpoint = new $this->_request_endpoint_class();
|
||||||
|
|
||||||
// check the accessibility of the requested endpoint's action
|
// check the accessibility of the requested endpoint's action
|
||||||
// by default, an endpoint's action is considered "private"
|
// by default, an endpoint's action is considered "private"
|
||||||
|
Reference in New Issue
Block a user