How to use a function that can be used for the validate of arguments in all routes?

Slim 3,How to use a function that can be used for the validate of arguments in all routes?

QQ%E6%88%AA%E5%9B%BE20180911172633
pic 1
QQ%E6%88%AA%E5%9B%BE20180911172647
pic2
require the namespaced file in the index.php(pic 1) or use composer to autoload it(pic 2)
QQ%E6%88%AA%E5%9B%BE20180911172647
use the namespace.
QQ%E6%88%AA%E5%9B%BE20180911172700
instantiating the class.

Use app middleware to parse the route args.