Re: Earthquake in Text_Wiki

From: Date: Wed, 26 May 2004 21:58:29 +0000
Subject: Re: Earthquake in Text_Wiki
References: 1  Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-29734@lists.php.net to get a copy of this message
Hi, Jan,
This actually easier and faster than searching a whole set of paths.
This is good stuff. However, I'm not sure it will work in this particular case. Here's what makes me think so (and I may be wrong).
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'; }
OK, so: dirname(__FILE__) refers to the directory holding the current file. However, the problem I run into is how to get to the file in the first place. Right now, Text_Wiki needs a relative or absolute path to the class file to load it, so obviously it knows how to get to the file that way. Under the new plan, still in construction :-), we kind of go back to an earlier form of Text_Wiki. The parsing and rendering class names and file names will have to conform to a convention, and the will not take a file path and class name as part of the info about the rule class. Only the name of the rule will be passed in (e.g., 'bold', not 'Text/Wiki/Rule/bold.php' and 'Text_Wiki_Rule_bold'). This should simplify the construction of custom rule sets. So here's the problem: if the new system does not use file paths as part of the rule info, and users want to specify that Text_Wiki should use a custom 'bold' parser and the default parsers for everything else, there's no way to tell Text_Wiki where that one parsing class is; its location is completely arbitrary. The reference to __FILE__ cannot be counted on, because the custom location may be outside the path to __FILE__. The solution for this, in Savant, was to specify which paths to search, falling back to a previous path whenever the file was not found. The speed hit does not appear to be dramatic, although certainly it is there. I think a similar solution might work in Text_Wiki, where users specify where their custom parse and render classes are located. If Text_Wiki needs a 'bold' rule, it looks first in the custom location: if there's a 'Text_Wiki_Parse_Bold.php' there it gets loaded; if not, it falls back to the default location for Text_Wiki_Parse_Bold.php. This should allow end-users to mix and match custom and default rules with little confusion (I hope). -- Paul M. Jones Savant: the simple alternative to Smarty for PHP. http://phpsavant.com/ DB_Table: build RDBMS tables and XHTML forms in one PHP class. http://wiki.ciaweb.net/yawiki/index.php?area=DB_Table Yawiki: your collaborative online documentation system. http://yawiki.com/ Yawp: a single-file foundation for PHP applications. http://phpyawp.com/

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