Beispiel #1
0
 /**
  * Constructor
  *
  * @param   DispatcherInterface  $dispatcher  The event dispatcher we're going to use
  *
  * @since   11.1
  */
 public function __construct(DispatcherInterface $dispatcher = null)
 {
     // Set the dispatcher
     if (!is_object($dispatcher)) {
         $dispatcher = JFactory::getContainer()->get('dispatcher');
     }
     $this->setDispatcher($dispatcher);
     $isLoaded = JPluginHelper::importPlugin('authentication');
     if (!$isLoaded) {
         JLog::add(JText::_('JLIB_USER_ERROR_AUTHENTICATION_LIBRARIES'), JLog::WARNING, 'jerror');
     }
 }
Beispiel #2
0
 /**
  * Get a renderer instance for the given type
  *
  * @param   string  $type  The type of renderer to fetch
  *
  * @return  static
  *
  * @since   4.0
  * @throws  \InvalidArgumentException
  */
 public static function getRenderer($type)
 {
     // Build the class name
     $class = __NAMESPACE__ . '\\Renderer\\' . ucfirst(strtolower($type)) . 'Renderer';
     // First check if an object may exist in the container and prefer that over everything else
     if (\JFactory::getContainer()->exists($class)) {
         return \JFactory::getContainer()->get($class);
     }
     // Next check if a local class exists and use that
     if (class_exists($class)) {
         return new $class();
     }
     // 404 Resource Not Found
     throw new \InvalidArgumentException(sprintf('There is not a error renderer for the "%s" format.', $type));
 }
Beispiel #3
0
 /**
  * Returns a JPathway object
  *
  * @param   string  $client   The name of the client
  * @param   array   $options  An associative array of options
  *
  * @return  JPathway  A JPathway object.
  *
  * @since   1.5
  * @throws  RuntimeException
  */
 public static function getInstance($client, $options = array())
 {
     if (empty(self::$instances[$client])) {
         // Create a JPathway object
         $classname = 'JPathway' . ucfirst($client);
         if (!class_exists($classname)) {
             throw new RuntimeException(JText::sprintf('JLIB_APPLICATION_ERROR_PATHWAY_LOAD', $client), 500);
         }
         // Check for a possible service from the container otherwise manually instantiate the class
         if (JFactory::getContainer()->exists($classname)) {
             self::$instances[$client] = JFactory::getContainer()->get($classname);
         } else {
             self::$instances[$client] = new $classname($options);
         }
     }
     return self::$instances[$client];
 }
Beispiel #4
0
 /**
  * Static method to get an instance of a JTable class if it can be found in the table include paths.
  *
  * To add include paths for searching for JTable classes see JTable::addIncludePath().
  *
  * @param   string  $type    The type (name) of the JTable class to get an instance of.
  * @param   string  $prefix  An optional prefix for the table class name.
  * @param   array   $config  An optional array of configuration values for the JTable object.
  *
  * @return  JTable|boolean   A JTable object if found or boolean false on failure.
  *
  * @since   11.1
  */
 public static function getInstance($type, $prefix = 'JTable', $config = array())
 {
     // Sanitize and prepare the table class name.
     $type = preg_replace('/[^A-Z0-9_\\.-]/i', '', $type);
     $tableClass = $prefix . ucfirst($type);
     // Only try to load the class if it doesn't already exist.
     if (!class_exists($tableClass)) {
         // Search for the class file in the JTable include paths.
         jimport('joomla.filesystem.path');
         $paths = self::addIncludePath();
         $pathIndex = 0;
         while (!class_exists($tableClass) && $pathIndex < count($paths)) {
             if ($tryThis = JPath::find($paths[$pathIndex++], strtolower($type) . '.php')) {
                 // Import the class file.
                 include_once $tryThis;
             }
         }
         if (!class_exists($tableClass)) {
             /*
              * If unable to find the class file in the JTable include paths. Return false.
              * The warning JLIB_DATABASE_ERROR_NOT_SUPPORTED_FILE_NOT_FOUND has been removed in 3.6.3.
              * In 4.0 an Exception (type to be determined) will be thrown.
              * For more info see https://github.com/joomla/joomla-cms/issues/11570
              */
             return false;
         }
     }
     // If a database object was passed in the configuration array use it, otherwise get the global one from JFactory.
     $db = isset($config['dbo']) ? $config['dbo'] : JFactory::getDbo();
     // Check for a possible service from the container otherwise manually instantiate the class
     if (JFactory::getContainer()->exists($tableClass)) {
         return JFactory::getContainer()->get($tableClass);
     }
     // Instantiate a new table class and return it.
     return new $tableClass($db);
 }
Beispiel #5
0
 /**
  * Returns a Model object, always creating it
  *
  * @param   string  $type    The model type to instantiate
  * @param   string  $prefix  Prefix for the model class name. Optional.
  * @param   array   $config  Configuration array for model. Optional.
  *
  * @return  JModelLegacy|boolean   A JModelLegacy instance or false on failure
  *
  * @since   12.2
  */
 public static function getInstance($type, $prefix = '', $config = array())
 {
     $type = preg_replace('/[^A-Z0-9_\\.-]/i', '', $type);
     $modelClass = $prefix . ucfirst($type);
     if (!class_exists($modelClass)) {
         jimport('joomla.filesystem.path');
         $path = JPath::find(self::addIncludePath(null, $prefix), self::_createFileName('model', array('name' => $type)));
         if (!$path) {
             $path = JPath::find(self::addIncludePath(null, ''), self::_createFileName('model', array('name' => $type)));
         }
         if (!$path) {
             return false;
         }
         require_once $path;
         if (!class_exists($modelClass)) {
             JLog::add(JText::sprintf('JLIB_APPLICATION_ERROR_MODELCLASS_NOT_FOUND', $modelClass), JLog::WARNING, 'jerror');
             return false;
         }
     }
     // Check for a possible service from the container otherwise manually instantiate the class
     if (JFactory::getContainer()->exists($modelClass)) {
         return JFactory::getContainer()->get($modelClass);
     }
     return new $modelClass($config);
 }
Beispiel #6
0
 /**
  * Method to load and return a view object. This method first looks in the
  * current template directory for a match and, failing that, uses a default
  * set path to load the view class file.
  *
  * Note the "name, prefix, type" order of parameters, which differs from the
  * "name, type, prefix" order used in related public methods.
  *
  * @param   string  $name    The name of the view.
  * @param   string  $prefix  Optional prefix for the view class name.
  * @param   string  $type    The type of view.
  * @param   array   $config  Configuration array for the view. Optional.
  *
  * @return  JViewLegacy|null  View object on success; null or error result on failure.
  *
  * @since   12.2
  * @throws  Exception
  */
 protected function createView($name, $prefix = '', $type = '', $config = array())
 {
     // Clean the view name
     $viewName = preg_replace('/[^A-Z0-9_]/i', '', $name);
     $classPrefix = preg_replace('/[^A-Z0-9_]/i', '', $prefix);
     $viewType = preg_replace('/[^A-Z0-9_]/i', '', $type);
     // Build the view class name
     $viewClass = $classPrefix . $viewName;
     if (!class_exists($viewClass)) {
         jimport('joomla.filesystem.path');
         $path = JPath::find($this->paths['view'], $this->createFileName('view', array('name' => $viewName, 'type' => $viewType)));
         if (!$path) {
             return null;
         }
         require_once $path;
         if (!class_exists($viewClass)) {
             throw new Exception(JText::sprintf('JLIB_APPLICATION_ERROR_VIEW_CLASS_NOT_FOUND', $viewClass, $path), 500);
         }
     }
     // Check for a possible service from the container otherwise manually instantiate the class
     if (JFactory::getContainer()->exists($viewClass)) {
         return JFactory::getContainer()->get($viewClass);
     }
     return new $viewClass($config);
 }
Beispiel #7
0
 /**
  * Returns a reference to a JCategories object
  *
  * @param   string  $extension  Name of the categories extension
  * @param   array   $options    An array of options
  *
  * @return  JCategories|false  JCategories object
  *
  * @since   11.1
  */
 public static function getInstance($extension, $options = array())
 {
     $hash = md5($extension . serialize($options));
     if (isset(self::$instances[$hash])) {
         return self::$instances[$hash];
     }
     $parts = explode('.', $extension);
     $component = 'com_' . strtolower($parts[0]);
     $section = count($parts) > 1 ? $parts[1] : '';
     $classname = ucfirst(substr($component, 4)) . ucfirst($section) . 'Categories';
     if (!class_exists($classname)) {
         $path = JPATH_SITE . '/components/' . $component . '/helpers/category.php';
         if (!is_file($path)) {
             return false;
         }
         include_once $path;
     }
     // Check for a possible service from the container otherwise manually instantiate the class
     if (JFactory::getContainer()->exists($classname)) {
         self::$instances[$hash] = JFactory::getContainer()->get($classname);
     } else {
         self::$instances[$hash] = new $classname($options);
     }
     return self::$instances[$hash];
 }
Beispiel #8
0
 /**
  * Returns the global JDocument object, only creating it
  * if it doesn't already exist.
  *
  * @param   string  $type        The document type to instantiate
  * @param   array   $attributes  Array of attributes
  *
  * @return  object  The document object.
  *
  * @since   11.1
  * @todo    This should allow custom class prefixes to be configured somehow
  */
 public static function getInstance($type = 'html', $attributes = array())
 {
     $signature = serialize(array($type, $attributes));
     if (empty(self::$instances[$signature])) {
         $type = preg_replace('/[^A-Z0-9_\\.-]/i', '', $type);
         $ntype = null;
         // Determine the path and class
         $class = 'JDocument' . ucfirst($type);
         if (!class_exists($class)) {
             // @deprecated 4.0 - JDocument objects should be autoloaded instead
             $path = __DIR__ . '/' . $type . '/' . $type . '.php';
             if (file_exists($path)) {
                 JLog::add('Non-autoloadable JDocument subclasses are deprecated, support will be removed in 4.0.', JLog::WARNING, 'deprecated');
                 require_once $path;
             } else {
                 $ntype = $type;
                 $class = 'JDocumentRaw';
             }
         }
         // Check for a possible service from the container otherwise manually instantiate the class
         if (JFactory::getContainer()->exists($class)) {
             $instance = JFactory::getContainer()->get($class);
         } else {
             $instance = new $class($attributes);
         }
         self::$instances[$signature] = $instance;
         if (!is_null($ntype)) {
             // Set the type to the Document type originally requested
             $instance->setType($ntype);
         }
     }
     return self::$instances[$signature];
 }
Beispiel #9
0
 /**
  * Get a file compression adapter.
  *
  * @param   string  $type  The type of adapter (bzip2|gzip|tar|zip).
  *
  * @return  JArchiveExtractable  Adapter for the requested type
  *
  * @since   11.1
  * @throws  UnexpectedValueException
  * @todo    This should allow custom class prefixes to be configured somehow
  */
 public static function getAdapter($type)
 {
     if (!isset(self::$adapters[$type])) {
         // Try to load the adapter object
         $class = 'JArchive' . ucfirst($type);
         if (!class_exists($class)) {
             throw new UnexpectedValueException('Unable to load archive', 500);
         }
         // Check for a possible service from the container otherwise manually instantiate the class
         if (JFactory::getContainer()->exists($class)) {
             self::$adapters[$type] = JFactory::getContainer()->get($class);
         } else {
             self::$adapters[$type] = new $class();
         }
     }
     return self::$adapters[$type];
 }
Beispiel #10
0
 /**
  * Loads a button type.
  *
  * @param   string   $type  Button Type
  * @param   boolean  $new   False by default
  *
  * @return  boolean
  *
  * @since   1.5
  */
 public function loadButtonType($type, $new = false)
 {
     $signature = md5($type);
     if (isset($this->_buttons[$signature]) && $new === false) {
         return $this->_buttons[$signature];
     }
     if (!class_exists('JToolbarButton')) {
         JLog::add(JText::_('JLIB_HTML_BUTTON_BASE_CLASS'), JLog::WARNING, 'jerror');
         return false;
     }
     $buttonClass = 'JToolbarButton' . ucfirst($type);
     if (!class_exists($buttonClass)) {
         if (isset($this->_buttonPath)) {
             $dirs = $this->_buttonPath;
         } else {
             $dirs = array();
         }
         $file = JFilterInput::getInstance()->clean(str_replace('_', DIRECTORY_SEPARATOR, strtolower($type)) . '.php', 'path');
         jimport('joomla.filesystem.path');
         if ($buttonFile = JPath::find($dirs, $file)) {
             include_once $buttonFile;
         } else {
             JLog::add(JText::sprintf('JLIB_HTML_BUTTON_NO_LOAD', $buttonClass, $buttonFile), JLog::WARNING, 'jerror');
             return false;
         }
     }
     if (!class_exists($buttonClass)) {
         // @todo remove code: return	JError::raiseError('SOME_ERROR_CODE', "Module file $buttonFile does not contain class $buttonClass.");
         return false;
     }
     // Check for a possible service from the container otherwise manually instantiate the class
     if (JFactory::getContainer()->exists($buttonClass)) {
         $this->_buttons[$signature] = JFactory::getContainer()->get($buttonClass);
     } else {
         $this->_buttons[$signature] = new $buttonClass($this);
     }
     return $this->_buttons[$signature];
 }
Beispiel #11
0
 /**
  * Returns a reference to a cache adapter object, always creating it
  *
  * @param   string  $type     The cache object type to instantiate; default is output.
  * @param   array   $options  Array of options
  *
  * @return  JCacheController
  *
  * @since   11.1
  * @throws  RuntimeException
  */
 public static function getInstance($type = 'output', $options = array())
 {
     self::addIncludePath(JPATH_PLATFORM . '/joomla/cache/controller');
     $type = strtolower(preg_replace('/[^A-Z0-9_\\.-]/i', '', $type));
     $class = 'JCacheController' . ucfirst($type);
     if (!class_exists($class)) {
         // Search for the class file in the JCache include paths.
         jimport('joomla.filesystem.path');
         $path = JPath::find(self::addIncludePath(), strtolower($type) . '.php');
         if ($path === false) {
             throw new RuntimeException('Unable to load Cache Controller: ' . $type, 500);
         }
         include_once $path;
         // The class should now be loaded
         if (!class_exists($class)) {
             throw new RuntimeException('Unable to load Cache Controller: ' . $type, 500);
         }
     }
     // Check for a possible service from the container otherwise manually instantiate the class
     if (JFactory::getContainer()->exists($class)) {
         return JFactory::getContainer()->get($class);
     }
     return new $class($options);
 }
Beispiel #12
0
 /**
  * Method to load an adapter instance
  *
  * @param   string  $adapter  Adapter name
  * @param   array   $options  Adapter options
  *
  * @return  JInstallerAdapter
  *
  * @since   3.4
  * @throws  InvalidArgumentException
  */
 public function loadAdapter($adapter, $options = array())
 {
     $class = $this->_classprefix . ucfirst($adapter);
     if (!class_exists($class)) {
         throw new InvalidArgumentException(sprintf('The %s install adapter does not exist.', $adapter));
     }
     // Ensure the adapter type is part of the options array
     $options['type'] = $adapter;
     // Check for a possible service from the container otherwise manually instantiate the class
     if (JFactory::getContainer()->exists($class)) {
         return JFactory::getContainer()->get($class);
     }
     return new $class($this, $this->getDbo(), $options);
 }
Beispiel #13
0
 /**
  * Set an adapter by name
  *
  * @param   string  $name      Adapter name
  * @param   object  &$adapter  Adapter object
  * @param   array   $options   Adapter options
  *
  * @return  boolean  True if successful
  *
  * @since   11.1
  */
 public function setAdapter($name, &$adapter = null, $options = array())
 {
     if (is_object($adapter)) {
         $this->_adapters[$name] =& $adapter;
         return true;
     }
     // Assemble the class name for the requested adapter
     $class = $this->_classprefix . ucfirst($name);
     if (!class_exists($class)) {
         $fullpath = $this->_basepath . '/' . $this->_adapterfolder . '/' . strtolower($name) . '.php';
         if (!file_exists($fullpath)) {
             return false;
         }
         // Try to load the adapter object
         require_once $fullpath;
         // The class should now be loaded
         if (!class_exists($class)) {
             return false;
         }
     }
     // Check for a possible service from the container otherwise manually instantiate the class
     if (JFactory::getContainer()->exists($class)) {
         $this->_adapters[$name] = JFactory::getContainer()->get($class);
     } else {
         $this->_adapters[$name] = new $class($this, $this->_db, $options);
     }
     return true;
 }