Class Ismo_Core_Application

Description

This is the class that receives the request and forwards it to the right IsmoState class.

You can subclass from this class if you want change the way the state classes are determined and found.

Additional documentation is available in the IsmoWiki at http://ismo.sourceforge.net/wiki/IsmoApplication

Located in /Application.php (line 61)


	
			
Variable Summary
mixed $_config
array $_filters
mixed $_logger
string $_name
IsmoRequest $_request
integer $_URLStyle
Method Summary
Ismo_Core_Application Ismo_Core_Application (string $name)
void execute ()
void registerFilter (IsmoFilter $filterClassInstance)
void setConfiguration (mixed &$config)
void setDefaultState (string $state)
void setLogger (mixed &$logInstance)
void setMissingStateCallBack (callback $callback)
void setRequest (mixed &$requestInstance)
void setStateLoader (mixed &$loader)
void setURLStyle (integer $style)
string _deduceState ()
void _dispatch (string $stateName)
void _init ()
void _stateMissing (string $name)
Variables
mixed $_config = null (line 154)

A temporary place to store a configuration container, until it's passed the the state.

  • access: private
string $_defaultState (line 70)

The default state.

  • access: private
array $_filters = array() (line 80)

The registered filters to call before processing a request.

  • access: private
mixed $_logger = null (line 96)

The logger class used.

By default the IsmoNullLogger is used and as can be guessed from it's name it's not logging anything. The logger class used can be changed with the setLogger() method.

  • access: private
callback $_missingStateCallBack = null (line 165)

This is an optional callback function (any callback PHP supports) called when a requested state can't be found.

  • access: private
string $_name (line 106)

The application's name.

  • access: private
IsmoRequest $_request (line 116)

The IsmoRequest instance that represents this request.

  • access: private
mixed $_stateLoader = null (line 132)

The state loader to use.

The state loader is the class that loads and makes instances of the state classes.

Example of state loaders are Ismo_Core_Loaders_FileSystem and Ismo_Core_Loaders_IncludePath.

  • access: private
integer $_URLStyle = ISMO_CORE_QUERY_STYLE (line 143)

The URL style to use when determining the state and action and also when generating new URLs.

  • access: private
Methods
Constructor Ismo_Core_Application (line 175)

The constructor.

  • access: public
Ismo_Core_Application Ismo_Core_Application (string $name)
  • string $name: the name of the application
execute (line 358)

Handles the request by executing the right action method.

  • access: public
void execute ()
registerFilter (line 405)

Registers a filter.

Before a request is processed and handed down to the state that will take care of it, the filter() method on all the registered filter class instances are called. It's given the request URI and the filter class can then decided if this request is allowed or not.

If a filter class returns true when its filter() method is called, it is assumed that the filter class has handled the request (usually be forwarding somewhere, e.g. a login page). If the method returns false the next filter class's filter() method is called.

This continues until all the registered filter classes have been processed. If all method calls returned false the state is deduced and the execution given to it.

  • access: public
void registerFilter (IsmoFilter $filterClassInstance)
  • IsmoFilter $filterClassInstance: the from IsmoFilter extended filter class instance
setConfiguration (line 535)

Set the configuration to pass to the state instance.

You can use this method to pass any global configuration parameters to the dispatched state.

  • access: public
void setConfiguration (mixed &$config)
  • mixed $config: a configuration container (variable, object or array)
setDefaultState (line 424)

This sets the application's default state.

Example:

  1. $a = new MyApplication();
  2. $a->setDefaultState('default');

  • access: public
void setDefaultState (string $state)
  • string $state: the default state
setLogger (line 448)

This sets the log class being used.

If you're making your own class it should implement the PEAR package Log's Log interface but it might be easier to just use one of the the Log package's ready implementations.

Example:

  1. $app = new Ismo_Core_Application('foo');
  2. $log =& new Log_file('log.txt', 'identity text');
  3. $app->setLogger($log);

  • access: public
void setLogger (mixed &$logInstance)
  • mixed $logInstance: the logging class instance to use
setMissingStateCallBack (line 309)

Set a callback function for missing state errors.

Use this method to set a callback function to be called when a requested state can't be found.

  • access: public
void setMissingStateCallBack (callback $callback)
  • callback $callback: a callback function
setRequest (line 462)

This sets the request class instance to use.

  • access: public
void setRequest (mixed &$requestInstance)
  • mixed $requestInstance: the request class instance to use
setStateLoader (line 489)

This sets the loader class to use.

The state loader is the class that loads and makes instances of the state classes.

Example of state loaders are Ismo_Core_Loaders_FileSystem and Ismo_Core_Loaders_IncludePath.

Example:

  1. $loader = new Ismo_Core_Loaders_FileSystem();
  2. $loader->setStatePath('./states');
  3. $app = new Ismo_Core_Application('MyCoolName');
  4. $app->setStateLoader($loader);

  • access: public
void setStateLoader (mixed &$loader)
  • mixed $loader: the state loader class instance to use
setURLStyle (line 516)

Controls which kind of URL style that will be used.

IsmoCore currently supports two kind of styles. The normal query parameter based one, i.e. http://foo.bar?state=thaState&action=theAction and the path-info parameter based on, which looks like http://foo.bar/theState/theAction.

By default the query parameter based style is used, but that can be changed using this method.

The style setting determines how the state and action is identified and it also affects the created URL:s.

  • access: public
void setURLStyle (integer $style)
  • integer $style: which style to use, either ISMO_CORE_QUERY_STYLE or ISMO_CORE_PATHINFO_STYLE
_deduceState (line 193)

Figures out the state.

Tries to figure out what the current state is and if it can't uses the "default" state. You might want to override this method if you want change how the current state is decided.

  • return: the current state
  • access: private
string _deduceState ()
_dispatch (line 230)

Dispatches the request to the right state class.

Tries to find a file named <state name>.php in the current directory. If one is found it is included and an instance of a class named <state name> is created. If the instance was created sucessfully the execute method of that instance is called and that method calls the perform method.

If something fails the stateMissing method is called.

void _dispatch (string $stateName)
  • string $stateName: the name of the state
_init (line 287)

Initializes the class.

Sets the _request and _logger attributes if they are not already set.

This makes it easier to unit test this class.

  • access: private
void _init ()
_stateMissing (line 329)

Missing state handler.

This method is called whenever a state is requested which doesn't have a matching state-class or when an error happened when the state was included or the instance created.

If an appropriate callback function is set it's called, otherwise a regular HTTP 404 error is thrown.

  • access: private
void _stateMissing (string $name)
  • string $name: the requested state's name

Documentation generated on Mon, 14 Jun 2004 11:59:12 +0200 by phpDocumentor 1.3.0RC3