Moved lib/API to lib/Router
- renamed lib/API/API.php to lib/Router/Front.php - updated namespaces in various file to account for namespace change
This commit is contained in:
@ -120,8 +120,12 @@ class Initializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
// legacy router
|
||||||
$this->setupRouter();
|
$this->setupRouter();
|
||||||
|
// new api (will replace legacy router completely)
|
||||||
$this->setupAPI();
|
$this->setupAPI();
|
||||||
|
|
||||||
|
$this->setupFrontRouter();
|
||||||
$this->setupPages();
|
$this->setupPages();
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
$this->handleFailedInitialization($e);
|
$this->handleFailedInitialization($e);
|
||||||
@ -187,8 +191,12 @@ class Initializer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function setupAPI() {
|
function setupAPI() {
|
||||||
$API = new \MailPoet\API\API();
|
|
||||||
$API->init();
|
}
|
||||||
|
|
||||||
|
function setupFrontRouter() {
|
||||||
|
$router = new Router\Front();
|
||||||
|
$router->init();
|
||||||
}
|
}
|
||||||
|
|
||||||
function runQueueSupervisor() {
|
function runQueueSupervisor() {
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Cron;
|
namespace MailPoet\Cron;
|
||||||
|
|
||||||
use MailPoet\API\API;
|
use MailPoet\Router\Front as FrontRouter;
|
||||||
use MailPoet\API\Endpoints\Queue as QueueAPI;
|
use MailPoet\Router\Queue as QueueEndpoint;
|
||||||
use MailPoet\Models\Setting;
|
use MailPoet\Models\Setting;
|
||||||
use MailPoet\Util\Security;
|
use MailPoet\Util\Security;
|
||||||
|
|
||||||
@ -40,9 +40,9 @@ class CronHelper {
|
|||||||
|
|
||||||
static function accessDaemon($token, $timeout = self::DAEMON_REQUEST_TIMEOUT) {
|
static function accessDaemon($token, $timeout = self::DAEMON_REQUEST_TIMEOUT) {
|
||||||
$data = array('token' => $token);
|
$data = array('token' => $token);
|
||||||
$url = API::buildRequest(
|
$url = FrontRouter::buildRequest(
|
||||||
QueueAPI::ENDPOINT,
|
QueueEndpoint::ENDPOINT,
|
||||||
QueueAPI::ACTION_RUN,
|
QueueEndpoint::ACTION_RUN,
|
||||||
$data
|
$data
|
||||||
);
|
);
|
||||||
$args = array(
|
$args = array(
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Newsletter\Links;
|
namespace MailPoet\Newsletter\Links;
|
||||||
|
|
||||||
use MailPoet\API\API;
|
use MailPoet\Router\Front as FrontRouter;
|
||||||
use MailPoet\API\Endpoints\Track as TrackAPI;
|
use MailPoet\Router\Track as TrackEndpoint;
|
||||||
use MailPoet\Models\NewsletterLink;
|
use MailPoet\Models\NewsletterLink;
|
||||||
use MailPoet\Newsletter\Shortcodes\Shortcodes;
|
use MailPoet\Newsletter\Shortcodes\Shortcodes;
|
||||||
use MailPoet\Util\Security;
|
use MailPoet\Util\Security;
|
||||||
@ -115,12 +115,12 @@ class Links {
|
|||||||
'queue' => $queue_id,
|
'queue' => $queue_id,
|
||||||
'hash' => $hash
|
'hash' => $hash
|
||||||
);
|
);
|
||||||
$API_action = ($matches[2][$index] === self::DATA_TAG_CLICK) ?
|
$router_action = ($matches[2][$index] === self::DATA_TAG_CLICK) ?
|
||||||
TrackAPI::ACTION_CLICK :
|
TrackEndpoint::ACTION_CLICK :
|
||||||
TrackAPI::ACTION_OPEN;
|
TrackEndpoint::ACTION_OPEN;
|
||||||
$link = API::buildRequest(
|
$link = FrontRouter::buildRequest(
|
||||||
TrackAPI::ENDPOINT,
|
TrackEndpoint::ENDPOINT,
|
||||||
$API_action,
|
$router_action,
|
||||||
$data
|
$data
|
||||||
);
|
);
|
||||||
$content = str_replace($match, $link, $content);
|
$content = str_replace($match, $link, $content);
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Newsletter;
|
namespace MailPoet\Newsletter;
|
||||||
|
|
||||||
use MailPoet\API\API;
|
use MailPoet\Router\Front as FrontRouter;
|
||||||
use MailPoet\API\Endpoints\ViewInBrowser as ViewInBrowserAPI;
|
use MailPoet\Router\ViewInBrowser as ViewInBrowserEndpoint;
|
||||||
use MailPoet\Models\Subscriber;
|
use MailPoet\Models\Subscriber;
|
||||||
|
|
||||||
class Url {
|
class Url {
|
||||||
@ -34,9 +34,9 @@ class Url {
|
|||||||
$queue['id'] :
|
$queue['id'] :
|
||||||
$queue
|
$queue
|
||||||
);
|
);
|
||||||
return API::buildRequest(
|
return FrontRouter::buildRequest(
|
||||||
ViewInBrowserAPI::ENDPOINT,
|
ViewInBrowserEndpoint::ENDPOINT,
|
||||||
ViewInBrowserAPI::ACTION_VIEW,
|
ViewInBrowserEndpoint::ACTION_VIEW,
|
||||||
$data
|
$data
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,17 +1,16 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\API;
|
namespace MailPoet\Router;
|
||||||
|
|
||||||
use MailPoet\Util\Helpers;
|
use MailPoet\Util\Helpers;
|
||||||
|
|
||||||
if(!defined('ABSPATH')) exit;
|
if(!defined('ABSPATH')) exit;
|
||||||
|
|
||||||
class API {
|
class Front {
|
||||||
public $api_request;
|
public $api_request;
|
||||||
public $endpoint;
|
public $endpoint;
|
||||||
public $action;
|
public $action;
|
||||||
public $data;
|
public $data;
|
||||||
const NAME = 'mailpoet_api';
|
const NAME = 'mailpoet_api';
|
||||||
const ENDPOINT_NAMESPACE = '\MailPoet\API\Endpoints\\';
|
|
||||||
const RESPONSE_ERROR = 404;
|
const RESPONSE_ERROR = 404;
|
||||||
|
|
||||||
function __construct($api_data = false) {
|
function __construct($api_data = false) {
|
||||||
@ -29,10 +28,10 @@ class API {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
$endpoint = self::ENDPOINT_NAMESPACE . ucfirst($this->endpoint);
|
$endpoint = ucfirst($this->endpoint);
|
||||||
if(!$this->api_request) return;
|
if(!$this->api_request) return;
|
||||||
if(!$this->endpoint || !class_exists($endpoint)) {
|
if(!$this->endpoint || !class_exists($endpoint)) {
|
||||||
self::terminateRequest(self::RESPONSE_ERROR, __('Invalid API endpoint.'));
|
self::terminateRequest(self::RESPONSE_ERROR, __('Invalid Router endpoint.'));
|
||||||
}
|
}
|
||||||
$this->callEndpoint(
|
$this->callEndpoint(
|
||||||
$endpoint,
|
$endpoint,
|
||||||
@ -43,7 +42,7 @@ class API {
|
|||||||
|
|
||||||
function callEndpoint($endpoint, $action, $data) {
|
function callEndpoint($endpoint, $action, $data) {
|
||||||
if(!method_exists($endpoint, $action)) {
|
if(!method_exists($endpoint, $action)) {
|
||||||
self::terminateRequest(self::RESPONSE_ERROR, __('Invalid API action.'));
|
self::terminateRequest(self::RESPONSE_ERROR, __('Invalid Router action.'));
|
||||||
}
|
}
|
||||||
call_user_func(
|
call_user_func(
|
||||||
array(
|
array(
|
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\API\Endpoints;
|
namespace MailPoet\Router;
|
||||||
|
|
||||||
use MailPoet\Cron\Daemon;
|
use MailPoet\Cron\Daemon;
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\API\Endpoints;
|
namespace MailPoet\Router;
|
||||||
|
|
||||||
use MailPoet\Subscription as UserSubscription;
|
use MailPoet\Subscription as UserSubscription;
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\API\Endpoints;
|
namespace MailPoet\Router;
|
||||||
|
|
||||||
use MailPoet\Statistics\Track\Clicks;
|
use MailPoet\Statistics\Track\Clicks;
|
||||||
use MailPoet\Statistics\Track\Opens;
|
use MailPoet\Statistics\Track\Opens;
|
@ -1,5 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\API\Endpoints;
|
namespace MailPoet\Router;
|
||||||
|
|
||||||
use MailPoet\Newsletter\ViewInBrowser as NewsletterViewInBrowser;
|
use MailPoet\Newsletter\ViewInBrowser as NewsletterViewInBrowser;
|
||||||
|
|
@ -1,8 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace MailPoet\Subscription;
|
namespace MailPoet\Subscription;
|
||||||
|
|
||||||
use MailPoet\API\API;
|
use MailPoet\Router\Front as FrontRouter;
|
||||||
use MailPoet\API\Endpoints\Subscription;
|
use MailPoet\Router\Subscription as SubscriptionEndpoint;
|
||||||
use MailPoet\Models\Subscriber;
|
use MailPoet\Models\Subscriber;
|
||||||
use MailPoet\Models\Setting;
|
use MailPoet\Models\Setting;
|
||||||
|
|
||||||
@ -45,10 +45,10 @@ class Url {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$params = array(
|
$params = array(
|
||||||
API::NAME,
|
FrontRouter::NAME,
|
||||||
'endpoint='.Subscription::ENDPOINT,
|
'endpoint='.SubscriptionEndpoint::ENDPOINT,
|
||||||
'action='.$action,
|
'action='.$action,
|
||||||
'data='.API::encodeRequestData($data)
|
'data='.FrontRouter::encodeRequestData($data)
|
||||||
);
|
);
|
||||||
|
|
||||||
// add parameters
|
// add parameters
|
||||||
|
Reference in New Issue
Block a user