Source for file factory.php
Documentation is available at factory.php
* @package Joomla.Platform
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
* Joomla Platform Factory class
* @package Joomla.Platform
* Global application object
public static $application =
null;
public static $cache =
null;
* Global configuraiton object
public static $config =
null;
* Container for JDate instances
public static $dates =
array();
public static $session =
null;
public static $language =
null;
public static $document =
null;
* @deprecated 13.3 (Platform) & 4.0 (CMS)
public static $acl =
null;
public static $database =
null;
public static $mailer =
null;
* Get a application object.
* Returns the global {@link JApplicationCms} object, only creating it if it doesn't already exist.
* @param mixed $id A client identifier or name.
* @param array $config An optional associative array of configuration settings.
* @param string $prefix Application prefix
* @return JApplicationCms object
public static function getApplication($id =
null, array $config =
array(), $prefix =
'J')
throw
new Exception('Application Instantiation Error', 500);
self::$application =
JApplicationCms::getInstance($id);
return self::$application;
* Get a configuration object
* Returns the global {@link JRegistry} object, only creating it if it doesn't already exist.
* @param string $file The path to the configuration file
* @param string $type The type of the configuration file
* @param string $namespace The namespace of the configuration file
public static function getConfig($file =
null, $type =
'PHP', $namespace =
'')
self::$config =
self::createConfig($file, $type, $namespace);
* Returns the global {@link JSession} object, only creating it if it doesn't already exist.
* @param array $options An array containing session options
* @return JSession object
public static function getSession(array $options =
array())
self::$session =
self::createSession($options);
* Returns the global {@link JLanguage} object, only creating it if it doesn't already exist.
* @return JLanguage object
self::$language =
self::createLanguage();
* Returns the global {@link JDocument} object, only creating it if it doesn't already exist.
* @return JDocument object
self::$document =
self::createDocument();
* Returns the global {@link JUser} object, only creating it if it doesn't already exist.
* @param integer $id The user to load - Can be an integer or string - If string, it is converted to ID automatically.
public static function getUser($id =
null)
$instance =
self::getSession()->get('user');
if (!($instance instanceof
JUser))
elseif ($instance->id !=
$id)
* Returns the global {@link JCache} object
* @param string $group The cache group name
* @param string $handler The handler to use
* @param string $storage The storage method
* @return JCacheController object
public static function getCache($group =
'', $handler =
'callback', $storage =
null)
$hash =
md5($group .
$handler .
$storage);
if (isset
(self::$cache[$hash]))
return self::$cache[$hash];
$handler =
($handler ==
'function') ?
'callback' :
$handler;
$options =
array('defaultgroup' =>
$group);
$options['storage'] =
$storage;
$cache =
JCache::getInstance($handler, $options);
self::$cache[$hash] =
$cache;
return self::$cache[$hash];
* Get an authorization object
* Returns the global {@link JAccess} object, only creating it
* if it doesn't already exist.
* @deprecated 13.3 (Platform) & 4.0 (CMS) - Use JAccess directly.
public static function getACL()
JLog::add(__METHOD__ .
' is deprecated. Use JAccess directly.', JLog::WARNING, 'deprecated');
self::$acl =
new JAccess;
* Returns the global {@link JDatabaseDriver} object, only creating it if it doesn't already exist.
* @return JDatabaseDriver
public static function getDbo()
self::$database =
self::createDbo();
* Returns the global {@link JMail} object, only creating it if it doesn't already exist.
self::$mailer =
self::createMailer();
$copy =
clone self::$mailer;
* Get a parsed XML Feed Source
* @param string $url Url for feed source.
* @param integer $cache_time Time to cache feed for (using internal cache mechanism).
* @return mixed SimplePie parsed object on success, false on failure.
* @throws BadMethodCallException
* @deprecated 4.0 Use directly JFeedFactory or supply SimplePie instead. Mehod will be proxied to JFeedFactory beginning in 3.2
if (!class_exists('JSimplepieFactory'))
throw
new BadMethodCallException('JSimplepieFactory not found');
JLog::add(__METHOD__ .
' is deprecated. Use JFeedFactory() or supply SimplePie instead.', JLog::WARNING, 'deprecated');
* @param string $data Full path and file name.
* @param boolean $isFile true to load a file or false to load a string.
* @return mixed JXMLElement or SimpleXMLElement on success or false on error.
* @note When JXMLElement is not present a SimpleXMLElement will be returned.
* @deprecated 13.3 (Platform) & 4.0 (CMS) - Use SimpleXML directly.
public static function getXML($data, $isFile =
true)
JLog::add(__METHOD__ .
' is deprecated. Use SimpleXML directly.', JLog::WARNING, 'deprecated');
$class =
'SimpleXMLElement';
// Disable libxml errors and allow to fetch error information as needed
// Try to load the XML file
// Try to load the XML string
* @param string $editor The editor to load, depends on the editor plugins that are installed
* @return JEditor instance of JEditor
* @throws BadMethodCallException
* @deprecated 12.3 (Platform) & 4.0 (CMS) - Use JEditor directly
public static function getEditor($editor =
null)
JLog::add(__METHOD__ .
' is deprecated. Use JEditor directly.', JLog::WARNING, 'deprecated');
throw
new BadMethodCallException('JEditor not found');
// Get the editor configuration setting
$conf =
self::getConfig();
$editor =
$conf->get('editor');
* Return a reference to the {@link JUri} object
* @param string $uri Uri name.
* @deprecated 13.3 (Platform) & 4.0 (CMS) - Use JUri directly.
public static function getURI($uri =
'SERVER')
JLog::add(__METHOD__ .
' is deprecated. Use JUri directly.', JLog::WARNING, 'deprecated');
* Return the {@link JDate} object
* @param mixed $time The initial time for the JDate object
* @param mixed $tzOffset The timezone offset.
public static function getDate($time =
'now', $tzOffset =
null)
$language =
self::getLanguage();
$locale =
$language->getTag();
if (!isset
($classname) ||
$locale !=
$mainLocale)
// Store the locale for future reference
if ($mainLocale !==
false)
$classname =
str_replace('-', '_', $mainLocale) .
'Date';
// The class does not exist, default to JDate
// No tag, so default to JDate
$key =
$time .
'-' .
($tzOffset instanceof
DateTimeZone ?
$tzOffset->getName() : (string)
$tzOffset);
if (!isset
(self::$dates[$classname][$key]))
self::$dates[$classname][$key] =
new $classname($time, $tzOffset);
$date =
clone self::$dates[$classname][$key];
* Create a configuration object
* @param string $file The path to the configuration file.
* @param string $type The type of the configuration file.
* @param string $namespace The namespace of the configuration file.
protected static function createConfig($file, $type =
'PHP', $namespace =
'')
// Create the registry with a default namespace of config
// Sanitize the namespace.
// Build the config name.
$name =
'JConfig' .
$namespace;
// Handle the PHP configuration type.
// Create the JConfig object
// Load the configuration values into the registry
$registry->loadObject($config);
* Create a session object
* @param array $options An array containing session options
* @return JSession object
protected static function createSession(array $options =
array())
// Get the editor configuration setting
$conf =
self::getConfig();
$handler =
$conf->get('session_handler', 'none');
// Config time is in minutes
$options['expire'] =
($conf->get('lifetime')) ?
$conf->get('lifetime') *
60 :
900;
if ($session->getState() ==
'expired')
* Create an database object
* @return JDatabaseDriver
$conf =
self::getConfig();
$host =
$conf->get('host');
$user =
$conf->get('user');
$password =
$conf->get('password');
$database =
$conf->get('db');
$prefix =
$conf->get('dbprefix');
$driver =
$conf->get('dbtype');
$debug =
$conf->get('debug');
$options =
array('driver' =>
$driver, 'host' =>
$host, 'user' =>
$user, 'password' =>
$password, 'database' =>
$database, 'prefix' =>
$prefix);
catch
(RuntimeException $e)
header('HTTP/1.1 500 Internal Server Error');
jexit('Database Error: ' .
$e->getMessage());
$conf =
self::getConfig();
$smtpauth =
($conf->get('smtpauth') ==
0) ?
null :
1;
$smtpuser =
$conf->get('smtpuser');
$smtppass =
$conf->get('smtppass');
$smtphost =
$conf->get('smtphost');
$smtpsecure =
$conf->get('smtpsecure');
$smtpport =
$conf->get('smtpport');
$mailfrom =
$conf->get('mailfrom');
$fromname =
$conf->get('fromname');
$mailer =
$conf->get('mailer');
// Set default sender without Reply-to
// Default mailer is to use PHP's mail function
$mail->useSMTP($smtpauth, $smtphost, $smtpuser, $smtppass, $smtpsecure, $smtpport);
* Create a language object
* @return JLanguage object
$conf =
self::getConfig();
$locale =
$conf->get('language');
$debug =
$conf->get('debug_lang');
* Create a document object
* @return JDocument object
$lang =
self::getLanguage();
$input =
self::getApplication()->input;
$type =
$input->get('format', 'html', 'word');
'language' =>
$lang->getTag(),
'direction' =>
$lang->isRTL() ?
'rtl' :
'ltr',
'mediaversion' =>
$version->getMediaVersion()
* Creates a new stream object with appropriate prefix
* @param boolean $use_prefix Prefix the connections for writing
* @param boolean $use_network Use network if available for writing; use false to disable (e.g. FTP, SCP)
* @param string $ua UA User agent to use
* @param boolean $uamask User agent masking (prefix Mozilla)
public static function getStream($use_prefix =
true, $use_network =
true, $ua =
null, $uamask =
false)
jimport('joomla.filesystem.stream');
// Setup the context; Joomla! UA and overwrite
// Set the UA for HTTP and overwrite for FTP
$context['http']['user_agent'] =
$version->getUserAgent($ua, $uamask);
$context['ftp']['overwrite'] =
true;
if ($FTPOptions['enabled'] ==
1 &&
$use_network)
$prefix =
'ftp://' .
$FTPOptions['user'] .
':' .
$FTPOptions['pass'] .
'@' .
$FTPOptions['host'];
$prefix .=
$FTPOptions['port'] ?
':' .
$FTPOptions['port'] :
'';
$prefix .=
$FTPOptions['root'];
elseif ($SCPOptions['enabled'] ==
1 &&
$use_network)
$prefix =
'ssh2.sftp://' .
$SCPOptions['user'] .
':' .
$SCPOptions['pass'] .
'@' .
$SCPOptions['host'];
$prefix .=
$SCPOptions['port'] ?
':' .
$SCPOptions['port'] :
'';
$prefix .=
$SCPOptions['root'];
$retval =
new JStream('', '', $context);
Documentation generated on Tue, 19 Nov 2013 15:02:49 +0100 by phpDocumentor 1.4.3