Back to CMSPlugin class

Method __construct

public
__construct
(mixed &$subject, mixed $config = array())
Constructor
Parameters
  • \Joomla\Event\DispatcherInterface & $subject The object to observe
  • array $config An optional associative array of configuration settings. Recognized key values include 'name', 'group', 'params', 'language' (this list is not meant to be comprehensive).
Since
  • 1.5
Class: CMSPlugin
Project: Joomla

Method __construct - Source code

/**
 * Constructor
 *
 * @param   DispatcherInterface  &$subject  The object to observe
 * @param   array                $config    An optional associative array of configuration settings.
 *                                          Recognized key values include 'name', 'group', 'params', 'language'
 *                                         (this list is not meant to be comprehensive).
 *
 * @since   1.5
 */
public function __construct(&$subject, $config = array())
{
    // Get the parameters.
    if (isset($config['params'])) {
        if ($config['params'] instanceof Registry) {
            $this->params = $config['params'];
        } else {
            $this->params = new Registry($config['params']);
        }
    }
    // Get the plugin name.
    if (isset($config['name'])) {
        $this->_name = $config['name'];
    }
    // Get the plugin type.
    if (isset($config['type'])) {
        $this->_type = $config['type'];
    }
    // Load the language files if needed.
    if ($this->autoloadLanguage) {
        $this->loadLanguage();
    }
    if (property_exists($this, 'app')) {
        $reflection = new \ReflectionClass($this);
        $appProperty = $reflection->getProperty('app');
        if ($appProperty->isPrivate() === false && \is_null($this->app)) {
            $this->app = Factory::getApplication();
        }
    }
    if (property_exists($this, 'db')) {
        $reflection = new \ReflectionClass($this);
        $dbProperty = $reflection->getProperty('db');
        if ($dbProperty->isPrivate() === false && \is_null($this->db)) {
            $this->db = Factory::getDbo();
        }
    }
    // Set the dispatcher we are to register our listeners with
    $this->setDispatcher($subject);
}