summaryrefslogtreecommitdiff
path: root/lib/phptal/PHPTAL/Tales.php
blob: 571e85e9e80465126befae535aa0a8e52e529a8d (plain)
1
2
3
4
5
6
7
8
9
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
<?php
/**
 * PHPTAL templating engine
 *
 * PHP Version 5
 *
 * @category HTML
 * @package  PHPTAL
 * @author   Laurent Bedubourg <lbedubourg@motion-twin.com>
 * @author   Kornel Lesiński <kornel@aardvarkmedia.co.uk>
 * @license  http://www.gnu.org/licenses/lgpl.html GNU Lesser General Public License
 * @version  SVN: $Id$
 * @link     http://phptal.org/
 */


/**
 * You can implement this interface to create custom tales modifiers
 *
 * Methods suitable for modifiers must be static.
 *
 * @package PHPTAL
 * @subpackage Php
 */
interface PHPTAL_Tales
{
}


/**
 * translates TALES expression with alternatives into single PHP expression.
 * Identical to phptal_tales() for singular expressions.
 *
 * Please use this function rather than PHPTAL_Php_TalesInternal methods.
 *
 * @see PHPTAL_Php_TalesInternal::compileToPHPExpressions()
 * @return string
 */
function phptal_tale($expression, $nothrow=false)
{
    return PHPTAL_Php_TalesInternal::compileToPHPExpression($expression, $nothrow);
}

/**
 * returns PHP code that will evaluate given TALES expression.
 * e.g. "string:foo${bar}" may be transformed to "'foo'.phptal_escape($ctx->bar)"
 *
 * Expressions with alternatives ("foo | bar") will cause it to return array
 * Use phptal_tale() if you always want string.
 *
 * @param bool $nothrow if true, invalid expression will return NULL (at run time) rather than throwing exception
 * @return string or array
 */
function phptal_tales($expression, $nothrow=false)
{
    return PHPTAL_Php_TalesInternal::compileToPHPExpressions($expression, $nothrow);
}