/
auto_server.php
65 lines (54 loc) · 2.37 KB
/
auto_server.php
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
<?php
/**
* Advanced usage of HTML_AJAX_Server
* Allows for a single server to manage exporting a large number of classes without high overhead per call
* Also gives a single place to handle setup tasks especially useful if session setup is required
*
* The server responds to ajax calls and also serves the js client libraries, so they can be used directly from the PEAR data dir
* 304 not modified headers are used when server client libraries so they will be cached on the browser reducing overhead
*
* @category HTML
* @package AJAX
* @author Joshua Eichorn <josh@bluga.net>
* @copyright 2005 Joshua Eichorn
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version Release: @package_version@
* @link http://pear.php.net/package/HTML_AJAX
*/
// include the server class
include 'HTML/AJAX/Server.php';
// extend HTML_AJAX_Server creating our own custom one with init{ClassName} methods for each class it supports calls on
class TestServer extends HTML_AJAX_Server {
// this flag must be set to on init methods
var $initMethods = true;
// init method for the test class, includes needed files an registers it for ajax
function initTest() {
include 'test.class.php';
$this->registerClass(new test());
}
// init method for the livesearch class, includes needed files an registers it for ajax
function initLivesearch() {
include 'livesearch.class.php';
$this->registerClass(new livesearch());
}
}
// create an instance of our test server
$server = new TestServer();
// init methods can also be added to the server by registering init objects, this is useful in cases where you want to dynamically add init methods
class initObject {
// init method for the test class, includes needed files an registers it for ajax
function initTest2() {
include 'test2.class.php';
$this->server->registerClass(new test2());
}
}
$init = new initObject();
$init->server =& $server;
$server->registerInitObject($init);
// you can use HTML_AJAX_Server to deliver your own custom javascript libs, when used with comma seperated client lists you can
// use just one javascript include for all your library files
// example url: auto_server.php?client=auto_server.php?client=Util,Main,Request,HttpClient,Dispatcher,Behavior,customLib
$server->registerJSLibrary('customLib','customLib.js','./');
// handle requests as needed
$server->handleRequest();
?>