Source for file Server.php
Documentation is available at Server.php
require_once 'HTML/AJAX.php';
* Class for creating an external AJAX server
* Can be used in 2 different modes, registerClass mode where you create an instance of the server and add the classes that will be registered
* and then run handle request
* Or you can extend it and add init{className} methods for each class you want to export
* Client js generation is exposed through 2 _GET params client and stub
* Setting the _GET param client to `all` will give you all the js classes needed
* Setting the _GET param stub to `all` will give you stubs of all registered classes, you can also set it too just 1 class
* @author Joshua Eichorn <josh@bluga.net>
* @copyright 2005 Joshua Eichorn
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version Release: @package_version@
* @link http://pear.php.net/package/PackageName
* @todo Decide if a syntax is needed to generate 2 stubs at once
* Client options array if set to true the code looks at _GET
* Set to true if your extending the server to add init{className methods}
* Constructor creates the HTML_AJAX instance
* @todo: verify that PHP_SELF always does what we want
* Handle a client request, either generating a client or having HTML_AJAX handle the request
if (!isset ($_GET['c'])) {
$this->_init ($_GET['c']);
* Register method passthrough to HTML_AJAX
* @see HTML_AJAX::registerClass for docs
function registerClass(&$instance, $exportedName = false , $exportedMethods = false ) {
* @todo Add Http_Cache type functionality so the client will cache the js
header('Content-type: text/javascript');
if ($this->options['stub'] === 'all') {
if ($this->options['stub'] !== false ) {
$this->_init ($this->options['stub']);
echo " alert('Unknown javascript library: $library');";
* Run readfile on input with basic error checking
* @param string $file file to read
function _readFile ($file) {
echo " alert('Unable to find javascript file: $file');";
* Get the location of the client js
* @todo figure out where this will be on an install
return '@data-dir@/HTML_AJAX/js/';
* @todo Is this preg_replace a good enough security check?
function _loadOptions () {
$this->options = array ('client'=>false ,'stub'=>false );
if (isset ($_GET['client'])) {
$this->options['client'] = $_GET['client'];
if (isset ($_GET['stub'])) {
* Run every init method on the class
foreach($methods as $method) {
if (substr($method,0 ,4 ) == 'init') {
* @param string $className
* @todo error handling if the method doesn't exist
function _init ($className) {
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
Documentation generated on Mon, 11 Mar 2019 14:16:00 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.
|