Skip to content

Instantly share code, notes, and snippets.

@brandonsavage
Created March 7, 2014 18:27
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save brandonsavage/360be526bbdd720ac7cd to your computer and use it in GitHub Desktop.
$di->params['Modus\Controller\Base'] = array(
'template' => $di->lazyGet('template'),
'session' => $di->lazyGet('session'),
'context' => $di->lazyGet('context'),
'response' => $di->lazyGet('context_response'),
);
<?php
namespace Modus\Controller;
use Aura\Web\Response;
use Aura\Web\Context;
use Aura\View;
use Modus\Session;
abstract class Base {
protected $session;
protected $context;
protected $response;
protected $template;
public function __construct(
View\TwoStep $template,
Session\Aura $session,
Context $context,
Response $response
) {
$this->template = $template;
$this->session = $session;
$this->context = $context;
$this->response = $response;
}
protected function authRequired() {
return [];
}
protected abstract function checkAuth($action);
protected function getResource($resourceName) {
return $this->di->get($resourceName);
}
protected function preExec() {}
protected function preAction() {}
protected function postAction() {}
protected function preRender() {}
protected function render() {
}
protected function postRender() {}
protected function postExec() {}
public function exec($action, array $params = [])
{
$this->preExec();
$this->preAction();
$badAuth = $this->checkAuth($action);
// If auth required but not provided, return a response object.
// That object should be configured with a redirect to login.
if($badAuth) {
return $badAuth;
}
$result = call_user_func_array([$this, $action], $params);
$this->postAction();
$this->preRender();
$this->render();
$this->postRender();
$this->postExec();
return $result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment