Last active
December 11, 2015 07:28
-
-
Save ajcrites/4566175 to your computer and use it in GitHub Desktop.
Attempt at mediator implementation for handling `before`/`after` controller requests.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$controller = $container->create($request->controller); | |
$mediator = $container->create('BeforeMediator'); | |
$controller->registerMediator($mediator); | |
$controller->triggerActions(); | |
$response = $container->create('Response'); | |
$controller->{'action' . $request->action}($request, $response); | |
class BeforeMediator { | |
/* snip */ | |
public function notify($action) { | |
foreach ($this->registrants as $r) { | |
$r->$action(); | |
} | |
} | |
} | |
class Controller { | |
/* snip */ | |
public function triggerActions() { | |
$this->mediator->notify('beforeRequest') | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment