public function __call($name, $args) { if (!is_function(array($this, $name))) { $s = 'return $this->bean->$name(' . implode(', ', $args) . ')'; eval($s); } }
/** * Parses a string and replaces :{%FUNCNAME(param1,param2,...)%} tags for the function result, * considering that FUNCNAME is the callable name of the function. * The call can have parameters without quotes. * Internally the 'call_user_func_array' function is used. * * @param string $content */ public static function parse($content) { preg_match_all("/\\:\\{\\%(.+)\\((.*)\\)\\%\\}/", $content, $matches); if (empty($matches) || count($matches) != 3) { return $content; } $functions = $matches[1]; $params = $matches[2]; if (empty($functions)) { return $content; } $filters = array(); $replacements = array(); foreach ($functions as $i => $func) { if (is_function($func)) { $filters[] = ":{%{$func}(" . $params[$i] . ")%}"; if (!empty($params[$i])) { $func_params = explode(",", $params[$i]); array_walk($func_params, "trim"); } else { $func_params = array(); } $replacements[] = call_user_func_array($func, $func_params); } } return str_replace($filters, $replacements, $content); }
/** * @param mixed $parameter * @param mixed &$variable may be function * @param int $data_type = PDO::PARAM_NONE * @param int $length = 0 mixed $driver_options ]]] ) * @param mixed $driver_options = null * @return bool */ public function bindParam($parameter, &$variable, $data_type = PDO::PARAM_STR, $length = 0, $driver_options = null) { // NB! параметер не используется для вывода значений. не придумал как и зачем это надо if ($parameter[0] != ':' && !is_int($parameter)) { $parameter = ':' . $parameter; } if (is_function($variable)) { $this->_bound_params[$parameter] = array('value' => $variable, 'type' => Pdo_Mongodb::PARAM_EXECUABLE); } else { $this->_bound_params[$parameter] = array('value' => &$variable, 'type' => $data_type); } return true; }
/** * Function map applies callback on values of array * * @return array */ public function map($callback, $array = null) { $temparray = $this->value; if (!is_function($callback)) { throw new \Exception('Invalid Parameter'); } if ($array != null && !is_array($array)) { throw new \Exception('Parameter 2 must be an array'); } else { $temparray = $array; } return $this->returnArray(array_map($callback, $temparray)); }