--- /dev/null
+<?php
+/***************************************************************************
+ * Copyright (C) 2003-2004 Polytechnique.org *
+ * http://opensource.polytechnique.org/ *
+ * *
+ * 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 *
+ * 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 this program; if not, write to the Free Software *
+ * Foundation, Inc., *
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
+ ***************************************************************************
+ $Id: xorg.hook.inc.php,v 1.1 2004-11-20 22:32:01 x2000habouzit Exp $
+ ***************************************************************************/
+
+require_once("PEAR.php");
+
+/** Hooks are used in modules to allow modules that depends upon us to hook
+ * themselves in our core functionnalities.
+ *
+ * Every module will use some hools, and define their names.
+ * Pretend « myhook » is one of those names, then :
+ * - hooks/myhook/API has to exists, and will explain the API of the hook
+ * - every module "mod" may have a file hooks/myhook/mod.inc.php that implements
+ * fully or partially the API of the hook.
+ *
+ * If the hook's API has to change, the functions that change MUST change their
+ * name to avoid any compatibility problem.
+ */
+class XOrgHook extends PEAR
+{
+ /** name of the hook we want to run */
+ var $_name;
+ /** name of all the modules that have exported some functions */
+ var $_mods = Array();
+
+ function XOrgHook($name)
+ {
+ global $globals;
+ $this->PEAR();
+
+ if (!file_exists($globals->root."/hooks/$name/API")) {
+ $this->raiseError("The hook $name do not exists, or is undocumented",1,PEAR_ERROR_DIE);
+ }
+ foreach (glob($globals->root."/hooks/$name/*.inc.php") as $file) {
+ require_once("$file");
+ $this->_mods[] = str_replace('.inc.php', '', $file);
+ }
+ }
+
+ function __call($function, $arguments, &$return)
+ {
+ foreach ($this->_mods as $mod) {
+ if (!function_exists($mod.'_'.$function)) continue;
+ call_user_func_array($mod.'_'.$function,$argument);
+ }
+
+ return ($return=true);
+ }
+}
+
+overload('XOrgHook');
+
+?>