- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
class/View.php
<?php
class View {
...
public function compile() {
$view_src = file_get_contents(VIEW_SRC_PATH . $this->full_name . EXT);
// echo
$view_src = preg_replace("/\{\{(\w+)\}\}/", "<?php echo \$$1; ?>", $view_src);
$view_src = preg_replace("/\{\{(\w+)\|(\w+)\}\}/", "<?php echo \$$1['$2']; ?>", $view_src);
$view_src = preg_replace("/\{\{(\w+)\.(\w+)\}\}/", "<?php echo \$$1->$2; ?>", $view_src);
// foreach
$view_src = preg_replace("/<!--each\s+(\w+)\s+in\s+(\w+)-->/", "<?php foreach(\$$2 as \$$1): ?>", $view_src);
$view_src = preg_replace("/<!--each\s+(\w+)\s+in\s+(\w+)\|(\w+)-->/", "<?php foreach(\$$2['$3'] as \$$1): ?>", $view_src);
$view_src = preg_replace("/<!--each\s+(\w+)\s+in\s+(\w+)\.(\w+)-->/", "<?php foreach(\$$2->$3 as \$$1): ?>", $view_src);
$view_src = preg_replace("/<!--each\s+(\w+)\s+(\w+)\s+in\s+(\w+)\.(\w+)-->/", "<?php foreach(\$$3->$4 as \$$1 => \$$2): ?>", $view_src);
$view_src = preg_replace("/<!--each\s+(\w+)\s+(\w+)\s+in\s+(\w+)-->/", "<?php foreach(\$$3 as \$$1 => \$$2): ?>", $view_src);
$view_src = preg_replace("/<!--each-->/", "<?php endforeach; ?>", $view_src);
// switch
$view_src = preg_replace("/<!--select\s+(\w+)\.(\w+)-->\s*<!--when\s+(.+)-->/", "<?php switch(\$$1->$2): case $3: ?>", $view_src);
$view_src = preg_replace("/<!--when\s+(.+)-->/", "<?php break; ?><?php case $1: ?>", $view_src);
$view_src = preg_replace("/<!--otherwise-->/", "<?php break; ?><?php default: ?>", $view_src);
$view_src = preg_replace("/<!--select-->/", "<?php endswitch; ?>", $view_src);
if (!file_exists(VIEW_PATH . $this->path)) mkdir(VIEW_PATH . $this->path, 0777, true);
$fp = fopen(VIEW_PATH . $this->full_name . EXT, 'w');
fwrite($fp, $view_src);
fclose($fp);
}
...
?>
view-src/ShadeType.php
{{type.name}}
<!--each k d in type.diameters-->
<h1>{{k}}</h1>
<!--each s in d-->
<div>
{{s.bottom}} × {{s.top}} × {{s.height}}
<div>
<!--select s.mode-->
<!--when 'u'-->(на ушках)
<!--when 'p'-->(только подвес)
<!--otherwise-->
<!--select-->
</div>
</div>
<!--each-->
<!--each-->
view/ShadeType.php
<?php echo $type->name; ?>
<?php foreach($type->diameters as $k => $d): ?>
<h1><?php echo $k; ?></h1>
<?php foreach($d as $s): ?>
<div>
<?php echo $s->bottom; ?> × <?php echo $s->top; ?> × <?php echo $s->height; ?>
<div>
<?php switch($s->mode): case 'u': ?>(на ушках)
<?php break; ?><?php case 'p': ?>(только подвес)
<?php break; ?><?php default: ?>
<?php endswitch; ?>
</div>
</div>
<?php endforeach; ?>
<?php endforeach; ?>
На хостинге PHP 5.2, а старые версии фреймворков не хочется. Решил запилить свой.