1<?php 2 3namespace dokuwiki\plugin\structcondstyle\meta; 4 5/** 6 * Class Operator 7 * 8 * Describes a boolean operator used to evaluate conditions 9 * 10 * @package dokuwiki\plugin\structcondstyle\meta 11 */ 12class Operator 13{ 14 private $reg; 15 private $eval_func; 16 17 function __construct($reg, $eval_func) 18 { 19 $this->reg = $reg; 20 $this->eval_func = $eval_func; 21 } 22 23 function getReg(){ 24 return $this->reg; 25 } 26 27 function evaluate($lhs, $rhs){ 28 // Evaluate the operator 29 $eval = $this->eval_func; 30 return $eval($lhs,$rhs); 31 } 32} 33 34class NumericOperator extends Operator 35{ 36 37 private function make_numeric($value){ 38 if(is_numeric($value)) 39 return floatval($value); 40 if(is_string($value)){ 41 if($value == "now") 42 return time(); 43 else 44 return strtotime($value); 45 46 } 47 else 48 return FALSE; 49 } 50 51 function evaluate($lhs, $rhs) 52 { 53 // First convert both sides to their numerical values 54 $lvalue = $this->make_numeric($lhs); 55 $rvalue = $this->make_numeric($rhs); 56 57 // If value could not be parsed, return false 58 if($lvalue === FALSE or $rvalue === FALSE) 59 return false; 60 61 // otherwise simply return the super function 62 return parent::evaluate($lvalue, $rvalue); 63 } 64 65} 66 67?>