diff options
author | Luke Shumaker <LukeShu@sbcglobal.net> | 2011-09-04 20:40:45 -0400 |
---|---|---|
committer | Luke Shumaker <LukeShu@sbcglobal.net> | 2011-09-04 20:40:45 -0400 |
commit | 103332a30f8976fcc224c8f55dc23aba7b99e578 (patch) | |
tree | 32337915884fb6217007d569636f418130757df3 /src/lib/Controller.class.php | |
parent | bca1b20b4fc6dca04368f8c03b5e1faeec5af7d3 (diff) |
New router and view selector engine magic coolness.
Diffstat (limited to 'src/lib/Controller.class.php')
-rw-r--r-- | src/lib/Controller.class.php | 61 |
1 files changed, 8 insertions, 53 deletions
diff --git a/src/lib/Controller.class.php b/src/lib/Controller.class.php index 592ea2c..f9ed59d 100644 --- a/src/lib/Controller.class.php +++ b/src/lib/Controller.class.php @@ -1,65 +1,20 @@ <?php -class Controller { - /** - * Find the best view file to include based on file extension and HTTP - * 'Accept' headers. - */ - private function _resolveView($view) { - require_once('Mime.class.php'); - require_once('HTTP_Accept.class.php'); - - // Make a list of candidate views - $glob_string = VIEWPATH.'/pages/'.$view.'.*.php'; - $files = glob($glob_string); - - // Return false if there were no candidate views. - if (count($files) < 1) return false; +require_once('View.class.php'); - // $prefs is a associative array where the key is the file - // extension, and the value is how much we like that extension. - // Higher numbers are better. - $prefs = array(); - - // $accept will tell us how much we like a given mime type, - // based on the ACCEPT constant. - $accept = new HTTP_Accept(ACCEPT); - - // Loop through the candidate views, and record how much we - // like each. - foreach ($files as $file) { - $ext = preg_replace('@[^.]*\.(.*)\.php$@','$1', $file); - $mimes = Mime::ext2mime($ext); - foreach ($mimes as $mime) { - $quality = $accept->getQuality($mime); - if (isset($final[$ext])) { - $quality = max($final[$ext], $quality); - } - $prefs[$ext] = $quality; - } - } - - // Sort $prefs such that the entry with the highest value will - // appear first. - arsort($prefs); - - // Return the first entry in $prefs. - foreach ($prefs as $ext => $quality) { - return VIEWPATH."/pages/$view.$ext.php"; - } - } - +class Controller { /** * Show a $view, in the most appropriate format (according to file * extension and HTTP Accept header). Pass the array $vars to the view. */ protected function showView($view, $vars=null) { - global $VARS, $mm; + global $mm; + if ($vars===null) { $vars = array(); } - $VARS = $vars; - $VARS['template'] = $mm->template(); - include($this->_resolveView($view)); - unset($VARS); + $vars['template'] = $mm->template(); + + $obj = new View($view); + $obj->show($vars); } // Here be default handlers //////////////////////////////////////////// |