Globals.php

Go to the documentation of this file.
00001 <?php
00002 
00031 class Robo47_View_Helper_Globals extends Zend_View_Helper_Abstract
00032 {
00033 
00044     public function Globals($global, $name = null, $default = null,
00045         $escape = true)
00046     {
00047         $value = $this->_checkGlobal($global, $name, $default);
00048 
00049         if (true === $escape) {
00050             if (is_string($value)) {
00051                 $value = $this->view->escape($value);
00052             }
00053         }
00054         return $value;
00055     }
00056 
00063     protected function _checkGlobal($global, $name, $default)
00064     {
00065         $lglobal = strtolower($global);
00066         switch ($lglobal) {
00067             case 'server':
00068             case 'env':
00069             case 'post':
00070             case 'get':
00071             case 'cookie':
00072             case 'session':
00073                 return $this->_getGlobal(
00074                     '_' . strtoupper($global),
00075                     $name,
00076                     $default
00077                 );
00078                 break;
00079             default:
00080                 $message = 'Unknown global "' . $global . '"';
00081                 throw new Robo47_View_Helper_Exception($message);
00082         }
00083     }
00084 
00092     protected function _getGlobal($global, $name = null, $default = null)
00093     {
00094         if (!isset($GLOBALS[$global])) {
00095             return $default;
00096         }
00097         if (null === $name) {
00098             return $GLOBALS[$global];
00099         }
00100         if (isset($GLOBALS[$global][$name])) {
00101             return $GLOBALS[$global][$name];
00102         } else {
00103             return $default;
00104         }
00105     }
00106 }