cvs: pear /HTML_AJAX/AJAX Debug.php Helper.php
| From: | Joshua Eichorn | Date: | Tue, 25 Oct 2005 03:28:59 +0000 |
| Subject: | cvs: pear /HTML_AJAX/AJAX Debug.php Helper.php | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-35835@lists.php.net to get a copy of this message | ||
jeichorn Mon Oct 24 23:28:59 2005 EDT
Added files:
/pear/HTML_AJAX/AJAX Debug.php Helper.php
Log:
new debug and helper classes
http://cvs.php.net/co.php/pear/HTML_AJAX/AJAX/Debug.php?r=1.1&p=1
Index: pear/HTML_AJAX/AJAX/Debug.php
+++ pear/HTML_AJAX/AJAX/Debug.php
<?php
define ("NEWLINE", "\n");
// {{{ class HTML_AJAX_Debug
/**
* AJAX Debugging implementation
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did
not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category HTML
* @package AJAX
* @author David Coallier <davidc@php.net>
* @copyright 2005 David Coallier
* @license http://www.opensource.org/licenses/lgpl-license.php
LGPL
* @version Release: @package_version@
*/
class HTML_AJAX_Debug {
// {{{ properties
/**
* This is the error message.
*
* @access private
*/
var $errorMsg;
/**
* The line where the error occured.
*
* @access private
*/
var $errorLine;
/**
* The error code.
*
* @access private
*/
var $errorCode;
/**
* The file where the error occured.
*
* @access private
*/
var $errorFile;
/**
* Time the error occured
*
* @access private
*/
var $_timeOccured;
/**
* The whole error itself
*
* @access private
* @see errorMsg
* @see errorLine
* @see errorFile
* @see errorCode
*/
var $error;
/**
* The file to save the error to.
*
* @access private
* @default ajaxErrLog.xml
*/
var $file = 'ajaxErrLog.xml';
// }}}
// {{{ constructor
/**
* The constructor.
*
* @param string $errorMsg The error message.
* @param string $errLine The line where error occured.
* @param string $errCode The error Code.
* @param string $errFile The file where error occured.
*/
function HTML_AJAX_Debug($errMsg, $errLine, $errCode, $errFile)
{
$this->errorMsg = $errMsg;
$this->errorLine = $errLine;
$this->errorCode = $errCode;
$this->errorFile = $errFile;
$this->_timeOccured = date("Y-m-d H:i:s", time());
$this->xmlError();
}
// }}}
// {{{ xmlError
/**
* This functions formats the error to xml format then we can save it.
*
* @access protected
* @return $this->error the main error.
*/
function xmlError()
{
$error = " <when>{$this->_timeOccured}</when>" . NEWLINE;
$error .= " <msg>{$this->errorMsg}</msg>" . NEWLINE;
$error .= " <code>{$this->errorCode}</code>" . NEWLINE;
$error .= " <line>{$this->errorLine}</line>" . NEWLINE;
$error .= " <file>{$this->errorFile}</file>" . NEWLINE .
NEWLINE;
return $this->error = $error;
}
// }}}
// {{{ sessionError
/**
* This function pushes the array $_SESSION['html_ajax_debug']['time'][]
* with the values inside of $this->error
*
* @access public
*/
function sessionError()
{
$_SESSION['html_ajax_debug']['time'][] = $this->error;
}
// }}}
// {{{ _saveError
/**
* This function saves the error to a file
* appending to this file.
*
* @access private.
*/
function _saveError()
{
if ($handle = fopen($this->file, 'a')) {
fwrite($handle, $this->error);
}
}
// }}}
}
// }}}
?>
http://cvs.php.net/co.php/pear/HTML_AJAX/AJAX/Helper.php?r=1.1&p=1
Index: pear/HTML_AJAX/AJAX/Helper.php
+++ pear/HTML_AJAX/AJAX/Helper.php
<?php
/**
* HTML/JavaScript Generation Helper
*
* @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@
*/
/**
* HTML/JavaScript Generation Helper
*
* @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
*/
class HTML_AJAX_Helper
{
/**
* URL where an HTML_AJAX_Server instance is serving up clients and taking ajax requests
*/
var $serverUrl = 'server.php';
/**
* JS libraries to include
*
* @var array
*/
var $jsLibraries =
array('Util','Main','Request','HttpClient','Dispatcher','Behavior','Loading');
/**
* Include all needed libraries, stubs, and set defaultServer
*
* @return string
*/
function setupAJAX()
{
$libs = implode(',',$this->jsLibraries);
$ret = "<script type='text/javascript'
src='{$this->serverUrl}?client={$libs}'></script>\n";
$ret .= $this->encloseInScript('HTML_AJAX.defaultServerUrl =
'.$this->escape($this->serverUrl));
return $ret;
}
/**
* Create a custom Loading message
*
* @param string $body HTML body of the loading div
* @param string $class CSS class of the div
* @param string $style style tag of the loading div
*/
function loadingMessage($body, $class = 'HTML_AJAX_Loading',
$style = 'position: absolute; top: 0; right: 0; backgroundColor: red; width: 80px; padding:
4px; display: none')
{
return "<div id='HTML_AJAX_LOADING' class='{$class}'
style=\"{$style}\">{$body}</div>\n";
}
/**
* Update the contents of an element using ajax
*
* @param string $id id of the element to update
* @param string|array $update Either a url to update with or a array like
array('class','method')
* @param string $type replace or append
* @param boolean $enclose
*/
function updateElement($id, $update, $type, $enclose = false) {
if (is_array($update)) {
$updateStr = "";
$comma = '';
foreach($update as $item) {
$updateStr .= $comma.$this->escape($item);
$comma = ',';
}
}
else {
$updateStr = $this->escape($update);
}
$ret = "HTML_AJAX.{$type}(".$this->escape($id).",{$updateStr});\n";
if ($enclose) {
$ret = $this->encloseInScript($ret);
}
return $ret;
}
/**
* Escape a string and add quotes allowing it to be a javascript paramater
*
* @param string $input
* @return string
* @todo do something here besides a quick hack
*/
function escape($input) {
return "'".addslashes($input)."'";
}
/**
* Enclose a string in a script block
*
* @param string $input
* @return string
*/
function encloseInScript($input) {
return '<script
type="text/javascript">'.$input."</script>\n";
}
}
?>