| 1: | <?php |
| 2: | namespace Sphp\tools { |
| 3: | class NativeGate extends ConsoleGate { |
| 4: | /** @var int WebSocket Connection ID which start Gate */ |
| 5: | public $mainConnection = null; |
| 6: | public $JQuery = null; |
| 7: | protected $childCom = null; |
| 8: | /** |
| 9: | * Create Child Process |
| 10: | * @param string $exepath file path to execute as child process |
| 11: | * @param array $param pass command line arguments to child process |
| 12: | * @param string $childid Optional Give the name of child process work as id |
| 13: | */ |
| 14: | public function createProcess($exepath, $param = array(), $childid = "mid1") {} |
| 15: | /** |
| 16: | * Send Message to browser |
| 17: | * @param type $msg |
| 18: | * @param string $type 'i' mean info other mean error |
| 19: | */ |
| 20: | public function sendMsg($msg,$type='i'){} |
| 21: | /** |
| 22: | * Advance function |
| 23: | * Setup proxy server for website |
| 24: | * @param string $param |
| 25: | * @deprecated since version 5.0.0 |
| 26: | */ |
| 27: | public function setupProxy($param) {} |
| 28: | /** |
| 29: | * Configure Gate as Global Gate Type. |
| 30: | * Global Gate has only 1 process for all requests and sessions. |
| 31: | * It will start on first request but it will not exit |
| 32: | * with browser close. By default Gate type is multi process |
| 33: | * that mean each session or Web Socket has 1 separate process. |
| 34: | */ |
| 35: | public function setGlobalGate() {} |
| 36: | /** |
| 37: | * Set Manager WS Connection for Global Gate. Every |
| 38: | * Global Gate has one main WS connection which started global Gate. |
| 39: | * But this WS connection lost if browser close or reload. So if you need a |
| 40: | * manager to control or watch global Gate processing then this method reassign |
| 41: | * any connection id as a main connection. Only Work with Global Gate and |
| 42: | * Web Socket connection. |
| 43: | */ |
| 44: | public function setGlobalGateManager() {} |
| 45: | /** |
| 46: | * Send Data to main connections related to All processes of |
| 47: | * current Gate or match with $gate. |
| 48: | * In case of global Gate(Single Process Gate) Only one main |
| 49: | * connection and if it is disconnected then data will not send. |
| 50: | * If you want to send data to all connections of global Gate then use sendOthers |
| 51: | * or sendAll. |
| 52: | * @param string $rawdata Optional Default=(send JSServer), JSON String |
| 53: | * @param string $datatype Optional Default=text Data Type |
| 54: | * @param string $gate Optional Default=this Gate, Gate of Gate to send data |
| 55: | */ |
| 56: | public function sendAllProcess($rawdata = null, $datatype = "text",$gate="") {} |
| 57: | /** |
| 58: | * Easy Send Data for custom use sendToWS |
| 59: | * Send Data to All WS Connections of Server also included current connection. |
| 60: | * @param string $rawdata Optional Default=(send JSServer), JSON String |
| 61: | * @param string $datatype Optional Default=text Data Type |
| 62: | */ |
| 63: | public function sendAllWS($rawdata = null, $datatype = "text") {} |
| 64: | /** |
| 65: | * Send Data to All WS Connections related to Gate process, current Gate or |
| 66: | * $gate of other Native Gate. |
| 67: | * It works similar to sendOthers but also send data to current connection. |
| 68: | * @param string $rawdata Optional Default=(send JSServer), JSON String |
| 69: | * @param string $datatype Optional Default=text Data Type |
| 70: | * @param string $gate Optional Default=this Gate, Gate of Gate to send data |
| 71: | */ |
| 72: | public function sendAll($rawdata = null, $datatype = "text", $gate = "") {} |
| 73: | /** |
| 74: | * Easy Send Data for custom use sendOthersRaw |
| 75: | * Send Data to All Others WS Connections and leave current connection id |
| 76: | * @param string $rawdata Optional Default=(send JSServer), JSON String |
| 77: | * @param string $datatype Optional Default=text Data Type |
| 78: | * @param string $gate Optional Default=this Gate, Gate of Gate to send data |
| 79: | */ |
| 80: | public function sendOthers($rawdata = null, $datatype = "text", $gate = "") {} |
| 81: | /** |
| 82: | * Send Data to connection id or current connection id |
| 83: | * @param int $conid Optional Default=(current request) |
| 84: | * @param string $rawdata Optional Default=(send JSServer), JSON String |
| 85: | * @param string $datatype Optional Default=text Data Type |
| 86: | */ |
| 87: | public function sendTo($conid = 0, $rawdata = null, $datatype = "text") {} |
| 88: | /** |
| 89: | * Advance for easy way use SendOthers |
| 90: | * Send Data to All Others WS Connections and leave current connection id |
| 91: | * @param string $rawdata Optional Default=(send JSServer), JSON String |
| 92: | * @param int $sendtype Optional Default=0(All Processes(Only Main Connection |
| 93: | * of process not all connections) of $gate Gate or this Gate), |
| 94: | * 1(All connections of global Gate), 2(All WS connections) |
| 95: | * @param string $datatype Optional Default=text Data Type |
| 96: | * @param string $gate Optional Default=this, Gate of Gate to send data |
| 97: | */ |
| 98: | public function sendOthersRaw($rawdata = null, $sendtype = 0, $datatype = "text", $gate = "") {} |
| 99: | /** |
| 100: | * Advance |
| 101: | * Send Data to WS Connections. |
| 102: | * sendtype:- |
| 103: | * 0 = send data to all processes of this Gate or other Gate Gate as $gate. |
| 104: | * for single process Gate(global Gate), data send only to main connection |
| 105: | * 1 = send data to all connections of WS with global Gate this or other Gate Gate as $gate. |
| 106: | * 2 = send data to all WS connections of Server |
| 107: | * 3 = send data to connection id $conid only |
| 108: | * @param string $rawdata Optional Default=(send JSServer), JSON String |
| 109: | * @param int $sendtype Optional Default=0 or 1,2,3 |
| 110: | * @param string $datatype Optional Default=text Data Type |
| 111: | * @param string $gate Optional Gate of Gate to send data |
| 112: | * @param int $conid Optional Default=-1=all, this id will leave to send data if $sendtype=0,1 or 2 |
| 113: | */ |
| 114: | public function sendToWS($rawdata = null, $sendtype = 0, $datatype = "text", $gate = "", $conid = -1) {} |
| 115: | /** |
| 116: | * override this event handler in your Gate to handle it. |
| 117: | * Event Handler for Child Process Console output |
| 118: | * @param string|array $data |
| 119: | * @param string $type |
| 120: | */ |
| 121: | public function onconsole($data, $type) {} |
| 122: | /** |
| 123: | * SphpServer Event Trigger when Child Process is ready. |
| 124: | * @param string $evtp |
| 125: | * @param array $bdata Child Process id |
| 126: | */ |
| 127: | public function page_event_s_onprocesscreate($evtp,$bdata){} |
| 128: | /** |
| 129: | * override this event handler in your Gate to handle it. |
| 130: | * Gate Exit Handler |
| 131: | */ |
| 132: | public function onquit() {} |
| 133: | /** |
| 134: | * override this event handler in your Gate to handle it. |
| 135: | * Gate Child process Exit Handler |
| 136: | */ |
| 137: | public function oncquit() {} |
| 138: | /** |
| 139: | * override this event handler in your Gate to handle it. |
| 140: | * WebSocket Connection Handler, |
| 141: | * Trigger on each new connection |
| 142: | * @param \Sphp\tools\WsCon $conobj WS Client Object |
| 143: | */ |
| 144: | public function onwscon($conobj) {} |
| 145: | /** |
| 146: | * override this event handler in your Gate to handle it. |
| 147: | * WebSocket DisConnection Handler |
| 148: | * Trigger on each connection close |
| 149: | * @param \Sphp\tools\WsCon $conobj WS Client Object |
| 150: | */ |
| 151: | public function onwsdiscon($conobj) {} |
| 152: | /** |
| 153: | * Advance Function |
| 154: | * Send Data to Browser in JSON format |
| 155: | * @param array|string $data |
| 156: | * @param string $type Optional Default=jsonweb |
| 157: | */ |
| 158: | public function sendData($data, $type = "jsonweb") {} |
| 159: | /** |
| 160: | * Advance function, Internal use |
| 161: | * Override wait event handler of ConsoleGate |
| 162: | */ |
| 163: | public function onwait() {} |
| 164: | /** |
| 165: | * Exit Manually |
| 166: | */ |
| 167: | public function ExitMe() {} |
| 168: | /** |
| 169: | * Advance function |
| 170: | */ |
| 171: | /** |
| 172: | * Advance function, Internal use |
| 173: | */ |
| 174: | } |
| 175: | /** |
| 176: | * WS Connection Object hold the WS Connection. |
| 177: | */ |
| 178: | class WsCon{ |
| 179: | /** |
| 180: | * Send Data to WS Client |
| 181: | * @param string $rawdata Optional Default=(send JSServer), JSON String |
| 182: | * @param string $datatype Optional Default=text Data Type |
| 183: | */ |
| 184: | public function send($rawdata = null, $datatype = "text"){} |
| 185: | /** |
| 186: | * Get Connection ID of WS Client |
| 187: | * @return int |
| 188: | */ |
| 189: | public function getConnectionId(){} |
| 190: | /** |
| 191: | * Get IP Address of WS Client |
| 192: | * @return string |
| 193: | */ |
| 194: | public function getAddress(){} |
| 195: | /** |
| 196: | * Get Port Address of WS Client |
| 197: | * @return string |
| 198: | */ |
| 199: | public function getPort(){} |
| 200: | } |
| 201: | /** |
| 202: | * Child Process Communication Protocol Object |
| 203: | */ |
| 204: | class CpCom{ |
| 205: | public $status = false; |
| 206: | /** |
| 207: | * Call function of child process and pass data |
| 208: | * @param string $fun function name of child process |
| 209: | * @param string|array $data |
| 210: | */ |
| 211: | public function callProcess($fun, $data) {} |
| 212: | /** |
| 213: | * Send Command to Child Process |
| 214: | * @param string $cmd Command Name of Child Process |
| 215: | */ |
| 216: | public function sendCommand($cmd) {} |
| 217: | /** |
| 218: | * Advance Function |
| 219: | * Send Data to Child Process |
| 220: | * @param string $ptype <p> |
| 221: | * Your custom command type. sendCommand use 'cmd' and callProcess use 'fun' |
| 222: | * </p> |
| 223: | * @param array|string $data |
| 224: | * @param string $type Optional Default=childp |
| 225: | */ |
| 226: | } |
| 227: | } |
| 228: |