| 1: | <?php |
| 2: | namespace Sphp\tools { |
| 3: | class NativeApp extends ConsoleApp { |
| 4: | /** @var int WebSocket Connection ID which start application */ |
| 5: | public $mainConnection = null; |
| 6: | /** |
| 7: | * Advance function |
| 8: | */ |
| 9: | /** |
| 10: | * Create Child Process |
| 11: | * @param string $exepath file path to execute as child process |
| 12: | * @param array $param pass command line arguments to child process |
| 13: | * @param string $childid Optional Give the name of child process work as id |
| 14: | */ |
| 15: | public function createProcess($exepath, $param = array(), $childid = "mid1") {} |
| 16: | /** |
| 17: | * Send Message to browser |
| 18: | * @param type $msg |
| 19: | * @param string $type 'i' mean info other mean error |
| 20: | */ |
| 21: | public function sendMsg($msg,$type='i'){} |
| 22: | /** |
| 23: | * Advance function |
| 24: | * Setup proxy server for website |
| 25: | * @param string $param |
| 26: | */ |
| 27: | public function setupProxy($param) {} |
| 28: | /** |
| 29: | * Configure Application as Global App Type. |
| 30: | * Global Application 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 application type is multi process |
| 33: | * that mean each session or Web Socket has 1 separate process. |
| 34: | */ |
| 35: | public function setGlobalApp() {} |
| 36: | /** |
| 37: | * Set Manager WS Connection for Global Application. Every |
| 38: | * Global Application has one main WS connection which started global App. |
| 39: | * But this WS connection lost if browser close or reload. So if you need a |
| 40: | * manager to control or watch global app processing then this method reassign |
| 41: | * any connection id as a main connection. Only Work with Global app and |
| 42: | * Web Socket connection. |
| 43: | */ |
| 44: | public function setGlobalAppManager() {} |
| 45: | /** |
| 46: | * Send Data to main connections related to All processes of |
| 47: | * current app or match with $groupctrl. |
| 48: | * In case of global app(Single Process App) 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 app 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 $groupctrl Optional Default=this app, controller of app to send data |
| 55: | */ |
| 56: | public function sendAllProcess($rawdata = null, $datatype = "text",$groupctrl="") {} |
| 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 app process, current controller or $groupctrl. |
| 66: | * It works similar to sendOthers but also send data to current connection. |
| 67: | * @param string $rawdata Optional Default=(send JSServer), JSON String |
| 68: | * @param string $datatype Optional Default=text Data Type |
| 69: | * @param string $groupctrl Optional Default=this app, controller of app to send data |
| 70: | */ |
| 71: | public function sendAll($rawdata = null, $datatype = "text", $groupctrl = "") {} |
| 72: | /** |
| 73: | * Easy Send Data for custom use sendOthersRaw |
| 74: | * Send Data to All Others WS Connections and leave current connection id |
| 75: | * @param string $rawdata Optional Default=(send JSServer), JSON String |
| 76: | * @param string $datatype Optional Default=text Data Type |
| 77: | * @param string $groupctrl Optional Default=this app, controller of app to send data |
| 78: | */ |
| 79: | public function sendOthers($rawdata = null, $datatype = "text", $groupctrl = "") {} |
| 80: | /** |
| 81: | * Send Data to connection id or current connection id |
| 82: | * @param int $conid Optional Default=(current request) |
| 83: | * @param string $rawdata Optional Default=(send JSServer), JSON String |
| 84: | * @param string $datatype Optional Default=text Data Type |
| 85: | */ |
| 86: | public function sendTo($conid = 0, $rawdata = null, $datatype = "text") {} |
| 87: | /** |
| 88: | * Advance for easy way use SendOthers |
| 89: | * Send Data to All Others WS Connections and leave current connection id |
| 90: | * @param string $rawdata Optional Default=(send JSServer), JSON String |
| 91: | * @param int $sendtype Optional Default=0(All Processes(Only Main Connection |
| 92: | * of process not all connections) of $groupctrl app or this app), |
| 93: | * 1(All connections of global app), 2(All WS connections) |
| 94: | * @param string $datatype Optional Default=text Data Type |
| 95: | * @param string $groupctrl Optional Default=this, controller of app to send data |
| 96: | */ |
| 97: | public function sendOthersRaw($rawdata = null, $sendtype = 0, $datatype = "text", $groupctrl = "") {} |
| 98: | /** |
| 99: | * Advance |
| 100: | * Send Data to WS Connections. |
| 101: | * sendtype:- |
| 102: | * 0 = send data to all processes of this app or other app controller as $groupctrl. |
| 103: | * for single process app(global app), data send only to main connection |
| 104: | * 1 = send data to all connections of WS with global app this or other app controller as $groupctrl. |
| 105: | * 2 = send data to all WS connections of Server |
| 106: | * 3 = send data to connection id $conid only |
| 107: | * @param string $rawdata Optional Default=(send JSServer), JSON String |
| 108: | * @param int $sendtype Optional Default=0 or 1,2,3 |
| 109: | * @param string $datatype Optional Default=text Data Type |
| 110: | * @param string $groupctrl Optional controller of app to send data |
| 111: | * @param int $conid Optional Default=-1=all, this id will leave to send data if $sendtype=0,1 or 2 |
| 112: | */ |
| 113: | public function sendToWS($rawdata = null, $sendtype = 0, $datatype = "text", $groupctrl = "", $conid = -1) {} |
| 114: | /** |
| 115: | * override this event handler in your application to handle it. |
| 116: | * Event Handler for Child Process Console output |
| 117: | * @param string|array $data |
| 118: | * @param string $type |
| 119: | */ |
| 120: | public function onconsole($data, $type) {} |
| 121: | /** |
| 122: | * override this event handler in your application to handle it. |
| 123: | * @param array $data |
| 124: | */ |
| 125: | public function onrequest($data) {} |
| 126: | /** |
| 127: | * override this event handler in your application to handle it. |
| 128: | * Application Exit Handler |
| 129: | */ |
| 130: | public function onquit() {} |
| 131: | /** |
| 132: | * override this event handler in your application to handle it. |
| 133: | * Application Child process Exit Handler |
| 134: | */ |
| 135: | public function oncquit() {} |
| 136: | /** |
| 137: | * override this event handler in your application to handle it. |
| 138: | * WebSocket Connection Handler, |
| 139: | * Connection object include conid, REQUEST_ADD and REQUEST_PORT key |
| 140: | * Trigger on each new connection |
| 141: | * @param array $conobj WS Connection Object |
| 142: | */ |
| 143: | public function onwscon($conobj) {} |
| 144: | /** |
| 145: | * override this event handler in your application to handle it. |
| 146: | * WebSocket DisConnection Handler |
| 147: | * Connection object include conid, REQUEST_ADD and REQUEST_PORT key |
| 148: | * Trigger on each connection close |
| 149: | * @param array $conobj WS Connection 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: | * Send Command to Child Process |
| 161: | * @param string|array $msg |
| 162: | * @param string $type Optional Default=childp |
| 163: | */ |
| 164: | public function sendCommand($msg, $type = "childp") {} |
| 165: | /** |
| 166: | * Advance Function |
| 167: | * Send Data to Child Process |
| 168: | * @param string $ptype <p> |
| 169: | * Your custom command type. sendCommand use 'cmd' and callProcess use 'fun' |
| 170: | * </p> |
| 171: | * @param array|string $data |
| 172: | * @param string $type Optional Default=childp |
| 173: | */ |
| 174: | public function sendProcess($ptype, $data, $type = "childp") {} |
| 175: | /** |
| 176: | * Call function of child process and pass data |
| 177: | * @param string $fun function name of child process |
| 178: | * @param string|array $data |
| 179: | * @param string $type Optional |
| 180: | */ |
| 181: | public function callProcess($fun, $data, $type = "childp") {} |
| 182: | /** |
| 183: | * Advance function, Internal use |
| 184: | * Override wait event handler of ConsoleAPP |
| 185: | */ |
| 186: | public function onwait() {} |
| 187: | /** |
| 188: | * Advance function, Internal use |
| 189: | */ |
| 190: | public function run() {} |
| 191: | } |
| 192: | } |
| 193: |