public
__construct
(mixed $config = array(), \Joomla\CMS\MVC\Factory\MVCFactoryInterface $factory = null, ?\Joomla\CMS\Application\CMSApplication $app = null, ?\Joomla\Input\Input $input = null)
/**
* Constructor.
*
* @param array $config An optional associative array of configuration settings.
* Recognized key values include 'name', 'default_task', 'model_path', and
* 'view_path' (this list is not meant to be comprehensive).
* @param MVCFactoryInterface $factory The factory.
* @param CMSApplication $app The Application for the dispatcher
* @param Input $input Input
*
* @since 3.0
*/
public function __construct($config = array(), MVCFactoryInterface $factory = null, ?CMSApplication $app = null, ?Input $input = null)
{
$this->methods = array();
$this->message = null;
$this->messageType = 'message';
$this->paths = array();
$this->redirect = null;
$this->taskMap = array();
$this->app = $app ?: Factory::getApplication();
$this->input = $input ?: $this->app->input;
if (\defined('JDEBUG') && JDEBUG) {
Log::addLogger(array('text_file' => 'jcontroller.log.php'), Log::ALL, array('controller'));
}
// Determine the methods to exclude from the base class.
$xMethods = get_class_methods('\\Joomla\\CMS\\MVC\\Controller\\BaseController');
// Get the public methods in this class using reflection.
$r = new \ReflectionClass($this);
$rMethods = $r->getMethods(\ReflectionMethod::IS_PUBLIC);
foreach ($rMethods as $rMethod) {
$mName = $rMethod->getName();
// Add default display method if not explicitly declared.
if ($mName === 'display' || !\in_array($mName, $xMethods)) {
$this->methods[] = strtolower($mName);
// Auto register the methods as tasks.
$this->taskMap[strtolower($mName)] = $mName;
}
}
// Set the view name
if (empty($this->name)) {
if (\array_key_exists('name', $config)) {
$this->name = $config['name'];
} else {
$this->name = $this->getName();
}
}
// Set a base path for use by the controller
if (\array_key_exists('base_path', $config)) {
$this->basePath = $config['base_path'];
} else {
$this->basePath = JPATH_COMPONENT;
}
// If the default task is set, register it as such
if (\array_key_exists('default_task', $config)) {
$this->registerDefaultTask($config['default_task']);
} else {
$this->registerDefaultTask('display');
}
// Set the models prefix
if (empty($this->model_prefix)) {
if (\array_key_exists('model_prefix', $config)) {
// User-defined prefix
$this->model_prefix = $config['model_prefix'];
} else {
$this->model_prefix = ucfirst($this->name) . 'Model';
}
}
// Set the default model search path
if (\array_key_exists('model_path', $config)) {
// User-defined dirs
$this->addModelPath($config['model_path'], $this->model_prefix);
} else {
$this->addModelPath($this->basePath . '/models', $this->model_prefix);
}
// Set the default view search path
if (\array_key_exists('view_path', $config)) {
// User-defined dirs
$this->setPath('view', $config['view_path']);
} else {
$this->setPath('view', $this->basePath . '/views');
}
// Set the default view.
if (\array_key_exists('default_view', $config)) {
$this->default_view = $config['default_view'];
} elseif (empty($this->default_view)) {
$this->default_view = $this->getName();
}
$this->factory = $factory ?: new LegacyFactory();
}