Invokes an aggregate function
@param \eMapper\SQL\Aggregate\SQLFunction $function
@throws \InvalidArgumentException
@return mixed
4776
protected function sqlFunction(SQLFunction $function) {
		//connect to database
		$this->mapper->connect();
	
		//build query
		$query = $this->mapper->newQuery($this->entityProfile)
		->from($this->entityProfile->getEntityTable(), Schema::DEFAULT_ALIAS)
		->select($function->getFunctionInstance());
	
		//set query condition
		if ($this->hasOption('query.filter'))
			$query->where($this->getFilter());
	
		list($sql, $args) = $query->build();
		return $this->mapper->merge($this->clean(['map.type' => $function->getDefaultType()]))->execute($sql, $args);
	}
979905
public function each(\Closure $function, array $args = [])
    {
        $content = $this->getArrayCopy();
        
        return new static(
            \array_combine(
                \array_keys($content),
                \array_map(
                    function ($value) use ($function, $args) {
                        return $this->callFunction($function, $value, $args);
                    },
                    \array_values($content)
                )
            )
        );
    }
875505
public function transactional(callable $func)
    {
        if (!\is_callable($func)) {
            throw new \InvalidArgumentException('Expected argument of type "callable", got "' . \gettype($func) . '"');
        }

        $this->connect();
        $this->pdo->beginTransaction();

        try {
            $return = $func($this);
            $this->pdo->commit();

            return $return ?: true;
        } catch (\Throwable $e) {
            $this->pdo->rollBack();
            throw $e;
        }
    }
1149117
private static function callWithComparator($function, $args)
    {
        $comparator = null;
        if (end($args) instanceof Comparator) {
            $comparator = array_pop($args);
        }
        $callback = [ (new SetTool())->setComparator($comparator), $function ];
        return call_user_func_array($callback, $args);
    }
63517
public function addFunction(TemplateFunction $function)
    {
        $functionName = $function->getFunctionName();
        if (isset($this->functions[ $functionName ])) {
            $extension = $this->functions[ $functionName ]->getExtension()->getExtensionName();
            $message   = "Function {$functionName} is already registered";
            if ($extension) {
                $message .= " in extension '{$extension}'";
            }
            throw new \InvalidArgumentException($message);
        }
        $this->functions[ $functionName ] = $function;
    }
459220
public function apply(DataQuery $query)
    {
        if ($this->aggregate) {
            throw new InvalidArgumentException(sprintf(
                'Aggregate functions can only be used with comparison filters. See %s',
                $this->fullName
            ));
        }

        return parent::apply($query);
    }
595886
public static function reflectionFunction($function, $arguments = []) {
        $method = is_array($function);

        if($method) {
            $reflection = new ReflectionMethod($function[0], $function[1]);
        }
        else {
            $reflection = new ReflectionFunction($function);
        }

        $args = self::getReflectionArgs($reflection, $arguments, $missing);

        if($missing) {
            $name = $reflection->getName();
            $parts = [];
            foreach($missing as $key => $name) {
                $parts[] = "'$name' (or '$key')";
            }
            $missing = implode(", ", $parts);
            throw new Exception("Can not call function '$name'. Argument(s) $missing need to be set.");
        }

        return $method ? $reflection->invokeArgs($function[0], $args) : $reflection->invokeArgs($args);
    }
1194452
public function setHashFunction($hashFunction)
    {
        $hashFunction = strtolower($hashFunction);
        if (!in_array($hashFunction, hash_algos())) {
            throw new \InvalidArgumentException("$hashFunction is not a supported hash function");
        }
        $this->hashFunction = $hashFunction;

        return $this;
    }
98373
private function _prepareColumnArgument($column)
	{
		if(!is_string($column) && !$column instanceof SqlFunctionInterface)
		{
			throw new \InvalidArgumentException('Argument 1 passed is not the expected type!');
		}
		if($column instanceof SqlFunctionInterface || $column === '*')
		{
			$this->columnName = (string)htmlentities($column, ENT_QUOTES);
		}
		else
		{
			$this->columnName = '`' . htmlentities($column, ENT_QUOTES) . '`';
		}
	}
961552
public static function run($function=null,$callback=null) {
        $that = self::instance();

        if($function instanceof \Closure) {
            $callback = $function;
            $function = Router::driver()->function;
        }

        $that->on($that->defaultCall,$callback);

        return $that->with($function);
    }
298050
public function inTransaction(callable $function)
    {
        if (!is_callable($function)) {
            throw new InvalidArgumentException('$function must be callable.');
        }
        $this->beginTransaction();
        try {
            if (func_num_args() === 1) {
                $returnValue = $function($this);
            } else {
                $args    = func_get_args();
                $args[0] = $this;
                $returnValue = call_user_func_array($function, $args);
            }
            $this->commit();
            return $returnValue;
        } catch (\PDOException $e) {
            $this->rollBack();
            throw $e;
        }
    }
876092
public static function createCustomFunction(
        string $function,
        float $weight = self::DEFAULT_WEIGHT,
        Filter $filter = null,
        string $scoreMode = self::SCORE_MODE_AVG
    ): ScoreStrategy {
        $scoreStrategy = self::createDefault();
        $scoreStrategy->type = self::CUSTOM_FUNCTION;
        $scoreStrategy->configuration['function'] = $function;
        $scoreStrategy->weight = $weight;
        $scoreStrategy->filter = self::fixFilterFieldPath($filter);
        $scoreStrategy->scoreMode = $scoreMode;

        return $scoreStrategy;
    }
299010
static function iterate($func)
	{
		$db = \App::get('db');

		$query = "SELECT cn FROM `#__xgroups`;";

		$db->setQuery($query);

		$result = $db->loadColumn();

		if ($result === false)
		{
			return false;
		}

		foreach ($result as $row)
		{
			call_user_func($func, $row);
		}

		return true;
	}
538743
public function invokeFunction($function, $vars = [])
    {
        $reflect = new \ReflectionFunction($function);
        $args = $this->bindParams($reflect, $vars);
        return $reflect->invokeArgs($args);
    }
646157
public function canHandle($type, JSONFunction $function, $instance = null)
    {
        if (isset($this->alias[$type])) {
            $canHandle = false;
            foreach ($this->alias[$type] as $target) {
                $canHandle = $canHandle || $this->canHandle($target, $function, $instance);
            }
            return $canHandle;
        }



        $name = $function->getName();

        if (!$this->hasFunction($type, $name)) {
            return false;
        }

        $instance = $instance == null ? $this->object : $instance;

        $args = $function->getArgs();
        /** @var \ReflectionParameter[] $parameters */
        $parameters = null;
        $this->callPreCallFunctions($type, $instance, $name, $args);

        if (isset($this->customFunctions[$type][$name])) {
            $parameters = (new \ReflectionFunction($this->customFunctions[$type][$name]))->getParameters();
            $args = array_merge([$instance], $args);
        } else if ($instance != null && isset($this->functions[$type]) && in_array($name, $this->functions[$type])) {
            $parameters = (new \ReflectionMethod($instance, $name))->getParameters();
        }
        if ($parameters === null) {
            return false;
        }

        return $this->parametersCheck($args, $parameters);
    }
6876
public function aggregate( $function, $columns = ['*'] )
	{
		// Postgres doesn't like ORDER BY when there's no GROUP BY clause
		if ( !isset( $this->groups ) )
			$this->reOrderBy( null );

		$this->aggregate = compact( 'function', 'columns' );

		$previousColumns = $this->columns;

		// We will also back up the select bindings since the select clause will be
		// removed when performing the aggregate function. Once the query is run
		// we will add the bindings back onto this query so they can get used.
		$previousSelectBindings = $this->bindings['select'];

		$this->bindings['select'] = [];

		$results = $this->get( $columns );

		// Once we have executed the query, we will reset the aggregate property so
		// that more select queries can be executed against the database without
		// the aggregate value getting in the way when the grammar builds it.
		$this->aggregate = null;

		$this->columns = $previousColumns;

		$this->bindings['select'] = $previousSelectBindings;

		if ( isset( $results[0] ) )
		{
			$result = array_change_key_case( (array) $results[0] );

			return $result['aggregate'];
		}

		return null;
	}
739008
public function addFunction($function) {
		$arguments = func_get_args();
		// Remove the first argument
		array_shift($arguments);
	
		$content = new HtmlFromFunction();
		$content->functionPointer = $function;
		$content->parameters = $arguments;
		$this->children[] = $content;
		return $this;
	}