Moved some more stuff to new structure
This commit is contained in:
parent
2ef67de718
commit
e68ecf50c6
@ -4,9 +4,11 @@ namespace Core;
|
|||||||
|
|
||||||
// Responsible for loading in all necessary classes. AKA a poor man's DI solution.
|
// Responsible for loading in all necessary classes. AKA a poor man's DI solution.
|
||||||
use BusinessLogic\Category\CategoryRetriever;
|
use BusinessLogic\Category\CategoryRetriever;
|
||||||
|
use BusinessLogic\Security\BanRetriever;
|
||||||
use DataAccess\CategoryGateway;
|
use DataAccess\CategoryGateway;
|
||||||
|
use DataAccess\Security\BanGateway;
|
||||||
|
|
||||||
class DependencyManager {
|
class ApplicationContext {
|
||||||
public $get;
|
public $get;
|
||||||
|
|
||||||
function __construct() {
|
function __construct() {
|
||||||
@ -14,5 +16,8 @@ class DependencyManager {
|
|||||||
|
|
||||||
$this->get['CategoryGateway'] = new CategoryGateway();
|
$this->get['CategoryGateway'] = new CategoryGateway();
|
||||||
$this->get['CategoryRetriever'] = new CategoryRetriever($this->get['CategoryGateway']);
|
$this->get['CategoryRetriever'] = new CategoryRetriever($this->get['CategoryGateway']);
|
||||||
|
|
||||||
|
$this->get['BanGateway'] = new BanGateway();
|
||||||
|
$this->get['BanRetriever'] = new BanRetriever($this->get['BanGateway']);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,25 +1,35 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
// Responsible for loading in all necessary scripts and kicking off the DependencyManager
|
// Responsible for loading in all necessary scripts and kicking off the DependencyManager
|
||||||
|
// Core requirements
|
||||||
define('IN_SCRIPT', 1);
|
define('IN_SCRIPT', 1);
|
||||||
define('HESK_PATH', '../');
|
define('HESK_PATH', '../');
|
||||||
require_once(__DIR__ . '/core/common.php');
|
require_once(__DIR__ . '/../hesk_settings.inc.php');
|
||||||
|
require_once(__DIR__ . '/../inc/common.inc.php');
|
||||||
|
require_once(__DIR__ . '/core/output.php');
|
||||||
require_once(__DIR__ . '/Link.php');
|
require_once(__DIR__ . '/Link.php');
|
||||||
require_once(__DIR__ . '/../hesk_settings.inc.php');
|
require_once(__DIR__ . '/../hesk_settings.inc.php');
|
||||||
|
|
||||||
// FILES
|
// Mods for HESK API Files
|
||||||
require_once(__DIR__ . '/http_response_code.php');
|
require_once(__DIR__ . '/http_response_code.php');
|
||||||
|
|
||||||
|
// Categories
|
||||||
require_once(__DIR__ . '/dao/category/CategoryGateway.php');
|
require_once(__DIR__ . '/dao/category/CategoryGateway.php');
|
||||||
require_once(__DIR__ . '/businesslogic/category/CategoryRetriever.php');
|
require_once(__DIR__ . '/businesslogic/category/CategoryRetriever.php');
|
||||||
require_once(__DIR__ . '/businesslogic/category/Category.php');
|
require_once(__DIR__ . '/businesslogic/category/Category.php');
|
||||||
require_once(__DIR__ . '/controllers/CategoryController.php');
|
require_once(__DIR__ . '/controllers/CategoryController.php');
|
||||||
|
|
||||||
|
// Banned Emails / IP Addresses
|
||||||
|
require_once(__DIR__ . '/dao/security/BanGateway.php');
|
||||||
|
require_once(__DIR__ . '/businesslogic/security/BanRetriever.php');
|
||||||
|
require_once(__DIR__ . '/businesslogic/security/BannedEmail.php');
|
||||||
|
require_once(__DIR__ . '/businesslogic/security/BannedIp.php');
|
||||||
|
|
||||||
hesk_load_api_database_functions();
|
hesk_load_api_database_functions();
|
||||||
|
|
||||||
// HESK files that require database access
|
// HESK files that require database access
|
||||||
require_once(__DIR__ . '/../inc/custom_fields.inc.php');
|
require_once(__DIR__ . '/../inc/custom_fields.inc.php');
|
||||||
|
|
||||||
require_once(__DIR__ . '/DependencyManager.php');
|
// Load the ApplicationContext
|
||||||
|
require_once(__DIR__ . '/ApplicationContext.php');
|
||||||
$applicationContext = new \Core\DependencyManager();
|
$applicationContext = new \Core\ApplicationContext();
|
@ -1,10 +1,4 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* Created by PhpStorm.
|
|
||||||
* User: user
|
|
||||||
* Date: 1/16/17
|
|
||||||
* Time: 10:10 PM
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace BusinessLogic\Category;
|
namespace BusinessLogic\Category;
|
||||||
|
|
||||||
|
@ -6,15 +6,23 @@ namespace BusinessLogic\Security;
|
|||||||
use DataAccess\Security\BanGateway;
|
use DataAccess\Security\BanGateway;
|
||||||
|
|
||||||
class BanRetriever {
|
class BanRetriever {
|
||||||
|
/**
|
||||||
|
* @var BanGateway
|
||||||
|
*/
|
||||||
|
private $banGateway;
|
||||||
|
|
||||||
|
function __construct($banGateway) {
|
||||||
|
$this->banGateway = $banGateway;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $email
|
* @param $email
|
||||||
* @param $heskSettings
|
* @param $heskSettings
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
static function isEmailBanned($email, $heskSettings) {
|
function isEmailBanned($email, $heskSettings) {
|
||||||
require_once(__DIR__ . '/../../dao/security/BanGateway.php');
|
|
||||||
|
|
||||||
$bannedEmails = BanGateway::getEmailBans($heskSettings);
|
$bannedEmails = $this->banGateway->getEmailBans($heskSettings);
|
||||||
|
|
||||||
foreach ($bannedEmails as $bannedEmail) {
|
foreach ($bannedEmails as $bannedEmail) {
|
||||||
if ($bannedEmail->email === $email) {
|
if ($bannedEmail->email === $email) {
|
||||||
@ -30,10 +38,8 @@ class BanRetriever {
|
|||||||
* @param $heskSettings
|
* @param $heskSettings
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
static function isIpAddressBanned($ip, $heskSettings) {
|
function isIpAddressBanned($ip, $heskSettings) {
|
||||||
require_once(__DIR__ . '/../../dao/security/BanGateway.php');
|
$bannedIps = $this->banGateway->getIpBans($heskSettings);
|
||||||
|
|
||||||
$bannedIps = BanGateway::getIpBans($heskSettings);
|
|
||||||
|
|
||||||
foreach ($bannedIps as $bannedIp) {
|
foreach ($bannedIps as $bannedIp) {
|
||||||
if ($bannedIp->ipFrom <= $ip && $bannedIp->ipTo >= $ip) {
|
if ($bannedIp->ipFrom <= $ip && $bannedIp->ipTo >= $ip) {
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
// Contains all common requirements. Nothing more.
|
|
||||||
require_once(__DIR__ . '/../../hesk_settings.inc.php');
|
|
||||||
require_once(__DIR__ . '/../../inc/common.inc.php');
|
|
||||||
require_once(__DIR__ . '/../core/output.php');
|
|
28
api/dao/CommonDao.php
Normal file
28
api/dao/CommonDao.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Created by PhpStorm.
|
||||||
|
* User: Mike
|
||||||
|
* Date: 1/28/2017
|
||||||
|
* Time: 1:33 AM
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace DataAccess;
|
||||||
|
|
||||||
|
|
||||||
|
use Exception;
|
||||||
|
|
||||||
|
class CommonDao {
|
||||||
|
/**
|
||||||
|
* @throws Exception if the database isn't properly configured
|
||||||
|
*/
|
||||||
|
function init() {
|
||||||
|
if (!function_exists('hesk_dbConnect')) {
|
||||||
|
throw new Exception('Database not loaded!');
|
||||||
|
}
|
||||||
|
hesk_dbConnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
function close() {
|
||||||
|
hesk_dbClose();
|
||||||
|
}
|
||||||
|
}
|
@ -1,22 +1,13 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* Created by PhpStorm.
|
|
||||||
* User: user
|
|
||||||
* Date: 1/16/17
|
|
||||||
* Time: 10:06 PM
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace DataAccess;
|
namespace DataAccess;
|
||||||
|
|
||||||
use BusinessObjects\Category;
|
use BusinessObjects\Category;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
class CategoryGateway {
|
class CategoryGateway extends CommonDao {
|
||||||
function getAllCategories($hesk_settings) {
|
function getAllCategories($hesk_settings) {
|
||||||
if (!function_exists('hesk_dbConnect')) {
|
$this->init();
|
||||||
throw new Exception('Database not loaded!');
|
|
||||||
}
|
|
||||||
hesk_dbConnect();
|
|
||||||
|
|
||||||
$sql = 'SELECT * FROM `' . hesk_dbEscape($hesk_settings['db_pfix']) . 'categories`';
|
$sql = 'SELECT * FROM `' . hesk_dbEscape($hesk_settings['db_pfix']) . 'categories`';
|
||||||
|
|
||||||
@ -37,7 +28,7 @@ class CategoryGateway {
|
|||||||
$results[$category->id] = $category;
|
$results[$category->id] = $category;
|
||||||
}
|
}
|
||||||
|
|
||||||
hesk_dbClose();
|
$this->close();
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
}
|
}
|
||||||
|
@ -1,25 +1,21 @@
|
|||||||
<?php
|
<?php
|
||||||
/**
|
|
||||||
* Created by PhpStorm.
|
|
||||||
* User: mkoch
|
|
||||||
* Date: 1/27/2017
|
|
||||||
* Time: 9:05 PM
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace DataAccess\Security;
|
namespace DataAccess\Security;
|
||||||
|
|
||||||
|
|
||||||
use BusinessLogic\Security\BannedEmail;
|
use BusinessLogic\Security\BannedEmail;
|
||||||
use BusinessLogic\Security\BannedIp;
|
use BusinessLogic\Security\BannedIp;
|
||||||
|
use DataAccess\CommonDao;
|
||||||
|
use Exception;
|
||||||
|
|
||||||
class BanGateway {
|
class BanGateway extends CommonDao {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $heskSettings
|
* @param $heskSettings
|
||||||
* @return BannedEmail[]
|
* @return BannedEmail[]
|
||||||
*/
|
*/
|
||||||
static function getEmailBans($heskSettings) {
|
function getEmailBans($heskSettings) {
|
||||||
require_once(__DIR__ . '/../../businesslogic/security/BannedEmail.php');
|
$this->init();
|
||||||
|
|
||||||
$rs = hesk_dbQuery("SELECT `bans`.`id` AS `id`, `bans`.`email` AS `email`,
|
$rs = hesk_dbQuery("SELECT `bans`.`id` AS `id`, `bans`.`email` AS `email`,
|
||||||
`users`.`id` AS `banned_by`, `bans`.`dt` AS `dt`
|
`users`.`id` AS `banned_by`, `bans`.`dt` AS `dt`
|
||||||
@ -40,6 +36,8 @@ class BanGateway {
|
|||||||
$bannedEmails[$bannedEmail->id] = $bannedEmail;
|
$bannedEmails[$bannedEmail->id] = $bannedEmail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->close();
|
||||||
|
|
||||||
return $bannedEmails;
|
return $bannedEmails;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,8 +45,8 @@ class BanGateway {
|
|||||||
* @param $heskSettings
|
* @param $heskSettings
|
||||||
* @return BannedIp[]
|
* @return BannedIp[]
|
||||||
*/
|
*/
|
||||||
static function getIpBans($heskSettings) {
|
function getIpBans($heskSettings) {
|
||||||
require_once(__DIR__ . '/../../businesslogic/security/BannedIp.php');
|
$this->init();
|
||||||
|
|
||||||
$rs = hesk_dbQuery("SELECT `bans`.`id` AS `id`, `bans`.`ip_from` AS `ip_from`,
|
$rs = hesk_dbQuery("SELECT `bans`.`id` AS `id`, `bans`.`ip_from` AS `ip_from`,
|
||||||
`bans`.`ip_to` AS `ip_to`, `bans`.`ip_display` AS `ip_display`,
|
`bans`.`ip_to` AS `ip_to`, `bans`.`ip_display` AS `ip_display`,
|
||||||
@ -72,6 +70,8 @@ class BanGateway {
|
|||||||
$bannedIps[$bannedIp->id] = $bannedIp;
|
$bannedIps[$bannedIp->id] = $bannedIp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->close();
|
||||||
|
|
||||||
return $bannedIps;
|
return $bannedIps;
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user