1#!/usr/bin/php -q 2<?php 3/** 4 * test.php 5 * This file is part of the YATE Project http://YATE.null.ro 6 * 7 * Yet Another Telephony Engine - a fully featured software PBX and IVR 8 * Copyright (C) 2004-2014 Null Team 9 * 10 * This software is distributed under multiple licenses; 11 * see the COPYING file in the main directory for licensing 12 * information for this specific distribution. 13 * 14 * This use of this software may be subject to additional restrictions. 15 * See the LEGAL file in the main directory for details. 16 * 17 * This program is distributed in the hope that it will be useful, 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 20 */ 21 22/* Test script for the Yate PHP interface 23 To test add in extmodule.conf 24 25 [scripts] 26 test.php= 27*/ 28require_once("libyate.php"); 29 30/* Always the first action to do */ 31Yate::Init(); 32 33/* Install a handler for the engine generated timer message */ 34Yate::Install("engine.timer",10); 35 36/* Create and dispatch an initial test message */ 37$m=new Yate("test"); 38$m->params["param1"]="val1"; 39$m->retval="ret_value"; 40$m->Dispatch(); 41 42Yate::GetLocal("engine.version"); 43Yate::GetLocal("engine.nodename"); 44Yate::GetLocal("engine.nosuch"); 45Yate::SetLocal("engine.nodename","error because is readonly"); 46Yate::GetLocal("config.nosuch"); 47Yate::GetLocal("config.localsym"); 48Yate::GetLocal("config.localsym.h323chan.yate"); 49Yate::SetLocal("config.localsym.h323chan.yate","r/o error too"); 50 51/* The main loop. We pick events and handle them */ 52for (;;) { 53 $ev=Yate::GetEvent(); 54 /* If Yate disconnected us then exit cleanly */ 55 if ($ev === false) 56 break; 57 /* Empty events are normal in non-blocking operation. 58 This is an opportunity to do idle tasks and check timers */ 59 if ($ev === true) { 60 Yate::Output("PHP event: empty"); 61 continue; 62 } 63 /* If we reached here we should have a valid object */ 64 switch ($ev->type) { 65 case "incoming": 66 Yate::Output("PHP Message: " . $ev->name . " id: " . $ev->id); 67 /* This is extremely important. 68 We MUST let messages return, handled or not */ 69 $ev->Acknowledge(); 70 break; 71 case "answer": 72 Yate::Output("PHP Answered: " . $ev->name . " id: " . $ev->id); 73 break; 74 case "installed": 75 Yate::Output("PHP Installed: " . $ev->name); 76 break; 77 case "uninstalled": 78 Yate::Output("PHP Uninstalled: " . $ev->name); 79 break; 80 case "setlocal": 81 Yate::Output("PHP Parameter: ". $ev->name . "=" . $ev->retval . ($ev->handled ? " (OK)" : " (error)")); 82 break; 83 default: 84 Yate::Output("PHP Event: " . $ev->type); 85 } 86} 87 88Yate::Output("PHP: bye!"); 89 90/* vi: set ts=8 sw=4 sts=4 noet: */ 91?> 92