Example #1
0
 /**
  * Loads a component by class name.
  * 
  * If the component class has a method named "ACCEPT_CONTEXT"
  * that method will be invoked on the object instance
  * after the component is initialized.
  * The context object (instance of this class) will be passed in as
  * an argument to ACCEPT_CONTEXT.
  *
  * @see DF_Web_Component_Loader for component initialization
  * @param string $class
  * @return DF_Web_Component
  */
 protected function component($class)
 {
     if (!is_string($class)) {
         throw new DF_Error_InvalidArgumentException("class", $class, "string");
     }
     #self::$LOGGER->debug("Looking up component: $class");
     $component = NULL;
     try {
         $component = $this->component_loader->component($class);
     } catch (DF_Web_Component_LoaderException $ex) {
         self::$LOGGER->error("Error loading component {$class}:\n" . $ex->__toString());
         // Dont need the entire stack trace of the component loader
         throw new DF_Web_Exception("Failed loading component {$class}:\n" . $ex->getMessage());
     } catch (DF_Web_Exception $ex) {
         #self::$LOGGER->error("Error initializing component $class:\n".$ex->__toString());
         throw $ex;
         #throw new DF_Web_Exception($ex->getMessage());
     }
     if (method_exists($component, 'ACCEPT_CONTEXT')) {
         try {
             return $component->ACCEPT_CONTEXT($this);
         } catch (DF_Web_Exception $ex) {
             throw new DF_Web_Exception("Failed to call {$class}->ACCEPT_CONTEXT(..)", $ex);
             #throw new DF_Web_Exception(
             #    "Failed executing {$class}->ACCEPT_CONTEXT(): "
             #    .$ex->getMessage().", exception in "
             #    .sprintf("%s(%d)",$ex->getFile(),$ex->getLine())
             #);
         }
     }
     return $component;
 }
 public function setUp()
 {
     $this->smarty = DF_Web_Component_Loader::component('DF_Web_View_Smarty', 'DF_Web');
 }