PHP Classes

File: test/test.php

Recommend this page to a friend!
  Classes of Nikos M.   Grammar Template   test/test.php   Download  
File: test/test.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Grammar Template
Template engine in PHP and other languages
Author: By
Last change:
Date: 3 years ago
Size: 1,074 bytes
 

Contents

Class file image Download
<?php
include "../src/php/GrammarTemplate.php";
function
echo_($s='')
{
    echo
$s . PHP_EOL;
}

echo_('GrammarTemplate.VERSION = ' . GrammarTemplate::VERSION);
echo_();

$tpl = "SELECT <column.select>[, <*column.select>]\nFROM <table.from>[, <*table.from>][\nWHERE (<?required.where>) AND (<?condition.where>)][\nWHERE <?required.where><?!condition.where>][\nWHERE <?!required.where><?condition.where>][\nGROUP BY <?group>[, <*group>]][\nHAVING (<?required.having>) AND (<?condition.having>)][\nHAVING <?required.having><?!condition.having>][\nHAVING <?!required.having><?condition.having>][\nORDER BY <?order>[, <*order>]][\nLIMIT <offset|0>, <?count>]";

$sql = new GrammarTemplate($tpl);

echo_("input template:");
echo_($tpl);

echo_( );

echo_("output:");
echo_($sql->render(array(
   
'column' => array( 'select' => array( 'field1', 'field2', 'field3', 'field4' ) ),
   
'table' => array( 'from' => array( 'tbl1', 'tbl2' ) ),
   
'condition' => array( 'where' => 'field1=1 AND field2=2', 'having' => 'field3=1 OR field4=2' ),
   
'count' => 5
)));