Factory
Joomla Platform Factory class.
| since |
1.7.0 |
|---|---|
| package |
Joomla CMS |
Methods
createConfig
Create a configuration object
createConfig( file, type = 'PHP', namespace = '') : \Joomla\Registry\Registry
| 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
| since |
4.0.0 |
|---|
Response
Container
createDbo
Create a database object
createDbo() : \Joomla\Database\DatabaseDriver
| 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
createLanguage
Create a language object
createLanguage() : \Joomla\CMS\Language\Language
createMailer
Create a mailer object
createMailer() : \Joomla\CMS\Mail\Mail
getApplication
Get the global application object. When the global application doesn't exist, an exception is thrown.
getApplication() : \Joomla\CMS\Application\CMSApplicationInterface
getCache
Get a cache object
getCache( group = '', handler = 'callback', storage = null) : \Joomla\CMS\Cache\CacheController
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
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
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, seeJoomla\CMS\Toolbar\Toolbar::getInstance()as an example - An application front controller loading and executing the Joomla application class,
see the
cli/joomla.phpfile 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
getDbo
Get a database object.
getDbo() : \Joomla\Database\DatabaseDriver
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
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
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
Returns the global {@link Mail} object, only creating it if it doesn't already exist.
| see | |
|---|---|
| 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
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
getUser
Get a user object.
getUser( id = null) : \Joomla\CMS\User\User
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
config
Global configuration object
| 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
| since |
4.0.0 |
|---|
Type(s)
Container
dates
Container for Date instances
| since |
1.7.3 |
|---|
Type(s)
array<string|int, mixed>
session
Global session object
| 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
| 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
| 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
| 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