Factory

Joomla Platform Factory class.

abstract
since

1.7.0

package

Joomla CMS

Methods

createConfig

Create a configuration object

createConfig( file,  type = 'PHP',  namespace = '') : \Joomla\Registry\Registry
static deprecated
see Registry
since

1.7.0

deprecated

4.0 will be removed in 6.0 Use the configuration object within the application. Example: Factory::getApplication->getConfig();

Arguments

file

stringThe path to the configuration file.

type

stringThe type of the configuration file.

namespace

stringThe namespace of the configuration file.

Response

Registry

createContainer

Create a container object

createContainer() : \Joomla\DI\Container
static
since

4.0.0

Response

Container

createDbo

Create a database object

createDbo() : \Joomla\Database\DatabaseDriver
static deprecated
see DatabaseDriver
since

1.7.0

deprecated

4.3 will be removed in 6.0 Use the database service in the DI container Example: Factory::getContainer()->get(DatabaseInterface::class);

Response

DatabaseDriver

createDocument

Create a document object

createDocument() : \Joomla\CMS\Document\Document
static deprecated
see Document
since

1.7.0

deprecated

4.0 will be removed in 6.0 Load the document service from the dependency injection container or via $app->getDocument() Example: Factory::getContainer()->get(FactoryInterface::class)->createDocument($type, $attributes);

Response

Documentobject

createLanguage

Create a language object

createLanguage() : \Joomla\CMS\Language\Language
static deprecated
see Language
since

1.7.0

deprecated

4.0 will be removed in 6.0 Load the language service from the dependency injection container or via $app->getLanguage() Example: Factory::getContainer()->get(LanguageFactoryInterface::class)->createLanguage($locale, $debug)

Response

Languageobject

createMailer

Create a mailer object

createMailer() : \Joomla\CMS\Mail\Mail
static deprecated
see Mail
since

1.7.0

deprecated

4.4.0 will be removed in 6.0 Use the mailer service in the DI container and create a mailer from there Example: Factory::getContainer()->get(MailerFactoryInterface::class)->createMailer();

Response

Mailobject

getApplication

Get the global application object. When the global application doesn't exist, an exception is thrown.

getApplication() : \Joomla\CMS\Application\CMSApplicationInterface
static
since

1.7.0

throws

Exception

Response

CMSApplicationInterfaceobject

getCache

Get a cache object

getCache( group = '',  handler = 'callback',  storage = null) : \Joomla\CMS\Cache\CacheController
static deprecated

Returns the global {@link CacheController} object

see Cache
since

1.7.0

deprecated

4.3 will be removed in 6.0 Use the cache controller factory instead Example: Factory::getContainer()->get(CacheControllerFactoryInterface::class)->createCacheController($handler, $options);

Arguments

group

stringThe cache group name

handler

stringThe handler to use

storage

stringThe storage method

Response

CacheControllerobject

getConfig

Get a configuration object

getConfig( file = null,  type = 'PHP',  namespace = '') : \Joomla\Registry\Registry
static deprecated

Returns the global {@link \JConfig} object, only creating it if it doesn't already exist.

see Registry
since

1.7.0

deprecated

4.3 will be removed in 6.0 Use the configuration object within the application Example: Factory::getApplication->getConfig();

Arguments

file

stringThe path to the configuration file

type

stringThe type of the configuration file

namespace

stringThe namespace of the configuration file

Response

Registry

getContainer

Get a container object

getContainer() : \Joomla\DI\Container
static

Returns the global service container object, only creating it if it doesn't already exist.

This method is only suggested for use in code whose responsibility is to create new services and needs to be able to resolve the dependencies, and should therefore only be used when the container is not accessible by other means. Valid uses of this method include:

  • A static getInstance() method calling a factory service from the container, see Joomla\CMS\Toolbar\Toolbar::getInstance() as an example
  • An application front controller loading and executing the Joomla application class, see the cli/joomla.php file as an example
  • Retrieving optional constructor dependencies when not injected into a class during a transitional period to retain backward compatibility, in this case a deprecation notice should also be emitted to notify developers of changes needed in their code

This method is not suggested for use as a one-for-one replacement of static calls, such as replacing calls to Factory::getDbo() with calls to Factory::getContainer()->get(DatabaseInterface::class), code should be refactored to support dependency injection instead of making this change.

since

4.0.0

Response

Container

getDate

Return the {@link Date} object

getDate( time = 'now',  tzOffset = null) : \Joomla\CMS\Date\Date
static
see Date
since

1.7.0

Arguments

time

mixedThe initial time for the Date object

tzOffset

mixedThe timezone offset.

Response

Dateobject

getDbo

Get a database object.

getDbo() : \Joomla\Database\DatabaseDriver
static deprecated

Returns the global {@link DatabaseDriver} object, only creating it if it doesn't already exist.

see DatabaseDriver
since

1.7.0

deprecated

4.3 will be removed in 6.0 Use the database service in the DI container Example: Factory::getContainer()->get(DatabaseInterface::class);

Response

DatabaseDriver

getDocument

Get a document object.

getDocument() : \Joomla\CMS\Document\Document
static deprecated

Returns the global {@link \Joomla\CMS\Document\Document} object, only creating it if it doesn't already exist.

see Document
since

1.7.0

deprecated

4.3 will be removed in 6.0 Use the document service in the DI container or get from the application object Example: Factory::getApplication()->getDocument();

Response

Documentobject

getLanguage

Get a language object.

getLanguage() : \Joomla\CMS\Language\Language
static deprecated

Returns the global {@link Language} object, only creating it if it doesn't already exist.

see Language
since

1.7.0

deprecated

4.3 will be removed in 6.0 Use the language service in the DI container or get from the application object Example: Factory::getApplication()->getLanguage();

Response

Languageobject

getMailer

Get a mailer object.

getMailer() : \Joomla\CMS\Mail\Mail
static deprecated

Returns the global {@link Mail} object, only creating it if it doesn't already exist.

see Mail
since

1.7.0

deprecated

4.4.0 will be removed in 6.0 Use the mailer service in the DI container and create a mailer from there Example: Factory::getContainer()->get(MailerFactoryInterface::class)->createMailer();

Response

Mailobject

getSession

Get a session object.

getSession(mixed||string|int options = []) : \Joomla\CMS\Session\Session
static deprecated

Returns the global {@link Session} object, only creating it if it doesn't already exist.

see Session
since

1.7.0

deprecated

4.3 will be removed in 6.0 Use the session service in the DI container or get from the application object Example: Factory::getApplication()->getSession();

Arguments

options

array<string|int, mixed>An array containing session options

Response

Sessionobject

getStream

Creates a new stream object with appropriate prefix

getStream( usePrefix = true,  useNetwork = true,  userAgentSuffix = 'Joomla',  maskUserAgent = false) : \Joomla\CMS\Filesystem\Stream
static
see Stream
since

1.7.0

Arguments

usePrefix

boolPrefix the connections for writing

useNetwork

boolUse network if available for writing; use false to disable (e.g. FTP, SCP)

userAgentSuffix

stringString to append to user agent

maskUserAgent

boolUser agent masking (prefix Mozilla)

Response

Stream

getUser

Get a user object.

getUser( id = null) : \Joomla\CMS\User\User
static deprecated

Returns the global {@link User} object, only creating it if it doesn't already exist.

see User
since

1.7.0

deprecated

4.3 will be removed in 6.0 Load the user service from the dependency injection container or get from the application object Example: Factory::getApplication()->getIdentity();

Arguments

id

intThe user to load - Can be an integer or string - If string, it is converted to ID automatically.

Response

Userobject

Properties

application

Global application object

static
since

1.7.0

Type(s)

CMSApplicationInterface

cache

Global cache object

static
since

1.7.0

Type(s)

Cache

config

Global configuration object

static deprecated
since

1.7.0

deprecated

4.3 will be removed in 6.0 Use the configuration object within the application Example: Factory::getApplication()->getConfig();

Type(s)

JConfig

container

Global container object

static
since

4.0.0

Type(s)

Container

dates

Container for Date instances

static
since

1.7.3

Type(s)

array<string|int, mixed>

session

Global session object

static deprecated
since

1.7.0

deprecated

4.3 will be removed in 6.0 Use the session service in the DI container or get from the application object Example: Factory::getApplication()->getSession();

Type(s)

Session

language

Global language object

static deprecated
since

1.7.0

deprecated

4.3 will be removed in 6.0 Use the language service in the DI container or get from the application object Example: Factory::getApplication()->getLanguage();

Type(s)

Language

document

Global document object

static deprecated
since

1.7.0

deprecated

4.3 will be removed in 6.0 Use the document service in the DI container or get from the application object Example: Factory::getApplication()->getDocument();

Type(s)

Document

database

Global database object

static deprecated
since

1.7.0

deprecated

4.3 will be removed in 6.0 Use the database service in the DI container Example: Factory::getContainer()->get(DatabaseInterface::class);

Type(s)

DatabaseDriver

mailer

Global mailer object

static
since

1.7.0

Type(s)

Mail