rm trailing white space
[mediawiki.git] / PHPTAL-NP-0.7.0 / libs / PHPTAL / SourceResolver.php
blob735a161160270f225ea994a5dcd03ef752103c13
1 <?php
3 /**
4 * This class is used to resolve template source path outside the file system.
6 * Given a path, a template repository and a template caller path, one resolver
7 * must decide whether or not it can retrieve the template source.
9 * @author Laurent Bedubourg <laurent.bedubourg@free.fr>
11 class PHPTAL_SourceResolver
13 /**
14 * Resolve a template source path.
16 * This method is invoked each time a template source has to be
17 * located.
19 * This method must returns a PHPTAL_SourceLocator object which
20 * 'point' to the template source and is able to retrieve it.
22 * If the resolver does not handle this kind of path, it must return
23 * 'false' so PHPTAL will ask other resolvers.
25 * @param string $path -- path to resolve
27 * @param string $repository -- templates repository if specified on
28 * on template creation.
30 * @param string $callerPath -- caller realpath when a template look
31 * for an external template or macro,
32 * this should be usefull for relative urls
34 * @return PHPTAL_SourceLocator | false
36 function resolve($path, $repository=false, $callerPath=false)
38 // first look at an absolute path
39 $pathes = array($path);
40 // search in the caller directory
41 if ($callerPath) {
42 $pathes[] = dirname($callerPath) . PHPTAL_PATH_SEP . $path;
44 // search in the template repository
45 if ($repository) {
46 $pathes[] = $repository . PHPTAL_PATH_SEP . $path;
48 // search in the defined repository
49 if (defined('PHPTAL_REPOSITORY')) {
50 $pathes[] = PHPTAL_REPOSITORY . PHPTAL_PATH_SEP . $path;
52 foreach ($pathes as $ftest) {
53 if (file_exists($ftest)) {
54 $realpath = realpath($ftest);
55 $locator = new PHPTAL_SourceLocator($realpath);
56 return $locator;
59 return false;