cvs: pear /Template/Template Multipath.php Provider.php

From: Date: Mon, 14 Jun 2004 08:34:09 +0000
Subject: cvs: pear /Template/Template Multipath.php Provider.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-20637@lists.php.net to get a copy of this message
alan_k Mon Jun 14 04:34:09 2004 EDT Added files: /pear/Template/Template Multipath.php Modified files: /pear/Template/Template Provider.php Log: add basic multipath support http://cvs.php.net/diff.php/pear/Template/Template/Provider.php?r1=1.1&r2=1.2&ty=u Index: pear/Template/Template/Provider.php diff -u pear/Template/Template/Provider.php:1.1 pear/Template/Template/Provider.php:1.2 --- pear/Template/Template/Provider.php:1.1 Mon Jun 14 03:16:20 2004 +++ pear/Template/Template/Provider.php Mon Jun 14 04:34:07 2004 @@ -16,7 +16,7 @@ // | Authors: alan@akkbhome.com | // +----------------------------------------------------------------------+ // -// $Id: Provider.php,v 1.1 2004/06/14 07:16:20 alan_k Exp $ +// $Id: Provider.php,v 1.2 2004/06/14 08:34:07 alan_k Exp $ // // Example of how a Provider can be written. // @@ -71,7 +71,7 @@ $this->template = &$template; // if you add default options, merge your options. - $this->template->options = array_merge($this->template->options,$this->options); + $this->template->options = array_merge($this->options,$this->template->options); // if you change any of the default options // (you may be overriding the user specifed ones.) http://cvs.php.net/co.php/pear/Template/Template/Multipath.php?r=1.1&p=1 Index: pear/Template/Template/Multipath.php +++ pear/Template/Template/Multipath.php <?php /* vim: set expandtab tabstop=4 shiftwidth=4: */ // +----------------------------------------------------------------------+ // | PHP Version 4 | // +----------------------------------------------------------------------+ // | Copyright (c) 1997-2002 The PHP Group | // +----------------------------------------------------------------------+ // | This source file is subject to version 2.02 of the PHP license, | // | that is bundled with this package in the file LICENSE, and is | // | available at through the world-wide-web at | // | http://www.php.net/license/2_02.txt. | // | If you did not receive a copy of the PHP license and are unable to | // | obtain it through the world-wide-web, please send a note to | // | license@php.net so we can mail you a copy immediately. | // +----------------------------------------------------------------------+ // | Authors: alan@akkbhome.com | // +----------------------------------------------------------------------+ // // $Id: Multipath.php,v 1.1 2004/06/14 08:34:07 alan_k Exp $ // // Multipath Provider - checks mulitple paths for the source of a template // class Template_Provider { /** * Default options related to this provider. * Please document these...!!! * * @var array * @access public */ var $options = array( 'multisource.order' => null, // use 'reverse' - to sort backwards.. 'multisource.allow' => false, // set to true to allow the same // file to exist in multiple sources // eg for themes. ); /** * A reference to the instantated template. * * @var object Template * @access public */ var $template = null; /** * initialize the Provider. * * when the provider is created by the template, this method is called, with a * reference to the template. * * Why not use PHP Constructors? * unfortunatly this would make using a Provider as a Factory base class almost * impossible (if not a little messy. * * Why not use a static Construct method? * a) this may limit the same pattern in any subclasses. * b) it gives you the posiblility to extend a base class, that does the same as this. * * * @param object Template The instantated template. * * @return none (it may return a PEAR::Error) * @access public */ function initProvider(&$template) { // if you need to access template variables (Eg. options/data/providers) // you should store a reference to the template object. $this->template = &$template; // if you add default options, merge your options. $this->template->options = array_merge($this->options,$this->template->options); return true; } function find($file) { $options = $this->template->options; $files = &$this->template->options; //Remove the slash if there is one in front, just to be safe. $file = ltrim($file,DIRECTORY_SEPARATOR); // PART A mulitlanguage support: ( part B is gettext support in the engine..) // - user created language version of template. // - compile('abcdef.html') will check for compile('abcdef.en.html') // (eg. when locale=en) $files['current_template'] = false; $parts = array(); if ($options['locale'] && preg_match('/(.*)(\.[a-z]+)$/i',$file,$parts)) { $newfile = $parts[1].'.'.$options['locale'] .$parts[2]; $dirs = array_unique($options['template_dir']); if ($this->options['multisource.order'] == 'reverse') { $dirs = array_reverse($dirs); } foreach ($options['template_dir'] as $tmplDir) { if (@!file_exists($tmplDir . DIRECTORY_SEPARATOR .$newfile)) { continue; } if ($files['current_template'] !== false && !$options['multisource.allow']) { $old = $files['current_template']; $files['current_template'] = false; return $this->template->raiseError( "You have more than one template Named %s in your paths, found in more" . "Than once, (in %s and %s)", TEMPLATE_ERROR_INVALIDARGS, TEMPLATE_ERROR_DIE, array($newfile, $old, $tmplDir . DIRECTORY_SEPARATOR .$newfile )); } $files['current_template'] = $tmplDir . DIRECTORY_SEPARATOR .$newfile; $files['current_template_from_dir'] = $tmplDir; $files['current_template_used_file'] = $newfile; } } // found it already! ( a localized version ) if ($files['current_template']) { return; } // look in all the posible locations for the template directory.. if ($this->currentTemplate === false) { $dirs = array_unique($options['templateDir']); if ($this->options['multisource.order'] == 'reverse') { $dirs = array_reverse($dirs); } foreach ($dirs as $tmplDir) { if (!@file_exists($tmplDir . DIRECTORY_SEPARATOR . $file)) { continue; } if (!$options['multisource.allow'] && ($files['current_template'] !== false)) { return $this->template->raiseError( "You have more than one template Named %s in your paths, found in more" . "Than once, (in %s and %s)", TEMPLATE_ERROR_INVALIDARGS, TEMPLATE_ERROR_DIE, array($file, $old, $tmplDir . DIRECTORY_SEPARATOR .$file )); } $files['current_template'] = $tmplDir . DIRECTORY_SEPARATOR . $file; $files['current_template_from_dir'] = $tmplDir; } } return true; } }

« previous php.pear.cvs (#20637) next »