Changeset 2604
- Timestamp:
- 12/06/07 13:17:29 (5 years ago)
- Files:
-
- 1 modified
-
lang/php/mumu/trunk/mumu.php (modified) (25 diffs)
Legend:
- Unmodified
- Added
- Removed
-
lang/php/mumu/trunk/mumu.php
r2603 r2604 206 206 } 207 207 208 class MuNode { 209 public function _render() { 210 return ''; 211 } 208 interface MuNode { 209 public function _render($context); 212 210 } 213 211 … … 229 227 } 230 228 231 class MuErrorNode extends MuNode {229 class MuErrorNode implements MuNode { 232 230 private $errorMsg; 233 231 private $filename; … … 278 276 279 277 // 1�ĤΥƥ�졼�Ȥ������������ 280 class MuFile extends MuNode {278 class MuFile implements MuNode { 281 279 public $nodelist; // �ե������ѡ�������NodeList 282 private $block_dict; // nodelist�������ock̾ => MuBlockNode(�λ��� 283 private $parent_tfile; // extends���������ƥƥ�졼�� function __construct($nodelist, $block_dict, $parentPath = null, $path = null) { 280 private $block_dict; // nodelist�������ock̾ => MuBlockNode(�λ��� 281 public $include_paths; // include�����ե��������ʥ�����������ǻȤ��� public $path; // ��ʬ�Υե����� 282 private $parent_path; // extends�Υե����� 283 private $parent_tfile; // extends���������ƥƥ�졼�� function __construct($nodelist, $block_dict, $include_paths, 284 $path = null, $parent_path = null) { 284 285 $this->nodelist = $nodelist; 285 286 $this->block_dict = $block_dict; 286 if ($parentPath && $path) { 287 if (($epath = MuUtil::getpath($path, $parentPath)) === false 288 || ($this->parent_tfile = MuParser::parse_from_file($epath)) === false) { 287 $this->include_paths = $include_paths; 288 $this->path = $path; 289 if ($parent_path && $path) { 290 if (($this->parent_path = MuUtil::getpath($path, $parent_path)) === false 291 || ($this->parent_tfile = MuParser::parse_from_file($this->parent_path)) === false) { 289 292 throw new MuParserException('invalid filename specified on extends'); 290 293 } … … 327 330 } 328 331 public function is_child() { 329 return ($parent_tfile !== false); 330 } 331 } 332 333 class MuTextNode extends MuNode { 332 return (isset($this->parent_tfile)); 333 } 334 // extends��clude���Ƥ��������뤬��������������Ȥ˹����������뤫 335 public function check_cache_mtime($cache_mtime) { 336 foreach ($this->include_paths as $inc_path) { 337 if ($cache_mtime < filemtime($inc_path)) { 338 return false; 339 } 340 } 341 if (isset($this->parent_path)) { 342 if ($cache_mtime < filemtime($this->parent_path)) { 343 return false; 344 } 345 // check parent 346 return $this->parent_tfile->check_cache_mtime($cache_mtime); 347 } 348 return true; 349 } 350 } 351 352 class MuTextNode implements MuNode { 334 353 private $text; 335 354 function __construct($text) { … … 341 360 } 342 361 343 class MuVariableNode extends MuNode {362 class MuVariableNode implements MuNode { 344 363 private $filter_expression; 345 364 function __construct($filter_expression) { … … 356 375 } 357 376 358 class MuIncludeNode extends MuNode {377 class MuIncludeNode implements MuNode { 359 378 private $tplfile; 360 function __construct($include Path, $path) {361 if (($epath = MuUtil::getpath($path, $include Path)) === false379 function __construct($include_path, $path) { 380 if (($epath = MuUtil::getpath($path, $include_path)) === false 362 381 || ($this->tplfile = MuParser::parse_from_file($epath)) === false) { 363 382 throw new MuParserException('include filename is invalid'); … … 367 386 return $this->tplfile->_render($context); 368 387 } 369 } 370 371 class MuBlockNode extends MuNode { 388 public function get_tplfile() { 389 return $this->tplfile; 390 } 391 } 392 393 class MuBlockNode implements MuNode { 372 394 public $name; 373 395 public $nodelist; … … 404 426 } 405 427 406 class MuCycleNode extends MuNode {428 class MuCycleNode implements MuNode { 407 429 private $cyclevars; 408 430 private $cyclevars_len; … … 426 448 } 427 449 428 class MuDebugNode extends MuNode {450 class MuDebugNode implements MuNode { 429 451 function _render($context) { 430 452 ob_start(); … … 445 467 } 446 468 447 class MuFilterNode extends MuNode {469 class MuFilterNode implements MuNode { 448 470 private $filter_expr; 449 471 private $nodelist; … … 465 487 } 466 488 467 class MuForNode extends MuNode {489 class MuForNode implements MuNode { 468 490 private $loopvar; 469 491 private $sequence; … … 513 535 } 514 536 515 class MuIfNode extends MuNode {537 class MuIfNode implements MuNode { 516 538 private $bool_exprs; 517 539 private $nodelist_true; … … 559 581 } 560 582 561 class MuIfEqualNode extends MuNode {583 class MuIfEqualNode implements MuNode { 562 584 private $var1; 563 585 private $var2; … … 589 611 } 590 612 591 class MuSpacelessNode extends MuNode {613 class MuSpacelessNode implements MuNode { 592 614 private $nodelist; 593 615 function __construct($nodelist) { … … 599 621 } 600 622 601 class MuTemplateTagNode extends MuNode {623 class MuTemplateTagNode implements MuNode { 602 624 private $tagtype; 603 625 // TODO: php5 don't support array as const... … … 620 642 } 621 643 622 class MuWidthRatioNode extends MuNode {644 class MuWidthRatioNode implements MuNode { 623 645 private $val_expr; 624 646 private $max_expr; … … 643 665 } 644 666 645 class MuNowNode extends MuNode {667 class MuNowNode implements MuNode { 646 668 private $format_string; 647 669 function __construct($format_string) { … … 653 675 } 654 676 655 class MuFirstOfNode extends MuNode {677 class MuFirstOfNode implements MuNode { 656 678 private $vars; 657 679 function __construct($vars) { … … 974 996 975 997 class MuParser { 976 private $template; // �ѡ�����Υƥ�졼����� private $template_len; // �ƥ�졼�����Ĺ�� 977 private $template_path; // �ƥ�졼�ȤΥѥ�(����) 978 private $block_dict = array(); // block���� => block�ؤλ��� private $extends = false; // extends�ξ��Υե����� 979 private $spos = 0; // ���ߥѡ�����ΰ�� 998 private $template; // �ѡ�����Υƥ�졼����� private $template_len; // �ƥ�졼�����Ĺ�� 999 private $template_path; // �ƥ�졼�ȤΥѥ�(����) 1000 private $serialize_path; // �ѡ����ѤߤΥƥ�졼�Ȥꥢ�饤����������ݴ�ath 1001 private $block_dict = array(); // block���� => block�ؤλ��� private $extends; // extends�Υե����� 1002 private $include_paths = array(); // include���Ƥ����������ΰ� 1003 private $spos = 0; // ���ߥѡ�����ΰ�� 980 1004 # template syntax constants 981 1005 const FILTER_SEPARATOR = '|'; … … 992 1016 // FIXME: ����������Ǥ������ѡ�����������äƤޤ� 993 1017 994 function __construct($template, $template_path = null ) {1018 function __construct($template, $template_path = null, $serialize_path = null) { 995 1019 $this->template = $template; 996 1020 $this->template_len = strlen($template); 997 1021 $this->template_path = $template_path; 1022 $this->serialize_path = $serialize_path; 998 1023 } 999 1024 … … 1134 1159 switch ($in[0]) { 1135 1160 // TODO: ������å���� case 'extends': 1136 if ( $this->extends !== false) {1161 if (isset($this->extends)) { 1137 1162 return $this->make_errornode('multiple_extends_tag'); 1138 1163 } … … 1157 1182 $this->spos = $lpos + 2; 1158 1183 $node = new MuIncludeNode($param[1], $this->template_path); 1184 $tplfile = $node->get_tplfile(); 1185 $this->include_paths[] = $tplfile->path; 1186 unset($tplfile->path); 1187 // ���롼�ɤΥ��롼��褬�������줿�饭���������� 1188 if (isset($tplfile->include_paths)) { 1189 $this->include_paths = array_merge($this->include_paths, $tplfile->include_paths); 1190 unset($tplfile->include_paths); 1191 } 1159 1192 break; 1160 1193 case 'block': // endblock … … 1361 1394 } 1362 1395 1363 static public function parse_from_file($template_path, $serialize_path = null) { 1364 if (($t = file_get_contents($template_path)) === false) { 1365 return false; 1366 } 1367 // check cache 1368 $cachePath = $template_path.'.cache'; 1369 if ($useSerialize && 1370 file_exists($cachePath) && 1371 filemtime($template_path) <= filemtime($cachePath)) { 1372 $mf = MuUtil::unserialize_from_file($cachePath); 1373 } else { 1374 $p = new MuParser($t, $template_path); 1396 static public function parse_from_file($template_path, $serialize_store = null) { 1397 // ������������å� 1398 if (isset($serialize_store)) { 1399 if (stristr($serialize_store, 'file://') == 0) { 1400 // TODO: check whether absolute path or not 1401 if (($spath = realpath(substr($serialize_store, 7))) === false) { 1402 return false; 1403 } 1404 $sfpath = $spath . '/' . basename($template_path) . '.cache'; 1405 if (file_exists($sfpath)) { 1406 if (($sfmtime = filemtime($sfpath)) === false) { 1407 return false; 1408 } 1409 if (filemtime($template_path) <= $sfmtime) { 1410 $mf = MuUtil::unserialize_from_file($sfpath); 1411 if (!$mf->check_cache_mtime($sfmtime)) { 1412 unset($mf); 1413 } 1414 } 1415 } 1416 } else { 1417 // TODO: now file cache only 1418 return false; 1419 } 1420 } 1421 if (!isset($mf)) { 1422 if (($t = file_get_contents($template_path)) === false) { 1423 return false; 1424 } 1425 $p = new MuParser($t, $template_path, $serialize_path); 1375 1426 try { 1376 1427 list($nl) = $p->_parse(array()); … … 1379 1430 $nl->push($p->make_errornode($e->getMessage())); 1380 1431 } 1381 $mf = new MuFile($nl, $p->block_dict, $p->extends, $template_path); 1382 MuUtil::serialize_to_file($mf, $cachePath); 1432 $mf = new MuFile($nl, $p->block_dict, $p->include_paths, $template_path, $p->extends); 1433 if (isset($sfpath)) { 1434 MuUtil::serialize_to_file($mf, $sfpath); 1435 } 1383 1436 } 1384 1437 return $mf; … … 1393 1446 $nl->push($p->make_errornode($e->getMessage())); 1394 1447 } 1395 return new MuFile($nl, $p->block_dict );1448 return new MuFile($nl, $p->block_dict, $p->include_paths); 1396 1449 } 1397 1450
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)