Re: Earthquake in Text_Wiki

From: Date: Wed, 26 May 2004 21:31:12 +0000
Subject: Re: Earthquake in Text_Wiki
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-29733@lists.php.net to get a copy of this message
Zitat von Paul M Jones <pmjones@ciaweb.net>:
Under the new directory structure, it appears to me that the old way of assigning user-defined rules is not going to work well (i.e., independent file name and class name). Instead, the new system will require that rule class names follow the standard PEAR naming convention, whether the rules are from Text_Wiki or user-defined. However, there is a system I use in Savant that may help with this. In Savant, you can define multiple search paths for templates, plugins, and filters; then, when it tries to auto-load a file, it searches those paths and uses the first matching file. This means that user-defined plugins take precedence over the default plugins. This has the added advantage that it can "fall back" to the default file on an arbitrary basis.
You might also consider how implement our factory methods in Horde. Take this example:
    /**
     * Attempts to return a concrete Horde_Cache instance based on
     * $driver.
     *
     * @access public
     *
     * @param mixed $driver           The type of concrete Horde_Cache
subclass to
     *                                return. This is based on the storage
     *                                driver ($driver). The code is
     *                                dynamically included. If $driver is an
     *                                array, then we will look in
     *                                $driver[0]/lib/Cache/ for the subclass
     *                                implementation named $driver[1].php.
     * @param optional array $params  A hash containing any additional
     *                                configuration or connection parameters
a
     *                                subclass might need.
     *
     * @return object Horde_Cache  The newly created concrete Horde_Cache
instance,
     *                             or false on error.
     */
    function &factory($driver, $params = array())
    {
        if (is_array($driver)) {
            $app = $driver[0];
            $driver = $driver[1];
        }
        $driver = basename($driver);
        if (empty($driver) || $driver == 'none') {
            return $ret = &new Horde_Cache($params);
        }
        if (!empty($app)) {
            require_once $app . '/lib/Cache/' . $driver . '.php';
        } elseif (@file_exists(dirname(__FILE__) . '/Cache/' . $driver .
'.php')) {
            require_once dirname(__FILE__) . '/Cache/' . $driver . '.php';
        } else {
            @include_once 'Horde/Cache/' . $driver . '.php';
        }
        $class = 'Horde_Cache_' . $driver;
        if (class_exists($class)) {
            return $ret = &new $class($params);
        } else {
            return PEAR::raiseError('Class definition of ' . $class . ' not
found.');
        }
    }
This actually easier and faster than searching a whole set of paths. Jan. -- Do you need professional PHP or Horde consulting? http://horde.org/consulting.php

« previous php.pear.dev (#29733) next »