Class NAJAX_Server

Description

NAJAX Server Class.

This class is used to handle client callbacks.

Example:

  1. <?php
  2.  
  3. require_once('najax.php');
  4.  
  5. class Calculator
  6. {
  7. var $result;
  8.  
  9. function Calculator()
  10. {
  11. $this->result = 0;
  12. }
  13.  
  14. function Add($arg)
  15. {
  16. $this->result += $arg;
  17. }
  18. }
  19.  
  20. NAJAX_Server::runServer();
  21.  
  22. ?>

  • version: 0.4.1.0
  • author: Stanimir Angeloff

Located in /classes/Server.class.php (line 77)

NAJAX_Observable
   |
   --NAJAX_Server
Method Summary
string addObserver (mixed &$observer)
void allowClasses (mixed $classes)
void denyClasses (mixed $classes)
string dispatch ()
void handleError (int $type, string $message)
bool isClassAllowed (string $class)
void loadClass (string $className)
void mapClass (string $className, mixed $files)
bool notifyObservers ([mixed $event = 'default'], [mixed $arg = null])
bool runServer ()
string throwException (string $message)
Methods
addObserver (line 832)

Adds a NAJAX_Server events observer.

  • return: true on success, false otherwise.
  • static:
  • access: public
string addObserver (mixed &$observer)
  • mixed $observer: The observer object to add (must extend NAJAX_Observer).

Redefinition of:
NAJAX_Observable::addObserver()
allowClasses (line 670)

Adds specified classes to the allowed classes map.

Example:

  1. <?php
  2.  
  3. class AllowedClass
  4. {
  5. function call() { return 'AllowedClass->call()'; }
  6. }
  7.  
  8. class DeniedClass
  9. {
  10. function call() { return 'DeniedClass->call()'; }
  11. }
  12.  
  13. require_once('najax.php');
  14.  
  15. NAJAX_Server::allowClasses('AllowedClass');
  16.  
  17. if (NAJAX_Server::runServer()) {
  18.  
  19. exit;
  20. }
  21.  
  22. ?>
  23. <?= NAJAX_Utilities::header() ?>
  24.  
  25. <script type="text/javascript">
  26.  
  27. var allowedClass = <?= NAJAX_Client::register(new AllowedClass()) ?>;
  28.  
  29. var deniedClass = <?= NAJAX_Client::register(new DeniedClass()) ?>;
  30.  
  31. alert(allowedClass.call());
  32.  
  33. // This line will throw an exception.
  34. // DeniedClass is not in the allowed classes list.
  35. alert(deniedClass.call());
  36.  
  37. </script>

  • static:
  • access: public
void allowClasses (mixed $classes)
  • mixed $classes: The classes that can be accessed within a callback request.
denyClasses (line 748)

Adds specified classes to the denied classes map.

Example:

  1. <?php
  2.  
  3. class AllowedClass
  4. {
  5. function call() { return 'AllowedClass->call()'; }
  6. }
  7.  
  8. class DeniedClass
  9. {
  10. function call() { return 'DeniedClass->call()'; }
  11. }
  12.  
  13. require_once('najax.php');
  14.  
  15. NAJAX_Server::denyClasses('DeniedClass');
  16.  
  17. if (NAJAX_Server::runServer()) {
  18.  
  19. exit;
  20. }
  21.  
  22. ?>
  23. <?= NAJAX_Utilities::header() ?>
  24.  
  25. <script type="text/javascript">
  26.  
  27. var allowedClass = <?= NAJAX_Client::register(new AllowedClass()) ?>;
  28.  
  29. var deniedClass = <?= NAJAX_Client::register(new DeniedClass()) ?>;
  30.  
  31. alert(allowedClass.call());
  32.  
  33. // This line will throw an exception.
  34. // DeniedClass is in the denied classes list.
  35. alert(deniedClass.call());
  36.  
  37. </script>

  • static:
  • access: public
void denyClasses (mixed $classes)
  • mixed $classes: The classes that can NOT be accessed within a callback request.
dispatch (line 355)

Dispatches a client callback to the server.

  • return: Outputs JavaString code that contains the result and the output of the callback.
  • static:
  • access: public
string dispatch ()
handleError (line 475)

Handles all errors that occur during the callback.

Only E_ERROR, E_PARSE, E_CORE_ERROR, E_COMPILE_ERROR and E_USER_ERROR will halt the callback and throw an exception.

  • static:
  • access: private
void handleError (int $type, string $message)
  • int $type: Error type (compile, core, user...).
  • string $message: Error message.
initializeCallback (line 138)

Checks if the request is a client callback to the server and initializes callback parameters.

  • return: true if the request is a valid client callback, false otherwise.
  • static:
  • access: public
bool initializeCallback ()
isClassAllowed (line 785)

Checks if a class can be accessed within a callback request.

  • return: true if the class can be accessed, false if the class is denied and can NOT be accessed.
  • static:
  • access: private
bool isClassAllowed (string $class)
  • string $class: The class name to check.
loadClass (line 587)

Loads a specified class from the classes map.

  • static:
  • access: private
void loadClass (string $className)
  • string $className: The class name to load. Note that all files that are included in the class map will be loaded.
mapClass (line 563)

Adds a specified class to the classes map.

Example:

  1. <?php
  2.  
  3. require_once('najax.php');
  4.  
  5. NAJAX_Server::mapClass('Calculator', 'Calculator.class.php');
  6.  
  7. NAJAX_Server::mapClass('EnglishDictionary', array('BaseDictionary.class.php', 'EnglishDictionary.class.php'));
  8.  
  9. NAJAX_Server::runServer();
  10.  
  11. ?>

  • static:
  • access: public
void mapClass (string $className, mixed $files)
  • string $className: The class name to add.
  • mixed $files: The files that are required to load the class.
notifyObservers (line 844)
  • access: private
bool notifyObservers ([mixed $event = 'default'], [mixed $arg = null])

Redefinition of:
NAJAX_Observable::notifyObservers()
runServer (line 91)

Checks if the request is a client callback to the server and handles it.

  • return: true if the request is a valid client callback, false otherwise.
  • static:
  • access: public
bool runServer ()
throwException (line 514)

Throws a NAJAX callback exception.

  • return: Outputs JavaString code that contains the exception message.
  • static:
  • access: private
string throwException (string $message)
  • string $message: Exception message.

Inherited Methods

Inherited From NAJAX_Observable

NAJAX_Observable::addObserver()
NAJAX_Observable::notifyObservers()

Documentation generated on Tue, 20 Sep 2005 21:40:29 +0300 by phpDocumentor 1.3.0RC3