Exemple #1
0
    /**
    * EXPERIMENTAL: Will allow to create finders when PHP includes aggregate_methods as a stable feature on PHP4, for PHP5 we might use __call
    *
    * @access private
    */
    function _buildFinders($finderFunctions = array('find','findFirst'))
    {
        if(!$this->_dynamicMethods){
            return;
        }
        $columns = !is_array($this->_dynamicMethods) ? array_keys($this->getColumns()) : $this->_dynamicMethods;
        $class_name = 'ak_'.md5(serialize($columns));
        if(!class_exists($class_name)){
            $permutations = Ak::permute($columns);
            $implementations = '';
            foreach ($finderFunctions as $finderFunction){
                foreach ($permutations as $permutation){
                    $permutation = array_map(array('AkInflector','camelize'),$permutation);
                    foreach ($permutation as $k=>$v){
                        $method_name = $finderFunction.'By'.join($permutation,'And');
                        $implementation = 'function &'.$method_name.'(';
                        $first_param = '';
                        $params = '';
                        $i = 1;
                        foreach ($permutation as $column){
                            $column = AkInflector::underscore($column);
                            $params .= "$$column, ";
                            $first_param .= "$column ";
                            $i++;
                        }
                        $implementation .= trim($params,' ,')."){\n";
                        $implementation .= '$options = func_num_args() == '.$i.' ? func_get_arg('.($i-1).') : array();'."\n";
                        $implementation .= 'return $this->'.$finderFunction.'By(\''.$first_param.'\', '.trim($params,' ,').", \$options);\n }\n";
                        $implementations[$method_name] = $implementation;
                        array_shift($permutation);
                    }
                }
            }
            eval('class '.$class_name.' { '.join("\n",$implementations).' } ');
        }

        aggregate_methods(&$this, $class_name);
    }
function &usr_reg_get_full($id)
{
    if ($r = db_sab('SELECT * FROM phpgw_fud_users WHERE id=' . $id)) {
        if (!function_exists('aggregate_methods')) {
            $o = new fud_user_reg();
            foreach ($r as $k => $v) {
                $o->{$k} = $v;
            }
            $r = $o;
        } else {
            aggregate_methods($r, 'fud_user_reg');
        }
    }
    return $r;
}
/**
 *	This function is used for method aggregation will work in PHP4 and PHP5
 *
 *	@param object object
 *	@param string class_name 
 */
function my_aggregate_methods(&$object, $class_name)
{
    if (function_exists('aggregate_methods')) {
        return aggregate_methods($object, $class_name);
    }
    if (function_exists('runkit_class_adopt')) {
        return @runkit_class_adopt(get_class($object), $class_name);
    }
    if (function_exists('classkit_aggregate_methods')) {
        return @classkit_aggregate_methods(get_class($object), $class_name);
    }
    die("Function aggregate_methods() doesn't exists. This is probably because " . "PHP 5 or later is running on this server. Try install Runkit or " . "Classkit extension from PECL repository (http://pecl.php.net). " . "Useing classkit is safe with " . "PHP 5.0, but does not work with later versions of PHP. Useing runkit " . "is experimental. Type 'pecl install -f runkit' on your command line " . "for install the extension. And do not forget enable the extension in " . "your php.ini file.");
}