Source for file extends.php
Documentation is available at extends.php
* Extends another template, read more about template inheritance at {@link http://wiki.dwoo.org/index.php/TemplateInheritance}
* * file : the template to extend
* This software is provided 'as-is', without any express or implied warranty.
* In no event will the authors be held liable for any damages arising from the use of this software.
* @author Jordi Boggiano <j.boggiano@seld.be>
* @copyright Copyright (c) 2008, Jordi Boggiano
* @license http://dwoo.org/LICENSE Modified BSD License
protected static $childSource;
protected static $lastReplacement;
public static function compile(Dwoo_Compiler $compiler, $file)
list
($l, $r) =
$compiler->getDelimiters();
self::$l =
preg_quote($l,'/');
self::$r =
preg_quote($r,'/');
if ($compiler->getLooseOpeningHandling()) {
self::$r =
'\s*'.
self::$r;
$inheritanceTree =
array(array('source'=>
$compiler->getTemplateSource()));
$curPath =
dirname($compiler->getDwoo()->getTemplate()->getResourceIdentifier()) .
DIRECTORY_SEPARATOR;
$curTpl =
$compiler->getDwoo()->getTemplate();
if ($file ===
'""' ||
$file ===
"''" ||
(substr($file, 0, 1) !==
'"' &&
substr($file, 0, 1) !==
'\'')) {
if (preg_match('#^["\']([a-z]{2,}):(.*?)["\']$#i', $file, $m)) {
// resource:identifier given, extract them
// get the current template's resource
$resource =
$curTpl->getResourceName();
$identifier =
substr($file, 1, -
1);
$parent =
$compiler->getDwoo()->templateFactory($resource, $identifier, null, null, null, $curTpl);
} elseif ($parent ===
false) {
$newParent =
array('source'=>
$parent->getSource(), 'resource'=>
$resource, 'identifier'=>
$parent->getResourceIdentifier(), 'uid'=>
$parent->getUid());
if (array_search($newParent, $inheritanceTree, true) !==
false) {
$inheritanceTree[] =
$newParent;
if (preg_match('/^'.
self::$l.
'extends\s+(?:file=)?\s*((["\']).+?\2|\S+?)'.
self::$r.
'/i', $parent->getSource(), $match)) {
$curPath =
dirname($identifier) .
DIRECTORY_SEPARATOR;
if (isset
($match[2]) &&
$match[2] ==
'"') {
} elseif (isset
($match[2]) &&
$match[2] ==
"'") {
$file =
'"'.
substr($match[1], 1, -
1).
'"';
$file =
'"'.
$match[1].
'"';
$child =
end($inheritanceTree);
self::$childSource =
$child['source'];
self::$lastReplacement =
count($inheritanceTree) ===
1;
if (!isset
($newSource)) {
$newSource =
$parent['source'];
// TODO parse blocks tree for child source and new source
// TODO replace blocks that are found in the child and in the parent recursively
$newSource =
preg_replace_callback('/'.
self::$l.
'block (["\']?)(.+?)\1'.
self::$r.
'(?:\r?\n?)(.*?)(?:\r?\n?)'.
self::$l.
'\/block'.
self::$r.
'/is', array('Dwoo_Plugin_extends', 'replaceBlock'), $newSource);
$newSource =
$l.
'do extendsCheck("'.
$parent['resource'].
':'.
$parent['identifier'].
'")'.
$r.
$newSource;
if (self::$lastReplacement) {
$compiler->setTemplateSource($newSource);
if (preg_match('/'.
self::$l.
'block (["\']?)'.
preg_quote($matches[2],'/').
'\1'.
self::$r.
'(?:\r?\n?)(.*?)(?:\r?\n?)'.
self::$l.
'\/block'.
self::$r.
'/is', self::$childSource, $override)) {
$l =
stripslashes(self::$l);
$r =
stripslashes(self::$r);
if (self::$lastReplacement) {
return preg_replace('/'.
self::$l.
'\$dwoo\.parent'.
self::$r.
'/is', $matches[3], $override[2]);
return $l.
'block '.
$matches[1].
$matches[2].
$matches[1].
$r.
preg_replace('/'.
self::$l.
'\$dwoo\.parent'.
self::$r.
'/is', $matches[3], $override[2]).
$l.
'/block'.
$r;
if (self::$lastReplacement) {
Documentation generated on Sun, 07 Feb 2010 17:53:43 +0000 by phpDocumentor 1.4.0