diff --git a/api/DependencyManager.php b/api/ApplicationContext.php similarity index 64% rename from api/DependencyManager.php rename to api/ApplicationContext.php index 005e731f..64cf99a1 100644 --- a/api/DependencyManager.php +++ b/api/ApplicationContext.php @@ -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']); } } \ No newline at end of file diff --git a/api/autoload.php b/api/autoload.php index 351d664f..5be0ed5a 100644 --- a/api/autoload.php +++ b/api/autoload.php @@ -1,25 +1,35 @@ 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) { diff --git a/api/core/common.php b/api/core/common.php deleted file mode 100644 index 77c14cd6..00000000 --- a/api/core/common.php +++ /dev/null @@ -1,6 +0,0 @@ -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; } diff --git a/api/dao/security/BanGateway.php b/api/dao/security/BanGateway.php index d1d9a829..78139819 100644 --- a/api/dao/security/BanGateway.php +++ b/api/dao/security/BanGateway.php @@ -1,25 +1,21 @@ 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; } } \ No newline at end of file