Dispatches walking an expression to the appropriate handler.

@return mixed

@throws RuntimeException
346490
public function dispatch(Expression $expr)
    {
        switch (true) {
            case $expr instanceof Comparison:
                return $this->walkComparison($expr);
            case $expr instanceof Value:
                return $this->walkValue($expr);
            case $expr instanceof CompositeExpression:
                return $this->walkCompositeExpression($expr);
            default:
                throw new RuntimeException('Unknown Expression ' . get_class($expr));
        }
    }
1334816
public function getFunctions()
    {
        return [
            /**
             * Evaluate a rule by name.
             */
            new ExpressionFunction(
                'rule',
                function () {
                    throw new RuntimeException(
                        'Function "rule" can\'t be compiled.'
                    );
                },
                function (array $context, $value) {
                    /**
                     * @var Rule $rule
                     */
                    $rule = $this
                        ->ruleRepository
                        ->findOneBy([
                            'name' => $value,
                        ]);

                    return $rule
                        ? $this
                            ->ruleManager
                            ->evaluate(
                                $rule,
                                $context
                            )
                        : false;
                }
            ),
        ];
    }
525489
public function run()
    {
        $url = parse_url($_SERVER['REQUEST_URI']);

        $controller = $this->router->find($url['path']);
        if (!$controller instanceof ControllerInterface) {
            throw new \RuntimeException('No valid controller found.');
        }

        $controller->setServer($this);

        $result = $controller->execute();

        $data = json_encode($result);

        if (array_key_exists('callback', $_GET)) {
            $data = $_GET['callback'] . '(' . $data . ')';
        }
        
        return $data;
    }
496815
protected function runCallable()
    {
        $parameters = $this->resolveMethodDependencies(
            $this->getParametersWithoutNulls(), new ReflectionFunction($this->action['uses'])
        );

        $callable = $this->action['uses'];

        return call_user_func_array($callable, $parameters);
    }
249319
public function collectionLoader()
    {
        if (!isset($this->collectionLoader)) {
            throw new RuntimeException(sprintf(
                'Collection Loader is not defined for "%s"',
                get_class($this)
            ));
        }

        return $this->collectionLoader;
    }
171901
public function getNextRunDate()
    {
        if ($this->nextRunDate === null) {
            $nextRun = $this->cronExpression->getNextRunDate();
            $this->nextRunDate = $nextRun->getTimestamp();
        }

        return $this->nextRunDate;
    }
574391
public function execute()
    {
        if (!is_resource($this->handle)) {
            throw new RuntimeException('Curl handle has been closed, just open it before execute...');
        }

        curl_setopt_array($this->handle, array_filter($this->options));
        $return = curl_exec($this->handle);

        if ($return === false) {
            throw ExceptionFactory::build(
                curl_errno($this->handle),
                curl_error($this->handle)
            );
        }

        return $return;
    }
325067
public function process()
    {
        $operands = $this->getOperands();

        if (($c = count($operands)) < 2) {
            $msg = "The 'qtism.runtime.expressions.operators.custom.Implode' custom operator takes 2 sub-expressions as parameters, ${c} given.";
            throw new OperatorProcessingException($msg, $this, OperatorProcessingException::NOT_ENOUGH_OPERANDS);
        } elseif ($operands->containsNull() === true) {
            return null;
        } elseif ($operands->exclusivelyString() === false) {
            $msg = "The 'qtism.runtime.expressions.operators.custom.Implode' custom operator only accepts operands with a string baseType.";
            throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_BASETYPE);
        } elseif ($operands[0]->getCardinality() !== Cardinality::SINGLE) {
            $msg = "The 'qtism.runtime.expressions.operators.custom.Implode' custom operator only accepts a first operand with single cardinality.";
            throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
        } elseif ($operands[1]->getCardinality() !== Cardinality::MULTIPLE && $operands[1]->getCardinality() !== Cardinality::ORDERED) {
            $msg = "The 'qtism.runtime.expressions.operators.custom.Implode' custom operator only accepts a second operand with multiple or ordered cardinality.";
            throw new OperatorProcessingException($msg, $this, OperatorProcessingException::WRONG_CARDINALITY);
        }

        $glue = $operands[0]->getValue();
        $pieces = $operands[1];

        // Note: implode() is binary-safe \0/!
        $string = implode($glue, $pieces->getArrayCopy());

        return new QtiString($string);
    }
183872
protected function executeHandler()/*# : bool */
    {
        try {
            $handler = $this->result->getHandler();
            $callable = $this->getResolver()->resolve($handler);

            if ($this->result->getRoute()) {
                return $this->callableWithRoute($callable);
            } else {
                call_user_func($callable, $this->result);
                return true;
            }
        } catch (\Exception $e) {
            $this->result->setHandler(null);
            return false;
        }
    }
511228
public function getRuntimeConfigurableWrapper()
    {
        if ($this->wrapper === null) {
            $this->wrapper = new RuntimeConfigurable($this, $this->getTaskName());
        }

        return $this->wrapper;
    }
960233
protected function expressionPasses()
    {
        $date = new \DateTime('now');
        if ($this->_timezone) {
            $date->setTimezone($this->_timezone);
        }
        return CronExpression::factory($this->_expression)->isDue($date);
    }
973497
public function execute() {
        if (count($this->config['arguments']) === 1) {
            if (array_key_exists($this->config['arguments'][0], $this->config['commands'])) {
                // APP help COMMAND:
                $class = $this->config['commands'][$this->config['arguments'][0]]['class'];

                if (!class_exists($class) ||
                    !is_subclass_of($class, __NAMESPACE__ . '\\Executes')
                ) {
                    throw new RuntimeException(sprintf(
                        'Command "%s" not found',
                        $this->config['arguments'][0]
                    ), ExitApp::BAD_USER_INTERACTION);
                }

                /** @var Executes $command */
                $command = new $class($this->config, $this->log);
                $command->printUsage();
            } else {
                // APP help unknown:
                throw new RuntimeException(sprintf(
                    'Command "%s" not found',
                    $this->config['arguments'][0]
                ), ExitApp::BAD_USER_INTERACTION);
            }
        } else {
            // APP help:
            $this->printUsage();
        }

        return $this;
    }
302180
public function get_handler() : handler {
        if ($this->handler === null) {
            $this->handler = handler::get_handler($this->get('component'), $this->get('area'), $this->get('itemid'));
        }
        return $this->handler;
    }
1091383
public function dispatch($http_method, $url)
    {
        if ($this->dispatcher === null) {
            throw new \RuntimeException('Route dispatcher is not initialized');
        }

        $this->dispatched_http_method = $http_method;
        $this->dispatched_url = $url;
        $this->route_info = $this->dispatcher->dispatch($http_method, $url);

        return $this->route_info;
    }
249722
public function getPath()
    {
        if (!$this->php_path) {
            if (!($this->php_path = $this->finder->find())) {
                throw new \RuntimeException(
                    'The php executable could not be found, add it to your PATH environment variable and try again'
                );
            }
            $this->php_path = escapeshellarg($this->php_path);
        }

        return $this->php_path;
    }
644105
public function getInstance()
    {
        if (!is_null($this->instance)) {
            return $this->instance;
        }

        if (!class_exists($this->class)) {
            throw new \RuntimeException('Could not find job class "'.$this->class.'"');
        }

        if (!method_exists($this->class, $this->method) or !is_callable(array($this->class, $this->method))) {
            throw new \RuntimeException('Job class "'.$this->class.'" does not contain a public "'.$this->method.'" method');
        }

        $class = new \ReflectionClass($this->class);

        if ($class->isAbstract()) {
            throw new \RuntimeException('Job class "'.$this->class.'" cannot be an abstract class');
        }

        $instance = $class->newInstance();

        return $this->instance = $instance;
    }
1071465
public function useGlobally()
    {
        if (!isset($this->handle)) {
            throw new \RuntimeException("The stream is closed");
        }
        
        if ($this->isGlobal()) {
            return $this;
        }
        
        $this->assertOutputBuffering();
        
        $output = $this->createOutputStream();
        if ($output === false) {
            throw new \RuntimeException("Failed to create temp stream");
        }
        
        $this->obClean();
        $this->rewind();
        stream_copy_to_stream($this->handle, $output);
        
        parent::close();
        $this->handle = $output;
        
        return $this;
    }