Connect a route to a callable
@param string $route
@param callable $callable
@throws InvalidArgumentException
424414
public function connect($route, $callable){
    if(!is_string($route)){
      throw new \InvalidArgumentException("Route to connect to callable musts be provided as a string");
    }
    if(!is_callable($callable)){
      throw new \InvalidArgumentException("Provided callable for $route is not valid.");
    }
    $this->routes[$route] = $callable;
  }
1129269
public function set($methods, $route, callable $callable)
	{
		if (is_string($methods)) {
			$methods = [$methods];
		}

		foreach ($methods as $method) {
			$this->add($method, $route, $callable);
		}

		return $this;
	}
1219251
public function map($callback)
    {
        if (!is_callable($callback)) {
            throw new InvalidArgumentException('Callback has to be a valid callable, '.gettype($callback).' given.');
        }

        for ($i = 0; $this->checkIfLineNumberIsValid($i, false); $i++) {
            $this->setCurrentLineNumber($i);
            call_user_func($callback, $this->getLine($i), $i, $this);
        }
    }
149713
def navigate(self, name, *args):
        
        if name not in self.routes:
            raise Exception('invalid route name \'%s\'' % name)
        elif callable(self.routes[name]):
            return self.routes[name](self, *args)
        raise Exception('route %s not callable', name)
808195
public function call($key, $callable)
    {
        if (!is_callable($callable)) {
            throw new \InvalidArgumentException('Not a valid callable.');
        }

        if ($this->exists($key)) {
            return $this->get($key);
        }

        $args = func_get_args();
        array_shift($args);
        array_shift($args);

        $value = call_user_func_array($callable, $args);

        $this->set($key, $value);

        return $value;
    }
1154666
public function addRoute($method, $route, $callback)
    {
        return $this->routes[] = new Route(strtoupper($method), $route, $callback);
    }
282670
protected function callController($callable, Request $request)
    {
        list($class, $action) = explode('@', $callable[0], 2);

        // Make sure any route parts are available as query parameters from the request.
        $request->query->add($callable[1]);

        $controller = $this->factory->make($class);
        $controller->setRequest($request);

        return $controller->call($action);
    }
662743
public static function call(callable $callable, $args=null)
    {

        if (!is_array($args)) {
            $args = $args === null ? [] : [$args];
        }

        return static::callFast($callable, static::evaluateArgs($args));

    }
1230597
public function setFilter($key, $callable)
    {
        if (!is_callable($callable)) {
            throw new InvalidArgumentException('Invalid callable for filter: "'.$key.'"');
        }
        if (!preg_match('/^'.self::KEY_REGEX.'$/', $key)) {
            throw new InvalidArgumentException('Invalid name for filter: "'.$key.'". The filter name can only contain alphanumeric characters and underscore.');
        }

        $this->filters[$key] = $callable;

        return $this;

    }
1232404
public function traverseFilters(callable $callable)
    {
        foreach ($this->filters() as $expr) {
            /**
             * @param  FilterInterface           $expr The iterated filter expression object.
             * @param  FilterCollectionInterface $this The context of the traversal.
             * @return void
             */
            $callable($expr, $this);
            if ($expr instanceof FilterCollectionInterface) {
                $expr->traverseFilters($callable);
            }
        }

        return $this;
    }
685889
public function setCallable($callable)
    {
        $matches = array();
        if (is_string($callable) && preg_match('!^([^\:]+)\:([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)$!', $callable, $matches)) {
            $class = $matches[1];
            $method = $matches[2];
            $callable = function() use ($class, $method) {
                static $obj = null;
                if ($obj === null) {
                    $obj = new $class;
                }
                return call_user_func_array(array($obj, $method), func_get_args());
            };
        }

        if (!is_callable($callable)) {
            throw new \InvalidArgumentException('Route callable must be callable');
        }

        $this->callable = $callable;
    }
1111462
public function addRoute(array $methods, string $route, $handler): void
    {
        if ($methods === []) {
            throw new \InvalidArgumentException('Methods is empty');
        }

        if (\is_callable($handler)) {
            $handler = \Closure::fromCallable($handler);
        } elseif (!\is_array($handler)) {
            throw new \InvalidArgumentException('Handler is not a valid type: ' . \var_export($handler, true));
        }

        $parts = \explode('/', \trim($route, static::SEPARATOR_TRIM));

        if (!isset($parts[1]) && $parts[0] === '') {
            $parts = [];
        }

        $current = &$this->routes;
        foreach ($parts as $v) {
            if ($v[0] === '{' && $v[-1] === '}') {
                $v = \substr($v, 1, -1);
                if (\strpos($v, ':') !== false) {
                    [$name, $regexp] = \explode(':', $v, 2);

                    $regexp = '/^' . $regexp . '$/';
                    if (!isset($current['regexps'][$regexp])) {
                        $current['regexps'][$regexp] = [
                            'children' => [],
                            'regexps' => [],
                            'name' => $name,
                        ];
                    }
                    $current = &$current['regexps'][$regexp];
                } else {
                    if (!isset($current['others'])) {
                        $current['others'] = [
                            'children' => [],
                            'regexps' => [],
                            'name' => $v,
                        ];
                    }
                    $current = &$current['others'];
                }
            } else {
                if (!isset($current['children'][$v])) {
                    $current['children'][$v] = [
                        'children' => [],
                        'regexps' => [],
                    ];
                }
                $current = &$current['children'][$v];
            }
        }

        $current['route'] = $route;

        if (!isset($current['methods'])) {
            $current['methods'] = [];
        }

        foreach ($methods as $v) {
            $current['methods'][\strtoupper($v)] = $handler;
        }
    }
761564
protected function callFilter($filter, $route, $request)
    {
        return $this->callRouteFilter(
            $filter['filter'], $filter['parameters'], $route, $request
        );
    }
420063
public function delete($table, callable $callable = null)
    {
        $this->connect($table);
        $delete = new Delete($this);

        return $callable($delete);
    }
774085
public function addBaselineCallable($name, $callable)
    {
        if (isset($this->callables[$name])) {
            throw new \InvalidArgumentException(sprintf(
                'Baseline callable "%s" has already been registered.',
                $name
            ));
        }

        if (!is_callable($callable)) {
            throw new \InvalidArgumentException(sprintf(
                'Given baseline "%s" callable "%s" is not callable.',
                $name, is_string($callable) ? $callable : gettype($callable)
            ));
        }

        $this->callables[$name] = $callable;
    }
311130
public function addRuleAnnotation(\Imi\Server\Route\Annotation\Route $annotation, $callable, $options = [])
    {
        $this->rules[$annotation->url][$this->hashKey($annotation)] = array_merge([
            'annotation'=> $annotation,
            'callable'  => $callable,
        ], $options);
    }
788521
public function read($table, callable $callable = null)
    {

        $this->connect($table);
        $read = new Read($this);

        return $callable($read);
    }