Exemplo n.º 1
0
 /**
  * Gets a temporary instance of a Dispatcher
  * 
  * @param   string  $option  The component name
  * @param   string  $view    The View name
  * @param   array   $config  Configuration data
  * 
  * @return ADispatcher
  */
 public static function &getTmpInstance($option = null, $view = null, $config = array())
 {
     if (array_key_exists('input', $config)) {
         if ($config['input'] instanceof AInput) {
             $input = $config['input'];
         } else {
             if (!is_array($config['input'])) {
                 $config['input'] = (array) $config['input'];
             }
             $config['input'] = array_merge($_REQUEST, $config['input']);
             $input = new AInput($config['input']);
         }
     } else {
         $input = new AInput();
     }
     $defaultApp = AApplication::getInstance()->getName();
     if (!is_null($option)) {
         $config['option'] = $option;
     } else {
         $config['option'] = $input->getCmd('option', $defaultApp);
     }
     if (!is_null($view)) {
         $config['view'] = $view;
     } else {
         $config['view'] = $input->getCmd('view', '');
     }
     $input->set('option', $config['option']);
     $input->set('view', $config['view']);
     $config['input'] = $input;
     $className = ucfirst($config['option']) . 'Dispatcher';
     if (!class_exists($className)) {
         $basePath = APATH_INSTALLATION;
         $searchPaths = array($basePath . '/' . $config['option'] . '/platform', $basePath . '/' . $config['option'] . '/platform/dispatchers', $basePath . '/' . $config['option'], $basePath . '/' . $config['option'] . '/dispatchers');
         if (array_key_exists('searchpath', $config)) {
             array_unshift($searchPaths, $config['searchpath']);
         }
         $path = AUtilsPath::find($searchPaths, 'dispatcher.php');
         if ($path) {
             require_once $path;
         }
     }
     if (!class_exists($className) && class_exists($className . 'Default')) {
         $className = $className . 'Default';
     } elseif (!class_exists($className)) {
         $className = 'ADispatcher';
     }
     $instance = new $className($config);
     return $instance;
 }
Exemplo n.º 2
0
 /**
  * Default task. Assigns a model to the view and asks the view to render
  * itself.
  */
 public function display()
 {
     $viewType = $this->input->getCmd('format', 'html');
     $view = $this->getThisView();
     $view->task = $this->task;
     $view->doTask = $this->doTask;
     // Get/Create the model
     if ($model = $this->getThisModel()) {
         // Push the model into the view (as default)
         $view->setModel($model, true);
     }
     // Set the layout
     $view->setLayout(is_null($this->layout) ? 'default' : $this->layout);
     // Display the view
     $view->display();
 }
Exemplo n.º 3
0
 /**
  * Sets an entire array of search paths for templates or resources.
  *
  * @param   string  $type  The type of path to set, typically 'template'.
  * @param   mixed   $path  The new search path, or an array of search paths.  If null or false, resets to the current directory only.
  *
  * @return  void
  *
  * @since   12.2
  */
 protected function _setPath($type, $path)
 {
     // Clear out the prior search dirs
     $this->_path[$type] = array();
     // Actually add the user-specified directories
     $this->_addPath($type, $path);
     // Always add the fallback directories as last resort
     switch (strtolower($type)) {
         case 'template':
             // Set the alternative template search dir
             $app = $this->container->application;
             $component = preg_replace('/[^A-Z0-9_\\.-]/i', '', $this->input->getCmd('option', ''));
             $fallback = APATH_THEMES . '/' . $app->getTemplate() . '/html/' . $component . '/' . $this->getName();
             $this->_addPath('template', $fallback);
             break;
     }
 }
Exemplo n.º 4
0
 /**
  * Returns current view object
  * @return FOFView The global instance of the view object (singleton)
  */
 public final function getThisView($config = array())
 {
     if (!is_object($this->viewObject)) {
         $prefix = null;
         $viewName = null;
         $viewType = null;
         $prefix = ucfirst($this->component) . 'View';
         if (!empty($this->viewName)) {
             $viewName = ucfirst($this->viewName);
         } else {
             $viewName = ucfirst($this->view);
         }
         $viewType = $this->input->getCmd('format', 'html');
         if (!array_key_exists('input', $config) || !$config['input'] instanceof AInput) {
             $config['input'] = $this->input;
         }
         $config['input']->set('base_path', $this->basePath);
         $this->viewObject = $this->getView($viewName, $viewType, $prefix, $config);
     }
     return $this->viewObject;
 }