Skip to content

Instantly share code, notes, and snippets.

@ajcrites
Last active December 11, 2015 07:28
Show Gist options
  • Save ajcrites/4566175 to your computer and use it in GitHub Desktop.
Save ajcrites/4566175 to your computer and use it in GitHub Desktop.
Attempt at mediator implementation for handling `before`/`after` controller requests.
<?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