Run a function and autoescape returned content if autoescape is turned on

@param  string $function Callback name
@return mixed
484107
private function doRun($function)
    {
        $raw = $this->execute($function, $this->functions, array_slice(func_get_args(), 1));
        if (
            ($this->autoescape && ! in_array($function, $this->safe, true))
            && (is_array($raw) || is_string($raw) || (is_object($raw) && ! $raw instanceof Extension))
        ) {
            $raw = $this->escaper->escape($raw);
            if (is_object($raw)) {
                $raw = '';
            }
        }

        return is_null($raw) ? '' : $raw;
    }
1319404
protected function getRaw($key, $function = null)
    {
        if (!$this->isString($key)) {
            /* If $key is not valid string throws InvalidArgumentException */
            throw new InvalidArgumentException('Cache key must be not empty string');
        }

        $item = $this->getCachedItem($key);

        if ($item && !$this->isExpired($item)) {
            return !is_null($function) ? $function($item->get()) : $item->get();
        }
    }
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);
    }
935631
protected function logDeprecated($function = null)
    {
        return;
        $message = '[DEPRECATED]  Deprecated call ';
        if (!is_null($function)) {
            $message .= 'of "' . $function . '"';
        }
        $message .= ' (' . get_called_class() .')';
        \common_Logger::i($message);
    }
170571
private function run(\Closure &$runFunc)
    {
        $__out = new Outer($this->sdopx);
        $_sdopx = $this->sdopx;
        try {
            call_user_func($runFunc, $_sdopx, $__out);
        } catch (\ErrorException $exception) {
            $__out->throw($exception);
        }
        return $__out->getCode();
    }
996219
public function callback($function, $params = null)
    {
        $callback = new Callback($function, $params);
        $this->register($callback);

        return $callback;
    }
668513
public function executeFunction($string)
    {
        preg_match_all('/(.*)\((.*)\)/', $string, $matches);

        if (count($matches) > 0 && is_array($matches[0]) && count($matches[0]) > 0) {
            $function = $matches[1][0];

            return $function($this->removeQuotes($matches[2][0]));
        }

        return Constants::NOT_RESOLVED;
    }
831344
private function runIfNotCached($variableName, callable $function)
    {
        if (null === $this->{$variableName}) {
            // Only assign that don't returns
            if (null !== $result = $function()) {
                $this->{$variableName} = $result;
            }
        }
    }
1306728
public function execute(callable $function, array $arguments = [])
    {
        $delayFunction = $this->delayFunction;
        $retryAttempt = 0;

        $continue = true;
        do {
            try {
                $res = call_user_func_array($function, $arguments);
                $continue = false;
                return $res;
            } catch (\Exception $exception) {
                if ($this->retryFunction) {
                    if (!call_user_func($this->retryFunction, $exception)) {
                        throw $exception;
                    }
                }

                if ($retryAttempt < $this->retries) {
                    $delay = $delayFunction($exception);
                    $delay += [
                        'seconds' => 0,
                        'nanos' => 0
                    ];

                    time_nanosleep($delay['seconds'], $delay['nanos']);

                    $retryAttempt++;
                } else {
                    $continue = false;
                    throw $exception;
                }
            }
        } while ($continue);
    }
982334
static function runTrigger( $name, $moduleName, $function, $parameters, $keys = null )
    {
        $trigger = eZPersistentObject::fetchObject( eZTrigger::definition(),
                                                    null,
                                                    array( 'name' => $name,
                                                           'module_name' => $moduleName,
                                                           'function_name' => $function ),
                                                    true );
        if ( $trigger !== NULL )
        {
            $workflowID = $trigger->attribute( 'workflow_id' );
            $workflow = eZWorkflow::fetch( $workflowID );
            if ( $keys != null )
            {
                $keys[] = 'workflow_id';
            }

            $parameters['workflow_id']     = $workflowID;
            $parameters['trigger_name']    = $name;
            $parameters['module_name']     = $moduleName;
            $parameters['module_function'] = $function;
            // It is very important that the user_id is set correctly.
            // If it was not supplied by the calling code we will use
            // the currently logged in user.
            if ( !isset( $parameters['user_id'] ) or
                 $parameters['user_id'] == 0 )
            {
                $user = eZUser::currentUser();
                $parameters['user_id'] = $user->attribute( 'contentobject_id' );
            }
            $processKey = eZWorkflowProcess::createKey( $parameters, $keys );

//            $searchKey = eZWorkflowProcess::createKey( $keyArray );

            $workflowProcessList = eZWorkflowProcess::fetchListByKey( $processKey );

            if ( count( $workflowProcessList ) > 0 )
            {
                $existingWorkflowProcess = $workflowProcessList[0];
                $existingWorkflowStatus = $existingWorkflowProcess->attribute( 'status' );


                switch( $existingWorkflowStatus )
                {
                    case eZWorkflow::STATUS_FAILED:
                    case eZWorkflow::STATUS_CANCELLED:
                    case eZWorkflow::STATUS_NONE:
                    case eZWorkflow::STATUS_BUSY:
                    {
                        $existingWorkflowProcess->removeThis();
                        return array( 'Status' => eZTrigger::WORKFLOW_CANCELLED,
                                      'Result' => null );
                    } break;
                    case eZWorkflow::STATUS_FETCH_TEMPLATE:
                    case eZWorkflow::STATUS_FETCH_TEMPLATE_REPEAT:
                    case eZWorkflow::STATUS_REDIRECT:
                    case eZWorkflow::STATUS_RESET:
                    {
                        return eZTrigger::runWorkflow( $existingWorkflowProcess );
//                        return eZTrigger::FETCH_TEMPLATE;
                    } break;
                    case eZWorkflow::STATUS_DEFERRED_TO_CRON:
                    {
                        return eZTrigger::runWorkflow( $existingWorkflowProcess );
/*                        return array( 'Status' => eZTrigger::STATUS_CRON_JOB,

                                      'Result' => array( 'content' => 'Operation halted during execution.<br/>Refresh page to continue<br/><br/><b>Note: The halt is just a temporary test</b><br/>',
                                                         'path' => array( array( 'text' => 'Operation halt',
                                                                            'url' => false ) ) ) );
*/                  } break;
                    case eZWorkflow::STATUS_DONE:
                    {
                        $existingWorkflowProcess->removeThis();
                        return array( 'Status' => eZTrigger::WORKFLOW_DONE,
                                      'Result' => null );
                    }
                }
                return array( 'Status' => eZTrigger::WORKFLOW_CANCELLED,
                              'Result' => null );
            }else
            {
//                print( "\n starting new workflow process \n");
//                var_dump( $keyArray );
//                print( " $workflowID, $userID, $objectID, $version, $nodeID, \n ");
            }
            $workflowProcess = eZWorkflowProcess::create( $processKey, $parameters );

            $workflowProcess->store();

            return eZTrigger::runWorkflow( $workflowProcess );

        }
        else
        {
            return array( 'Status' => eZTrigger::NO_CONNECTED_WORKFLOWS,
                          'Result' => null );
        }
    }
440011
protected function _canExecuteFunction($view, $function)
    {
        $canExecute = true;
        if (method_exists($view, $function)) {
            $reflectionMethod = new ReflectionMethod($view, $function);
            if (!$reflectionMethod->isPublic()) {
                $canExecute = false;
            }
        }

        return $canExecute;
    }
217753
public function cacheFun($function) {
        if ($this->getConfig('debug') && !is_callable($function))
            echo "no valid function";

        $r = new ReflectionFunction($function);
        $id = null;

        foreach ($r->getStaticVariables() as $key => $var) {
            if ($key == 'key')
                $id = $var;
        }

        if (is_object($id))
            $id = $this->getIDfromOjb($id);

        if ($id == null && $this->getConfig('debug')) {
            echo "no caching key";
            return $function();
        }

        $cachefile = $this->getConfig('cacheDir') . '/' . utf8_decode($id);
        $cachetime = $this->getConfig('cacheTime');

        if (file_exists($cachefile) && time() - $cachetime < fileatime($cachefile)) {
            $ser = file_get_contents($cachefile);
            $val = bzdecompress(unserialize($ser));
            return $val;
        } else {
            $value = $function();
            $ser = serialize(bzcompress($value));
            file_put_contents($cachefile, $ser);
            return $value;
        }

        if ($this->getConfig('debug'))
            echo "no caching";
    }
480971
public function call($function, $params) {

		if(null === $this -> getAdapter()) {
			return trigger_error(sprintf('No database adapter was set in "%s"', __METHOD__), E_USER_ERROR);
		}

		if(null !== $function && false === is_string($function)) {
			return trigger_error(sprintf('Argument 1 passed to %s() must be of the type string, "%s" given', __METHOD__, gettype($function)), E_USER_ERROR);
		}

		if(false === is_array($params)) {
			return trigger_error(sprintf('Argument 2 passed to %s() must be of the type array, "%s" given', __METHOD__, gettype($params)), E_USER_ERROR);
		}

		$query  = sprintf('CALL %s(%s)', $function, implode(array_fill(0, count($params), '?'), ','));
		$output = $this -> getAdapter() -> query($query, $params) -> execute();

		return $output;
	}
1182158
public function processRequest($function = null)
    {
        if ($function) {
            $this->$function();
            $this->dispatchEvent(new AfterRequestProcessedEvent);
        } else {
            $sQAdd = $this->_getQuery();

            // formatting SQL queries
            $sQ = $this->_getDataQuery($sQAdd);
            $sCountQ = $this->_getCountQuery($sQAdd);

            $this->_outputResponse($this->_getData($sCountQ, $sQ));
        }
    }
26063
public function request($function, array $params = array(), $cache = null)
    {
        $request = $this->startRequest($function, $params, $cache);

        return $this->fetchResponse($request);
    }
661824
protected function decorate($function, $args, $quotes = '\'')
	{
		if ( ! is_null( $args ) ) {
			$args = $this->argsToString($args, $quotes);
			return $function . '(' . $args . ')';
		} else {
			return $function;
		}
	}
1089155
protected function setEscapeCallable($escapeFunction)/*# : callable */
    {
        if (!is_callable($escapeFunction)) {
            $this->escape = function ($v) {
                if (is_numeric($v) && !is_string($v)) {
                    return $v;
                } else {
                    return "'" . str_replace("'", "\\'", (string) $v) . "'";
                }
            };
        } else {
            $this->escape = $escapeFunction;
        }
        return $this;
    }