OSDN Git Service

初回コミット(v2.6.17.1)
[magic3/magic3.git] / include / lib / patTemplate / patTemplate / Modifier / Expression.php
1 <?PHP
2 /**
3  * patTemplate modfifier Expression
4  *
5  * $Id: Expression.php 440 2008-03-30 09:00:16Z fishbone $
6  *
7  * @package             patTemplate
8  * @subpackage  Modifiers
9  * @author              Stephan Schmidt <schst@php.net>
10  */
11
12 /**
13  * patTemplate modfifier Expression
14  *
15  * Evaluates an expression and returns one of
16  * the defined values for true and false.
17  *
18  * Possible attributes are:
19  * - expression (string)
20  * - true (string)
21  * - false (string)
22  *
23  * @package             patTemplate
24  * @subpackage  Modifiers
25  * @author              Stephan Schmidt <schst@php.net>
26  * @link                http://www.php.net/manual/en/function.wordwrap.php
27  */
28 class patTemplate_Modifier_Expression extends patTemplate_Modifier
29 {
30    /**
31         * modify the value
32         *
33         * @access       public
34         * @param        string          value
35         * @return       string          modified value
36         */
37         function modify( $value, $params = array() )
38         {
39                 /*
40                  * true and false
41                  */
42                 if( !isset( $params['true'] ) )
43                         $params['true'] =       'true';
44                 if( !isset( $params['false'] ) )
45                         $params['false']=       'false';
46
47         /*
48          * replace the value in the expression
49          */
50         $params['expression'] = str_replace( '$self', "'$value'", $params['expression'] );
51
52         @eval( '$result = '.$params['expression'].';' );
53         
54         if ($result === true) {
55             return str_replace( '$self', $value, $params['true'] );
56         }
57         return str_replace( '$self', $value, $params['false'] );
58         }
59 }
60 ?>