Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No executing middleware #210

Open
ghost opened this issue Aug 14, 2023 · 2 comments
Open

No executing middleware #210

ghost opened this issue Aug 14, 2023 · 2 comments

Comments

@ghost
Copy link

ghost commented Aug 14, 2023

I tryed to execute like the documentation

$router->before('GET|POST', '/admin/.*', function() {
if (!isset($_SESSION['user'])) {
header('location: /auth/login');
exit();
}
});

but isnt working the request goes direct into private side of application without check if user has access and is loged

@drnkwati
Copy link

Hello @gitbucket-crypto
It might not work for several reasons: try the following:
session_start()
session_status()

Check PHP session documentation

https://www.php.net/manual/en/ref.session.php

@ghost
Copy link
Author

ghost commented Oct 7, 2023

I discovered the problem, the node '/admin/.*, has setted data in global $_REQUEST like other nodes but the internal handler for requisition never uses that, I made my handler for this problems

`
class Handler
{
public function __construct()
{

}


const CALLABLE  = 1;
const INVOKE = 2;


public function handle($type, $fn, $params = [])
{
    list($controller, $method) = explode('@', $fn);
    switch($type)
    {
        case Handler::CALLABLE :
            $controller = new $controller($params);
            $className = get_class($controller);
            $methodVariable = array($controller,  $method); 
          

            if(is_callable($methodVariable, true, $callable_name)==true){
              
                call_user_func($methodVariable, $params); 
                unset($controller);
                unset($params);
            }
            else 
            {
                 $this->handle( Handler::INVOKE,$fn, $params); 
            }
            exit;
            
        break;
        case Handler::INVOKE :
            $reflectedMethod = new \ReflectionMethod($controller, $method);
            if (class_exists($controller) & ($reflectedMethod->isStatic()==false) )
            {
                $controller = new $controller($params);
                $reflectionClass = new \ReflectionClass(get_class($controller));
                $reflectionMethod = $reflectionClass->getMethod(strval($method));
                $reflectionMethod->setAccessible(true); 
                $reflectionMethod->invoke(new $controller($params)); 
                unset($controller);
                unset($params);
                unset($reflectedMethod);
                unset($reflectionMethod);
            }
            else
            {
                 $this->handle( Handler::CALLABLE,$fn, $params); 
            }
        break;
    }
}

}`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant