Moved some more stuff to new structure

remotes/upstream/api-rewrite
Mike Koch 7 years ago
parent 2ef67de718
commit e68ecf50c6

@ -4,9 +4,11 @@ namespace Core;
// Responsible for loading in all necessary classes. AKA a poor man's DI solution.
use BusinessLogic\Category\CategoryRetriever;
use BusinessLogic\Security\BanRetriever;
use DataAccess\CategoryGateway;
use DataAccess\Security\BanGateway;
class DependencyManager {
class ApplicationContext {
public $get;
function __construct() {
@ -14,5 +16,8 @@ class DependencyManager {
$this->get['CategoryGateway'] = new 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
// Responsible for loading in all necessary scripts and kicking off the DependencyManager
// Core requirements
define('IN_SCRIPT', 1);
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__ . '/../hesk_settings.inc.php');
// FILES
// Mods for HESK API Files
require_once(__DIR__ . '/http_response_code.php');
// Categories
require_once(__DIR__ . '/dao/category/CategoryGateway.php');
require_once(__DIR__ . '/businesslogic/category/CategoryRetriever.php');
require_once(__DIR__ . '/businesslogic/category/Category.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 files that require database access
require_once(__DIR__ . '/../inc/custom_fields.inc.php');
require_once(__DIR__ . '/DependencyManager.php');
$applicationContext = new \Core\DependencyManager();
// Load the ApplicationContext
require_once(__DIR__ . '/ApplicationContext.php');
$applicationContext = new \Core\ApplicationContext();

@ -1,10 +1,4 @@
<?php
/**
* Created by PhpStorm.
* User: user
* Date: 1/16/17
* Time: 10:10 PM
*/
namespace BusinessLogic\Category;

@ -6,15 +6,23 @@ namespace BusinessLogic\Security;
use DataAccess\Security\BanGateway;
class BanRetriever {
/**
* @var BanGateway
*/
private $banGateway;
function __construct($banGateway) {
$this->banGateway = $banGateway;
}
/**
* @param $email
* @param $heskSettings
* @return bool
*/
static function isEmailBanned($email, $heskSettings) {
require_once(__DIR__ . '/../../dao/security/BanGateway.php');
function isEmailBanned($email, $heskSettings) {
$bannedEmails = BanGateway::getEmailBans($heskSettings);
$bannedEmails = $this->banGateway->getEmailBans($heskSettings);
foreach ($bannedEmails as $bannedEmail) {
if ($bannedEmail->email === $email) {
@ -30,10 +38,8 @@ class BanRetriever {
* @param $heskSettings
* @return bool
*/
static function isIpAddressBanned($ip, $heskSettings) {
require_once(__DIR__ . '/../../dao/security/BanGateway.php');
$bannedIps = BanGateway::getIpBans($heskSettings);
function isIpAddressBanned($ip, $heskSettings) {
$bannedIps = $this->banGateway->getIpBans($heskSettings);
foreach ($bannedIps as $bannedIp) {
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');

@ -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
/**
* Created by PhpStorm.
* User: user
* Date: 1/16/17
* Time: 10:06 PM
*/
namespace DataAccess;
use BusinessObjects\Category;
use Exception;
class CategoryGateway {
class CategoryGateway extends CommonDao {
function getAllCategories($hesk_settings) {
if (!function_exists('hesk_dbConnect')) {
throw new Exception('Database not loaded!');
}
hesk_dbConnect();
$this->init();
$sql = 'SELECT * FROM `' . hesk_dbEscape($hesk_settings['db_pfix']) . 'categories`';
@ -37,7 +28,7 @@ class CategoryGateway {
$results[$category->id] = $category;
}
hesk_dbClose();
$this->close();
return $results;
}

@ -1,25 +1,21 @@
<?php
/**
* Created by PhpStorm.
* User: mkoch
* Date: 1/27/2017
* Time: 9:05 PM
*/
namespace DataAccess\Security;
use BusinessLogic\Security\BannedEmail;
use BusinessLogic\Security\BannedIp;
use DataAccess\CommonDao;
use Exception;
class BanGateway {
class BanGateway extends CommonDao {
/**
* @param $heskSettings
* @return BannedEmail[]
*/
static function getEmailBans($heskSettings) {
require_once(__DIR__ . '/../../businesslogic/security/BannedEmail.php');
function getEmailBans($heskSettings) {
$this->init();
$rs = hesk_dbQuery("SELECT `bans`.`id` AS `id`, `bans`.`email` AS `email`,
`users`.`id` AS `banned_by`, `bans`.`dt` AS `dt`
@ -40,6 +36,8 @@ class BanGateway {
$bannedEmails[$bannedEmail->id] = $bannedEmail;
}
$this->close();
return $bannedEmails;
}
@ -47,8 +45,8 @@ class BanGateway {
* @param $heskSettings
* @return BannedIp[]
*/
static function getIpBans($heskSettings) {
require_once(__DIR__ . '/../../businesslogic/security/BannedIp.php');
function getIpBans($heskSettings) {
$this->init();
$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`,
@ -72,6 +70,8 @@ class BanGateway {
$bannedIps[$bannedIp->id] = $bannedIp;
}
$this->close();
return $bannedIps;
}
}
Loading…
Cancel
Save