Пример #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;
 }
Пример #2
0
 /**
  * Load a helper file
  *
  * @param   string  $hlp  The name of the helper source file automatically searches the helper paths and compiles as needed.
  *
  * @return  void
  */
 public function loadHelper($hlp = null)
 {
     // Clean the file name
     $file = preg_replace('/[^A-Z0-9_\\.-]/i', '', $hlp);
     // Load the helper script
     $helper = AUtilsPath::find($this->_path['helper'], $this->_createFileName('helper', array('name' => $file)));
     if ($helper != false) {
         // Include the requested template filename in the local scope
         include_once $helper;
     }
 }
Пример #3
0
 /**
  * Returns a new model object. Unless overriden by the $config array, it will
  * try to automatically populate its state from the request variables.
  *
  * @param string $type
  * @param string $prefix
  * @param array $config
  * @return AModel
  */
 public static function &getAnInstance($type, $prefix = '', $config = array())
 {
     $type = preg_replace('/[^A-Z0-9_\\.-]/i', '', $type);
     $modelClass = $prefix . ucfirst($type);
     $modelClassAlt = $prefix . ucfirst($type) . 'Default';
     $result = false;
     // Guess the component name and include path
     if (!empty($prefix)) {
         preg_match('/(.*)Model$/', $prefix, $m);
         $component = strtolower($m[1]);
     } else {
         $component = '';
     }
     if (array_key_exists('input', $config)) {
         if (!$config['input'] instanceof AInput) {
             if (!is_array($config['input'])) {
                 $config['input'] = (array) $config['input'];
             }
             $config['input'] = array_merge($_REQUEST, $config['input']);
             $config['input'] = new AInput($config['input']);
         }
     } else {
         $config['input'] = new AInput();
     }
     if (empty($component)) {
         $defaultApp = AApplication::getInstance()->getName();
         $component = $config['input']->get('option', $defaultApp);
     }
     $config['option'] = $component;
     $needsAView = true;
     if (array_key_exists('view', $config)) {
         if (!empty($config['view'])) {
             $needsAView = false;
         }
     }
     if ($needsAView) {
         $config['view'] = strtolower($type);
     }
     $config['input']->set('option', $config['option']);
     $config['input']->set('view', $config['view']);
     // Try to load the requested model class
     if (!class_exists($modelClass)) {
         $include_paths = array(APATH_INSTALLATION . '/' . $component . '/platform/models', APATH_INSTALLATION . '/platform/models', APATH_INSTALLATION . '/' . $component . '/models');
         // Try to load the model file
         $path = AUtilsPath::find($include_paths, self::createFileName('model', array('name' => $type)));
         if ($path) {
             require_once $path;
         }
     }
     if (!class_exists($modelClass) && class_exists($modelClassAlt)) {
         $modelClass = $modelClassAlt;
     } elseif (!class_exists($modelClass)) {
         $modelClass = 'AModel';
     }
     $result = new $modelClass($config);
     return $result;
 }
Пример #4
0
 /**
  * Adds to the search path for templates and resources.
  *
  * @param   string  $type  The path type (e.g. 'model', 'view').
  * @param   mixed   $path  The directory string  or stream array to search.
  *
  * @return  AController  A JControllerLegacy object to support chaining.
  */
 protected function addPath($type, $path)
 {
     // Just force path to array
     settype($path, 'array');
     if (!isset($this->paths[$type])) {
         $this->paths[$type] = array();
     }
     // Loop through the path directories
     foreach ($path as $dir) {
         // No surrounding spaces allowed!
         $dir = rtrim(AUtilsPath::check($dir, '/'), '/') . '/';
         // Add to the top of the search dirs
         array_unshift($this->paths[$type], $dir);
     }
     return $this;
 }
Пример #5
0
 /**
  * Returns a new model object. Unless overriden by the $config array, it will
  * try to automatically populate its state from the request variables.
  *
  * @param string $type
  * @param string $prefix
  * @param array $config
  * @param   AContainer $container
  *
  * @return AModel
  */
 public static function &getAnInstance($type, $prefix = '', $config = array(), AContainer $container = null)
 {
     if (is_null($container)) {
         $container = AApplication::getInstance()->getContainer();
     }
     $type = preg_replace('/[^A-Z0-9_\\.-]/i', '', $type);
     $types = array(ANGIE_INSTALLER_NAME . $type, $type);
     $modelClass = '';
     $modelClassAlt = $prefix . ucfirst($type) . 'Default';
     // Guess the component name and include path
     if (!empty($prefix)) {
         preg_match('/(.*)Model$/', $prefix, $m);
         $component = strtolower($m[1]);
     } else {
         $component = '';
     }
     if (empty($component)) {
         $defaultApp = $container->application->getName();
         $component = $container->input->get('option', $defaultApp);
     }
     $config['option'] = $component;
     $needsAView = true;
     if (array_key_exists('view', $config)) {
         if (!empty($config['view'])) {
             $needsAView = false;
         }
     }
     if ($needsAView) {
         $config['view'] = strtolower($type);
     }
     $container->input->set('option', $config['option']);
     $container->input->set('view', $config['view']);
     foreach ($types as $currentType) {
         $modelClass = $prefix . ucfirst($currentType);
         // Try to load the requested model class
         if (!class_exists($modelClass)) {
             $include_paths = array(APATH_INSTALLATION . '/' . $component . '/platform/models', APATH_INSTALLATION . '/platform/models', APATH_INSTALLATION . '/' . $component . '/models');
             // Try to load the model file
             $path = AUtilsPath::find($include_paths, self::createFileName('model', array('name' => $currentType)));
             if ($path) {
                 require_once $path;
             }
         }
         if (class_exists($modelClass)) {
             break;
         }
     }
     if (!class_exists($modelClass) && class_exists($modelClassAlt)) {
         $modelClass = $modelClassAlt;
     } elseif (!class_exists($modelClass)) {
         $modelClass = 'AModel';
     }
     $result = new $modelClass($config, $container);
     return $result;
 }