Exemple #1
0
 protected function _contentRendering()
 {
     $content = '';
     foreach ($this->_obj->getContent() as $elem) {
         if ($elem instanceof View\ViewObject) {
             try {
                 $deco = Decorator::factory($elem);
             } catch (View\Exception $e) {
                 $decoratorClassBase = get_class($elem) . '\\' . View::getContext();
                 try {
                     // get decorator data from object
                     $objDecorator = $this->_obj->getDecorator();
                     // Current class object decorator
                     $decoratorClass = $decoratorClassBase . ucfirst($objDecorator['name']);
                     $deco = new $decoratorClass($elem);
                 } catch (View\Exception $e) {
                     // Default decorator
                     $decoratorClass = $decoratorClassBase . 'Default';
                     $deco = new $decoratorClass($elem);
                 }
             }
             if ($deco instanceof self) {
                 $content .= $deco->render();
             }
         } else {
             $content .= $elem;
         }
     }
     return $content;
 }
Exemple #2
0
 /**
  * Factory pattern used to instanciate a proper decorator for the given object extended from t41\View\ViewObject
  *
  * @param t41\View\ViewObject $object disabled for now because of legacy problems
  * @param array $params
  * @return t41\View\AbstractDecorator
  */
 public static function factory($object, array $params = null)
 {
     $decoratorData = $object->getDecorator();
     if (is_null($params) && isset($decoratorData['params'])) {
         $params = $decoratorData['params'];
     } elseif (!is_null($params) && isset($decoratorData['params'])) {
         $params = array_merge($params, $decoratorData['params']);
     }
     // class name without the first component of the namespace
     $class = substr(get_class($object), strpos(get_class($object), '\\') + 1);
     if (View::getViewType() != Adapter\WebAdapter::ID) {
         $decoratorData['name'] = 'Default';
     }
     if (!isset($decoratorData['name']) || trim($decoratorData['name']) == '') {
         $decoratorData['name'] = 'Default';
     }
     // decorator name
     $deconame = View::getContext() . ucfirst($decoratorData['name']);
     foreach (self::$_paths as $library) {
         $file = $library['path'] . str_replace('\\', '/', $class) . '/' . $deconame . '.php';
         if (file_exists($file)) {
             require_once $file;
             $fullclassname = '\\' . $library['ns'] . '\\' . $class . '\\' . $deconame;
             if (class_exists($fullclassname)) {
                 try {
                     $decorator = new $fullclassname($object, $params);
                 } catch (Exception $e) {
                     throw new Exception("Error instanciating '{$fullclassname}' decorator.", $e->getCode(), $e);
                 }
                 return $decorator;
             }
         }
     }
     throw new Exception("The decorator class '{$class}' doesn't exist or was not found");
 }