Base::route PHP Method

route() public method

Bind handler to route pattern
public route ( $pattern, $handler, $ttl, $kbps ) : null
$pattern string|array
$handler callback
$ttl int
$kbps int
return null
    function route($pattern, $handler, $ttl = 0, $kbps = 0)
    {
        $types = ['sync', 'ajax', 'cli'];
        $alias = null;
        if (is_array($pattern)) {
            foreach ($pattern as $item) {
                $this->route($item, $handler, $ttl, $kbps);
            }
            return;
        }
        preg_match('/([\\|\\w]+)\\h+(?:(?:@(\\w+)\\h*:\\h*)?(@(\\w+)|[^\\h]+))' . '(?:\\h+\\[(' . implode('|', $types) . ')\\])?/', $pattern, $parts);
        if (isset($parts[2]) && $parts[2]) {
            $this->hive['ALIASES'][$alias = $parts[2]] = $parts[3];
        } elseif (!empty($parts[4])) {
            if (empty($this->hive['ALIASES'][$parts[4]])) {
                user_error(sprintf(self::E_Named, $parts[4]), E_USER_ERROR);
            }
            $parts[3] = $this->hive['ALIASES'][$alias = $parts[4]];
        }
        if (empty($parts[3])) {
            user_error(sprintf(self::E_Pattern, $pattern), E_USER_ERROR);
        }
        $type = empty($parts[5]) ? 0 : constant('self::REQ_' . strtoupper($parts[5]));
        foreach ($this->split($parts[1]) as $verb) {
            if (!preg_match('/' . self::VERBS . '/', $verb)) {
                $this->error(501, $verb . ' ' . $this->hive['URI']);
            }
            $this->hive['ROUTES'][$parts[3]][$type][strtoupper($verb)] = [$handler, $ttl, $kbps, $alias];
        }
    }

Usage Example

コード例 #1
0
ファイル: middleware.php プロジェクト: Kekesed/Kambeng-Blog
 public function on($event, $pattern, $handler)
 {
     $bak = $this->f3->ROUTES;
     $this->f3->ROUTES = array();
     $this->f3->route($pattern, $handler);
     $this->routes[$event] = $this->f3->ROUTES;
     $this->f3->ROUTES = $bak;
 }
All Usage Examples Of Base::route