Source for file GenericEngine.php
Documentation is available at GenericEngine.php
* @copyright Copyright 2005-2010 RedIRIS, http://www.rediris.es/
* This file is part of phpPoA2.
* phpPoA2 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 3 of the License, or
* (at your option) any later version.
* phpPoA2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with phpPoA2. If not, see <http://www.gnu.org/licenses/>.
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License
* @author Jaime Perez <jaime.perez@rediris.es>
* A generic engine class.
* Main constructor for the engine.
* @param file The path to the configuration file. Can be in the include path.
* @param section The section of the configuration file, if any.
//$this->handler = new PoAEventHandler($site);
* @param file The path to the configuration file. Can be in the include path.
* @param section The section of the configuration file, if any.
// search and initialize configurator
$this->cfg = new $configurator($file,$section);
* Adds a function to the specified hook, which will be executed at some point of the code.
* @param name The name of the hook.
* @param hook A mixed object. Can be the name of a function (string) or
* an array with two elements: the former, the name of a class or an object,
* and the latter the name of the method.
* @return boolean true if successful, false in any other case.
public function addHook($name, $hook) {
// check if the hook exists
if (!($hook instanceof Hook)) return false;
// check if the hook is registered
$this->hooks[$name][] = $hook;
* Removes a function fromt he specified hook.
* @param name The name of the hook.
* @param hook A mixed object. Can be the name of a function (string) or
* an array with two elements: the former, the name of a class or an object,
* and the latter the name of the method.
* @return boolean true if successful, false in any other case.
// check if the hook exists
// check if the hook is registered
foreach ($this->hooks[$name] as $item) {
$this->hooks[$name] = $new;
* Run all hooks attached to an specific action.
* @param hook The name of the hook.
* @param params An array with all params (in order) that must be passed to the function.
protected function runHooks($hook, &$params) {
// check if the hook exists
foreach ($this->hooks[$hook] as $h) {
if ($h->run($params)) break;
* Set the event handler to the one specified.
* @param handler The event handler to use.
* Register error and exception handlers for logging. Use it only for methods not declared
* in the interface that could trigger errors.
// register autoload function
* Unregister error and exception handlers. Use it only for methods not declared in the
* interface that previously called registerHandler() method.
protected function clean() {
|