Location: PHPKode > scripts > actions_dispatcher > actions_dispatcher/actions.inc.php

	Action Dispatching control v.1.0.101
	Dispatches queries centralizing it on a unique index.php, a better, clean way to PHP scripting.
	By Llorenç Herrera [hide@address.com]
	Copyright 2002, Llorenç Herrera
	Please do not remove this credits
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
	class action
		var $todo_class;
		var $todo;
		var $getvariables;
		function action ($todo_class, $todo, $getvariables)
			$this->todo_class = &$todo_class;
			$this->todo = $todo;
			if (is_array ($getvariables)) $this->getvariables = $getvariables;
		function execute ()
			$todo_class = $this->todo_class;
			$todo = $this->todo;
			if (is_array ($this->getvariables))
				$variables = $this->getvariables;
				$numvariables = sizeof ($variables);
				while (list (,$value) = each ($variables))
					$v[] = $value;
				$numvariables = 0;
			switch ($numvariables)
				case 0:		$todo_class->$todo (); break;
				case 1:		$todo_class->$todo ($v[0]); break;
				case 2:		$todo_class->$todo ($v[0], $v[1]); break;
				case 3:		$todo_class->$todo ($v[0], $v[1], $v[2]); break;
				case 4:		$todo_class->$todo ($v[0], $v[1], $v[2], $v[3]); break;
				case 5:		$todo_class->$todo ($v[0], $v[1], $v[2], $v[3], $v[4]); break;
				case 6:		$todo_class->$todo ($v[0], $v[1], $v[2], $v[3], $v[4], $v[5]); break;
				case 7:		$todo_class->$todo ($v[0], $v[1], $v[2], $v[3], $v[4], $v[5], $v[6]); break;
				case 8:		$todo_class->$todo ($v[0], $v[1], $v[2], $v[3], $v[4], $v[5], $v[6], $v[7]); break;
				case 9:		$todo_class->$todo ($v[0], $v[1], $v[2], $v[3], $v[4], $v[5], $v[6], $v[7], $v[8]); break;
				case 10:	$todo_class->$todo ($v[0], $v[1], $v[2], $v[3], $v[4], $v[5], $v[6], $v[7], $v[8], $v[9]); break;
				case 11:	$todo_class->$todo ($v[0], $v[1], $v[2], $v[3], $v[4], $v[5], $v[6], $v[7], $v[8], $v[9], $v[10]); break;
				case 12:	$todo_class->$todo ($v[0], $v[1], $v[2], $v[3], $v[4], $v[5], $v[6], $v[7], $v[8], $v[9], $v[10], $v[11]); break;
				case 13:	$todo_class->$todo ($v[0], $v[1], $v[2], $v[3], $v[4], $v[5], $v[6], $v[7], $v[8], $v[9], $v[10], $v[11], $v[12]); break;
				case 14:	$todo_class->$todo ($v[0], $v[1], $v[2], $v[3], $v[4], $v[5], $v[6], $v[7], $v[8], $v[9], $v[10], $v[11], $v[12], $v[13]); break;
				case 15:	$todo_class->$todo ($v[0], $v[1], $v[2], $v[3], $v[4], $v[5], $v[6], $v[7], $v[8], $v[9], $v[10], $v[11], $v[12], $v[13], $v[14]); break;
	class actions_dispatcher
		var $indexfilename;
		var $actions;
		var $defaultaction;
		function actions_dispatcher ($indexfilename, $defaultaction)
			$this->indexfilename	= $indexfilename;
			$this->defaultaction	= $defaultaction;
		function addaction ($id, $todo_class, $todo, $getvariables)
			$this->actions[$id] = new action ($todo_class, $todo, $getvariables);
		function doaction ()
			global $a;
			if (isset ($this->actions[$a]))
				$this->actions[$a]->execute ();
				$this->actions[$this->defaultaction]->execute ();

Return current item: actions_dispatcher