Source for file Hook.php
Documentation is available at Hook.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>
* Hook class that allows to run a function or a method specified by their name.
* @param hook The name of a function or an array specifying a class and its method.
* @return boolean true if everything is ok.
* @throws PoAException if something goes wrong.
// perform some sanity checks
throw new PoAException('hook-error', E_USER_ERROR, array($printable));
// if array, check no. of elements
throw new PoAException('hook-error', E_USER_ERROR, array($printable));
// if array and no. of elements is ok, check it
// not an object and the class does not exist
throw new PoAException('hook-error', E_USER_ERROR, array($printable));
// not an object, but the class exists
// is there such method in the class?
throw new PoAException('hook-error', E_USER_ERROR, array($printable));
$this->_hook = array($object, $method);
$this->_name = $class. "::". $method;
// an object, is there such method in the class?
throw new PoAException('hook-error', E_USER_ERROR, array($printable));
// an object, everything ok
$this->_hook = array($class, $method);
// a function, check if we can call it
throw new PoAException('hook-error', E_USER_ERROR, array($printable));
* Run the hook with the specified params.
* @param args An array with all the params the function receives.
* @return boolean The return value of the function. Please, bear in mind that the function
* must return true if hooks proccessing should stop, false in any other case.
public function run(&$args) {
while ($i < count($args)) {
$input .= "\$args[". $i. "],";
$input = trim($input, ",");
* Get the name of the hook.
* @return string The name.
|