head

HEAD route

@see route()				Documetation of self::route();

@param mixed $route		The matched "route" found by the routing engine
@param mixed $callback	The callback function definition
@static
@access public
@return callable
778386
public static function head( $route = null, $callback = null ) {
		// Make sure that our parameters are what they say they are
		$args = self::smart_parameters( func_get_args() );

		return self::route( 'HEAD', $args[ 'route' ], $args[ 'callback' ] );
	}
868958
public function register($route, $callback, $httpMethod = '')
    {
        // Convert empty routes to the string 'method:home'
        if (!$route) 
            $route = 'home';
        
        // append the http method supplied
        if ($httpMethod) 
            $route = strtolower($httpMethod).':'.$route;
                
        $this->routes[$route] = $callback;
    }
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;
	}
446012
public function options(String $path, Callable $callback) : Route {

		return $this->collectRoute('OPTIONS', $path, $callback);

	}
181085
private function add(string $method, string $route, callable $callable)
	{
		$entry = (object)[
			'route' => $route,
			'pattern' => $this->createPattern($route),
			'callable' => $callable
		];

		if (!array_key_exists($method, $this->routes)) {
			$this->routes[$method] = [];
		}

		$this->routes[$method][] = $entry;
	}
371085
public static function get($url, $callback)
    {
        $route = new self($url);
        $route->setClosure($callback);
        $route->setMethod('get');

        $route->add();

        return $route;
    }
460049
protected function dispatchRoute(\Parable\Routing\Route $route)
    {
        $this->response->setHttpCode(200);
        $this->hook->trigger(self::HOOK_HTTP_200, $route);

        $dispatcher = \Parable\DI\Container::get(\Parable\Framework\Dispatcher::class);
        $dispatcher->dispatch($route);

        return $this;
    }
632130
public function add(Route $route, array $params = [])
    {
        $callback = $route->getCallable();
        if (empty($callback)) {
            return;
        }

        $this->routes[] = $route->getRoute();
        $paramNames = $route->getParamNames();
        foreach ($paramNames as $name) {
            if (isset($params[$name])) {
                $this->setParam($name, $params[$name]);
            }
        }

        if (is_array($callback)) {
            $this->callable = array_merge($this->callable, $callback);
        } elseif (!in_array($callback, $this->callable)) {
            $this->callable[] = $callback;
        }
    }
540920
public function post($path, $callback)
    {
        Argument::i()
            //argument 1 should be a string
            ->test(1, 'string')
            //argument 2 should be callable
            ->test(2, 'callable');
        
        return $this->route('post', $path, $callback);
    }
351064
public function get(string $pattern, callable $callback)
    {
        if ($this->requestMethod === "GET") {
            $this->mapRoute($pattern, $callback);
        }
    }
533881
public function route(string $method, string $path, callable $callback, int $priority = 0)
    {
        $this->getRouter()->route($method, $path, $callback, $priority);

        return $this;
    }
290113
private function callController(Route $route, array $args)
    {
        $callback = $route->getController();

        $args = array_merge($route->getArgs(), $args);

        // keep route for error
        if (!$this->currentRoute) {
            $this->currentRoute = $route;
            $this->args = $args;
        }

        // simple function
        if (is_callable($callback) && is_object($callback)) {
            return call_user_func_array($callback, [$args]);
        }

        // controller
        preg_match('`([A-Za-z_0-9\\\\<>]+)(?:::)?([A-Za-z_0-9_<>]+)?`', $callback, $find);

        $class = $this->replaceDynamicArgs($find[1], $route, $args);
        $method = isset($find[2]) ? $this->replaceDynamicArgs($find[2], $route, $args) : null;

        // replace class dynamic args
        if (!class_exists($class)) {
            throw new \BadMethodCallException(sprintf(
                "Can't load class '%s' on route '%s'",
                $class,
                $route->getName()
            ));
        }

        $controller = new $class();

        if (is_null($method)) {
            $method = 'get';

            if (self::request()->isAjax() && method_exists($controller, 'ajax')) {
                $method = 'ajax';
            } elseif (self::request()->getMethod() == 'POST' && method_exists($controller, 'post')) {
                $method = 'post';
            }
        }

        $ordererArgs = $this->mapArguments($controller, $method, $args);

        $event = new TimerEvent('router.mainController');
        $event->setData([
            'controller' => $class,
            'method' => $method,
            'data' => $ordererArgs,
        ]);

        try {
            $return = null;
            if (method_exists($controller, 'init')) {
                $return = call_user_func_array(
                    [$controller, 'init'],
                    $this->mapArguments($controller, 'init', $args)
                );
            }

            if (is_null($return)) {
                $return = call_user_func_array([$controller, $method], $ordererArgs);
            }
        } catch (HttpStatusCode $exception) {
            $return = $exception->getResponse();

            if (!$return) {
                $return = self::returnError($exception->getCode());
            }
        }

        self::emit($event);

        return $return;
    }
520000
public function put( $path, callable $callback ) {
        $route = new Route( 'PUT', $path, $callback );
        $this->_routes[] = $route;
        return $route;
    }
521889
public function route(Route $route, $handler) 
	{
		if (!is_callable($handler)) {
			throw new Exception('Route handler must be callable.');
		}

		$this->currentContext->addRoute($route, $handler);
		return $this;
	}
437391
public function post(string $url, $callback): Route
    {
        $route = new Route(['POST'], $url, $callback);
        $this->addRoute($route);

        return $route;
    }
888564
public function match( $method, $path, callable $callback ) {
        $route = new Route( mb_strtoupper( $method ), $path, $callback );
        $this->_routes[] = $route;
        return $route;
    }
485250
protected function storeRoute(array $methods, array $route)
    {
        $this->callbacks[] = (object)$route;
        $index             = count($this->callbacks) - 1;

        if (!isset($this->routes[$route['pattern']])) {
            $this->routes[$route['pattern']] = [];
        }

        if ($route['name']) {
            $this->names[$route['name']] = $index;
        }

        foreach ($methods as $method) {
            $this->routes[$route['pattern']][strtoupper($method)] = $index;
        }
    }