• Уважаемый Гость.
    - Прежде чем создать свою тему, пожалуйста, попробуй воспользоваться этим -> ПОИСКОМ !!!
    - После решения Вашего вопроса (проблемы) - нажмите "Лучший ответ", на сообщении, которое его решило. За игнорирование этого действия - Вы получите соответствующее предупреждение. Мы - стараемся Вам помочь. Уделите 10 секунд - чтобы нажать кнопку. (Если у Вас нет такой возможности - укажите в последнем своем сообщении какой ответ Вы считаете лучшим. Наши модераторы сделают это за Вас)
    ЗАПРЕЩЕНО:
    - Cоздавать темы с названиями "Помогите", "Плиз", "Ошибка", "Не могу найти", "Хелп" и тому подобное;
    - Cоздавать темы без детального описания того, что нужно исправить.
    - Cоздавать темы из одного скриншота.
    За игнор правил форума - Ваша тема будет удалена, а Вы получите системное предупреждение.

Fatal error: Call to undefined method Keys::keys() in on line 76

Статус
В этой теме нельзя размещать новые ответы.

Xxxtreton

Умник
Код Router.php
PHP:
<?php

/**
 * @method static Macaw get(string $route, Callable $callback)
 * @method static Macaw post(string $route, Callable $callback)
 * @method static Macaw put(string $route, Callable $callback)
 * @method static Macaw delete(string $route, Callable $callback)
 * @method static Macaw options(string $route, Callable $callback)
 * @method static Macaw head(string $route, Callable $callback)
 */
class Router
{
    public static $halts = false;
    public static $routes = array();
    public static $methods = array();
    public static $callbacks = array();
    public static $patterns = array(
        ':any' => '[^/]+',
        ':num' => '[0-9]+',
        ':all' => '.*'
    );
    public static $error_callback;
    /**
     * Defines a route w/ callback and method
     */
    public static function __callstatic($method, $params)
    {

        $uri = $params[0];
        $callback = $params[1];
        array_push(self::$routes, $uri);
        array_push(self::$methods, strtoupper($method));
        array_push(self::$callbacks, $callback);
    }

    /**
     * Defines callback if route is not found
     */
    public static function error($callback)
    {
        self::$error_callback = $callback;
    }

    public static function haltOnMatch($flag = true)
    {
        self::$halts = $flag;
    }

    /**
     * Runs the callback for the given request
     */
    public static function dispatch()
    {
        $uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
        $method = $_SERVER['REQUEST_METHOD'];
        $searches = array_keys(static::$patterns);
        $replaces = array_values(static::$patterns);
        $found_route = false;
        // check if route is defined without regex
        if (in_array($uri, self::$routes)) {
            $route_pos = array_keys(self::$routes, $uri);
            foreach ($route_pos as $route) {
                if (self::$methods[$route] == $method) {
                    $found_route = true;
                    //if route is not an object
                    if (!is_object(self::$callbacks[$route])) {
                        //grab all parts based on a / separator
                        $parts = explode('/', self::$callbacks[$route]);
                        //collect the last index of the array
                        $last = end($parts);
                        //grab the controller name and method call
                        $segments = explode('@', $last);
                        //instanitate controller
                        $controller = new $segments[0]();
                        //call method
                        $controller->{$segments[1]}();

                        if (self::$halts) {
                            return;
                        }

                    } else {
                        //call closure
                        call_user_func(self::$callbacks[$route]);

                        if (self::$halts) {
                            return;
                        }

                    }
                }
            }
        } else {
            // check if defined with regex
            $pos = 0;
            foreach (self::$routes as $route) {
                if (strpos($route, ':') !== false) {
                    $route = str_replace($searches, $replaces, $route);
                }
                if (preg_match('#^' . $route . '$#', $uri, $matched)) {
                    if (self::$methods[$pos] == $method) {
                        $found_route = true;
                        array_shift($matched); //remove $matched[0] as [1] is the first parameter.
                        if (!is_object(self::$callbacks[$pos])) {
                            //grab all parts based on a / separator
                            $parts = explode('/', self::$callbacks[$pos]);
                            //collect the last index of the array
                            $last = end($parts);
                            //grab the controller name and method call
                            $segments = explode('@', $last);
                            //instanitate controller
                            $controller = new $segments[0]();
                            //call method and pass any extra parameters to the method
                            $params = count($matched);

                            //call method and pass any extra parameters to the method
                            switch ($params) {
                                case '0':
                                    $controller->$segments[1]();
                                    break;
                                case '1':
                                    $controller->{$segments[1]}($matched[0]);
                                    break;
                                case '2':
                                    $controller->$segments[1]($matched[0],$matched[1]);
                                    break;
                            }

                            if (self::$halts) {
                                return;
                            }

                        } else {
                            call_user_func_array(self::$callbacks[$pos], $matched);

                            if (self::$halts) {
                                return;
                            }

                        }

                    }
                }
                ++$pos;
            }
        }

        // run the error callback if the route was not found
        if ($found_route == false) {
            if (!self::$error_callback) {
                self::$error_callback = function () {
                    $page = 'Оффлайн страница | SAMP: Valenta Role Play - Играй в GTA: SA по сети!';
                    include 'engine/template/other/404.php';
                    
                };
            }
            call_user_func(self::$error_callback);
        }
    }
};
строка где выходит ошибка
PHP:
$controller->{$segments[1]}();
 
Статус
В этой теме нельзя размещать новые ответы.
Сверху Снизу