src/Oito/Micro/Application.php
public function run() {
        if (isset($this['kernel'])) {
            return $this['kernel'];
        }

        $uri    = $this['request']->getRequestUri();
        $method = $this['request']->getMethod();
        $has404 = isset($this['404']);

        $route = $this['router']->match($uri, $method);

        if (!$route) {
            return $has404 ? $this['404'] : header('HTTP/1.0 404', true, 404);
        }

        $name = $route['name'] ? (string) S::create($route['name'])->underscored() : 'undefined';
        $this->event()->emit('route.' . $name, [$this, $route]);

        $callable = $route['target'];
        $params   = is_array($route['params']) ? $route['params'] : [];

        if (!is_callable($callable) && !($callable instanceof \Closure)) {
            return $has404 ? $this['404'] : header('HTTP/1.0 404', true, 404);
        }

        // we also define the parameters in the request attributes (if not using callable parameters)
        $this->request()->attributes->add($params);

        // binding the Closure to the Application object
        if ($callable instanceof \Closure) {
            $callable = $callable->bindTo($this);
        }

        ksort($params);
        $params    = array_merge([$this], $params);
        $hasEvents = $route['name'] && array_key_exists($route['name'], $this->routeEvents);

        if ($hasEvents) {
            foreach ($this->routeEvents as $event) {
                $this->event()->emit($event, [$this, $route, $callable, $params]);
            }
        }

        $this->event()->emit('run.before', [$this, $route, $callable, $params]);

        // processing...
        $response = call_user_func_array($callable, $params);

        if ($hasEvents) {
            foreach ($this->routeEvents as $event) {
                $this->event()->emit($event, [$this, $route, $callable, $params]);
            }
        }

        $this->event()->emit('run.after', [$this, $route, $callable, $params, $response]);

        if ($response instanceof Response) {
            $response->send();
        }
    }
public function run() {
        if (isset($this['kernel'])) {
            return $this['kernel'];
        }

        $uri    = $this['request']->getRequestUri();
        $method = $this['request']->getMethod();
        $has404 = isset($this['404']);

        $route = $this['router']->match($uri, $method);

        if (!$route) {
            return $has404 ? $this['404'] : header('HTTP/1.0 404', true, 404);
        }

        $name = $route['name'] ? (string) S::create($route['name'])->underscored() : 'undefined';
        $this->event()->emit('route.' . $name, [$this, $route]);

        $callable = $route['target'];
        $params   = is_array($route['params']) ? $route['params'] : [];

        if (!is_callable($callable) && !($callable instanceof \Closure)) {
            return $has404 ? $this['404'] : header('HTTP/1.0 404', true, 404);
        }

        // we also define the parameters in the request attributes (if not using callable parameters)
        $this->request()->attributes->add($params);

        // binding the Closure to the Application object
        if ($callable instanceof \Closure) {
            $callable = $callable->bindTo($this);
        }

        ksort($params);
        $params    = array_merge([$this], $params);
        $hasEvents = $route['name'] && array_key_exists($route['name'], $this->routeEvents);

        if ($hasEvents) {
            foreach ($this->routeEvents as $event) {
                $this->event()->emit($event, [$this, $route, $callable, $params]);
            }
        }

        $this->event()->emit('run.before', [$this, $route, $callable, $params]);

        // processing...
        $response = call_user_func_array($callable, $params);

        if ($hasEvents) {
            foreach ($this->routeEvents as $event) {
                $this->event()->emit($event, [$this, $route, $callable, $params]);
            }
        }

        $this->event()->emit('run.after', [$this, $route, $callable, $params, $response]);

        if ($response instanceof Response) {
            $response->send();
        }
    }
Dispatch the application
@return mixed