riverside / php-express

:horse: PHP micro-framework inspired by Express.js
https://riverside.github.io/php-express/
MIT License
26 stars 10 forks source link

Pass a static function to Application->use #1

Closed cstayyab closed 3 years ago

cstayyab commented 3 years ago

I have a class named Middleware and all the middlewares are declared as static functions in that class. How can I pass any of the function to use it as middleware. I tried following code but it does not work.

$app->use(Middlewares::setDeveloperHeader); // Here setDeveloperHeader is a public static function of class Middlewares

Any help would be appreciated.

riverside commented 3 years ago

You can use something like this: $app->use('\Middlewares@setDeveloperHeader');

See full example: https://github.com/riverside/php-express/blob/master/examples/03-controllers/index.php