[go: up one dir, main page]

Menu

[3822d7]: / core / Gateway.php  Maximize  Restore  History

Download this file

123 lines (102 with data), 3.0 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?php
namespace ICT\Core;
/* * ***************************************************************
* Copyright © 2014 ICT Innovations Pakistan All Rights Reserved *
* Developed By: Nasir Iqbal *
* Website : http://www.ictinnovations.com/ *
* Mail : nasir@ictinnovations.com *
* *************************************************************** */
class Gateway
{
/** @const */
const GATEWAY_FLAG = 0;
const GATEWAY_TYPE = 'gateway';
const CONTACT_FIELD = 'phone';
/** @var boolean $conn */
protected $conn = FALSE;
public static function load($gateway_flag) {
static $gatewayMap = null;
if (empty($gatewayMap)) {
// manually load all available service classes
include_once_directory('Gateway');
$listGateway = list_available_classes('ICT\\Core\\Gateway');
foreach ($listGateway as $gatewayClass) {
$flag = $gatewayClass::GATEWAY_FLAG;
$gatewayMap[$flag] = $gatewayClass;
}
}
if (!empty($gateway_flag) && isset($gatewayMap[$gateway_flag])) {
$className = $gatewayMap[$gateway_flag];
$oGateway = new $className;
return $oGateway;
} else {
return false;
}
}
protected function connect()
{
$this->conn = TRUE; /* handle to connection */
}
protected function dissconnect()
{
return fclose($this->conn);
}
public function send($command, Provider $oProvider = NULL)
{
if ($this->connect()) {
// process
Corelog::log('Gateway->Send demo: ' . $command . ' via: ' . $oProvider->name, Corelog::WARNING);
$this->dissconnect();
return TRUE;
} else {
return FALSE;
}
}
public function get()
{
if ($this->connect()) {
// process
$this->dissconnect();
return TRUE;
} else {
return FALSE;
}
}
public static function default_route()
{
return null; // no default route
}
public static function template_dir()
{
return '.';
}
public static function locate_account($account)
{
return Account::locate($account, static::CONTACT_FIELD);
}
public static function locate_contact($contact)
{
// first search for matching accounts, to detect internal communication
$oAccount = Account::locate($contact, static::CONTACT_FIELD);
if (!empty($oAccount)) {
return $oAccount;
}
return Contact::locate($contact, static::CONTACT_FIELD);
}
public function config_save($type, $name, $data = '')
{
Corelog::log("Gateway->config_save demo. type: $type, name: $name", Corelog::WARNING, $data);
}
public function config_delete($type, $name)
{
Corelog::log("Gateway->config_delete demo. type: $type, name: $name", Corelog::WARNING);
}
public function config_reload()
{
Corelog::log('Gateway->config_reload', Corelog::WARNING);
}
public function provider_status($provider_name)
{
return false;
}
}