-
Notifications
You must be signed in to change notification settings - Fork 10
Middleware
AzJezz edited this page Apr 22, 2018
·
10 revisions
Middleware allows you to intercept or execute services before the app runs. Use the run
function as you would construct. Middleware supports the same definitions as Services.
$tipsy = new Tipsy\Tipsy;
$tipsy->middleware('LoginService', [
'run' => function() {
if (!$_SESSION['user']) {
// login
} else {
$this->user = 'devin';
}
}
]);
$tipsy->router()->home(function($LoginService) {
echo $LoginService->user;
});
$tipsy->run();
This will create the middleware and run it immediately.
$tipsy->middleware(function($Request) {
if ($Request->loc() == 'api') {
// do special login stuff for any /api/* url
}
});
- Home
- Getting Started
- Server Config
- Installation
- Installing Composer
- App
- Route Shorthand
- Config
- Routes
- Methods
- Controller Types
- Params & Regex
- Aliases
- Dependency Injection
- Advanced Routing
- Services
- User Defined Services
- Built in Services
- Middleware
- Views
- Templates
- Scope
- Resource
- Factory
- Looper
- Examples
- Plugins
- About