⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 server.class.php

📁 Ajax最流行书籍
💻 PHP
📖 第 1 页 / 共 2 页
字号:
				if (NAJAX_Server::notifyObservers('dispatchFailed', array('request' => &$requestBody, 'message' => NAJAX_SERVER_EXCEPTION))) {					NAJAX_Server::throwException(NAJAX_SERVER_EXCEPTION);					return false;				}			}			$callbackResponse['returnObject'] =& $requestBody['source'];			if ($outputBuffering) {				$output = @ob_get_contents();				if ( ! empty($output)) {					$callbackResponse['output'] = $output;				}				@ob_end_clean();			}			restore_error_handler();			if (NAJAX_Server::notifyObservers('dispatchLeave', array('request' => &$requestBody, 'response' => &$callbackResponse))) {				print NAJAX_Client::register($callbackResponse);			}		}	}	/**	 * Handles all errors that occur during the callback.	 *	 * <p>Only E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR and E_USER_ERROR	 * will halt the callback and throw an exception.</p>	 *	 * @access	private	 *	 * @param	int		$type		Error type (compile, core, user...).	 *	 * @param	string	$message	Error message.	 *	 * @return	void	 *	 * @static	 *	 */	function handleError($type, $message)	{		if (error_reporting()) {			if ( ! NAJAX_Server::notifyObservers('handleErrorEnter', array('type' => &$type, 'message' => &$message))) {				return false;			}			$breakLevel = E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR;			if (($type & $breakLevel) > 0) {				if ( ! defined('NAJAX_SERVER_EXCEPTION')) {					/**					 * Defines the error message that caused the callback to halt.					 */					define('NAJAX_SERVER_EXCEPTION', $message);				}			}		}		NAJAX_Server::notifyObservers('handleErrorLeave', array('type' => &$type, 'message' => &$message));	}	/**	 * Throws a NAJAX callback exception.	 *	 * @access	private	 *	 * @param	string	$message	Exception message.	 *	 * @return	string	Outputs JavaString code that contains the	 *					exception message.	 *	 * @static	 *	 */	function throwException($message)	{		if ( ! NAJAX_Server::notifyObservers('throwExceptionEnter', array('message' => &$message))) {			return false;		}		restore_error_handler();		$callbackException = array();		$callbackException['exception'] = $message;		if (NAJAX_Server::notifyObservers('throwExceptionLeave', array('message' => &$message))) {			print NAJAX_Client::register($callbackException);		}	}	/**	 * Adds a specified class to the classes map.	 *	 * <p>Example:</p>	 * <code>	 * <?php	 *	 * require_once('najax.php');	 *	 * NAJAX_Server::mapClass('Calculator', 'Calculator.class.php');	 *	 * NAJAX_Server::mapClass('EnglishDictionary', array('BaseDictionary.class.php', 'EnglishDictionary.class.php'));	 *	 * NAJAX_Server::runServer();	 *	 * ?>	 * </code>	 *	 * @access	public	 *	 * @param	string	$className	The class name to add.	 *	 * @param	mixed	$files		The files that are required	 *								to load the class.	 *	 * @return	void	 *	 * @static	 *	 */	function mapClass($className, $files)	{		if ( ! isset($GLOBALS['_NAJAX_SERVER_CLASSES_MAP'])) {			$GLOBALS['_NAJAX_SERVER_CLASSES_MAP'] = array();		}		$GLOBALS['_NAJAX_SERVER_CLASSES_MAP'][strtolower($className)] = $files;	}	/**	 * Loads a specified class from the classes map.	 *	 * @access	private	 *	 * @param	string	$className	The class name to load. Note that all files	 *								that are included in the class map will be	 *								loaded.	 *	 * @return	void	 *	 * @static	 *	 */	function loadClass($className)	{		$className = strtolower($className);		if ( ! empty($GLOBALS['_NAJAX_SERVER_CLASSES_MAP'])) {			if (isset($GLOBALS['_NAJAX_SERVER_CLASSES_MAP'][$className])) {				$files = $GLOBALS['_NAJAX_SERVER_CLASSES_MAP'][$className];				$filesType = NAJAX_Utilities::getType($files);				if ($filesType == 'string') {					require_once($files);				} else if (				($filesType == 's_array') ||				($filesType == 'a_array')) {					foreach ($files as $fileName) {						require_once($fileName);					}				}			}		}	}	/**	 * Adds specified classes to the allowed classes map.	 *	 * <p>Example:</p>	 * <code>	 * <?php	 *	 * class AllowedClass	 * {	 * 	function call() { return 'AllowedClass->call()'; }	 * }	 *	 * class DeniedClass	 * {	 * 	function call() { return 'DeniedClass->call()'; }	 * }	 *	 * require_once('najax.php');	 *	 * NAJAX_Server::allowClasses('AllowedClass');	 *	 * if (NAJAX_Server::runServer()) {	 *	 * 	exit;	 * }	 *	 * ?>	 * <?= NAJAX_Utilities::header() ?>	 *	 * <script type="text/javascript">	 *	 * var allowedClass = <?= NAJAX_Client::register(new AllowedClass()) ?>;	 *	 * var deniedClass = <?= NAJAX_Client::register(new DeniedClass()) ?>;	 *	 * alert(allowedClass.call());	 *	 * // This line will throw an exception.	 * // DeniedClass is not in the allowed classes list.	 * alert(deniedClass.call());	 *	 * </script>	 * </code>	 *	 * @access	public	 *	 * @param	mixed	$classes	The classes that can be accessed within	 *								a callback request.	 *	 * @return	void	 *	 * @static	 *	 */	function allowClasses($classes)	{		$classesType = NAJAX_Utilities::getType($classes);		if ( ! isset($GLOBALS['_NAJAX_SERVER_ALLOWED_CLASSES'])) {			$GLOBALS['_NAJAX_SERVER_ALLOWED_CLASSES'] = array();		}		$allowedClasses =& $GLOBALS['_NAJAX_SERVER_ALLOWED_CLASSES'];		if ($classesType == 'string') {			$allowedClasses[] = strtolower($classes);		} else if (($classesType == 's_array') || ($classesType == 'a_array')) {			foreach ($classes as $class) {				$allowedClasses[] = strtolower($class);			}		}	}	/**	 * Adds specified classes to the denied classes map.	 *	 * <p>Example:</p>	 * <code>	 * <?php	 *	 * class AllowedClass	 * {	 * 	function call() { return 'AllowedClass->call()'; }	 * }	 *	 * class DeniedClass	 * {	 * 	function call() { return 'DeniedClass->call()'; }	 * }	 *	 * require_once('najax.php');	 *	 * NAJAX_Server::denyClasses('DeniedClass');	 *	 * if (NAJAX_Server::runServer()) {	 *	 * 	exit;	 * }	 *	 * ?>	 * <?= NAJAX_Utilities::header() ?>	 *	 * <script type="text/javascript">	 *	 * var allowedClass = <?= NAJAX_Client::register(new AllowedClass()) ?>;	 *	 * var deniedClass = <?= NAJAX_Client::register(new DeniedClass()) ?>;	 *	 * alert(allowedClass.call());	 *	 * // This line will throw an exception.	 * // DeniedClass is in the denied classes list.	 * alert(deniedClass.call());	 *	 * </script>	 * </code>	 *	 * @access	public	 *	 * @param	mixed	$classes	The classes that can NOT be accessed	 *								within a callback request.	 *	 * @return	void	 *	 * @static	 *	 */	function denyClasses($classes)	{		$classesType = NAJAX_Utilities::getType($classes);		if ( ! isset($GLOBALS['_NAJAX_SERVER_DENIED_CLASSES'])) {			$GLOBALS['_NAJAX_SERVER_DENIED_CLASSES'] = array();		}		$deniedClasses =& $GLOBALS['_NAJAX_SERVER_DENIED_CLASSES'];		if ($classesType == 'string') {			$deniedClasses[] = strtolower($classes);		} else if (($classesType == 's_array') || ($classesType == 'a_array')) {			foreach ($classes as $class) {				$deniedClasses[] = strtolower($class);			}		}	}	/**	 * Checks if a class can be accessed within a callback request.	 *	 * @access	private	 *	 * @param	string	$class	The class name to check.	 *	 * @return	bool	true if the class can be accessed, false if	 *					the class is denied and can NOT be accessed.	 *	 * @static	 *	 */	function isClassAllowed($class)	{		$allowedClasses = null;		$deniedClasses = null;		if (isset($GLOBALS['_NAJAX_SERVER_ALLOWED_CLASSES'])) {			$allowedClasses =& $GLOBALS['_NAJAX_SERVER_ALLOWED_CLASSES'];		}		if (isset($GLOBALS['_NAJAX_SERVER_DENIED_CLASSES'])) {			$deniedClasses =& $GLOBALS['_NAJAX_SERVER_DENIED_CLASSES'];		}		if ( ! empty($deniedClasses)) {			if (in_array(strtolower($class), $deniedClasses)) {				return false;			}		}		if ( ! empty($allowedClasses)) {			if ( ! in_array(strtolower($class), $allowedClasses)) {				return false;			}		}		return true;	}	/**	 * Adds a {@link NAJAX_Server} events observer.	 *	 * @access	public	 *	 * @param	mixed	$observer	The observer object to add (must extend {@link NAJAX_Observer}).	 *	 * @return	string	true on success, false otherwise.	 *	 * @static	 *	 */	function addObserver(&$observer)	{		return parent::addObserver($observer, 'NAJAX_Server');	}	/**	 *	 * @access	private	 *	 * @return	bool	 *	 */	function notifyObservers($event = 'default', $arg = null)	{		return parent::notifyObservers($event, $arg, 'NAJAX_Server');	}}?>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -