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