/**
* Constructor
*
* @param array $config An array of configuration options (name, state, dbo, table_path, ignore_request).
* @param MVCFactoryInterface $factory The factory.
*
* @since 3.0
* @throws \Exception
*/
public function __construct($config = array(), MVCFactoryInterface $factory = null)
{
parent::__construct($config);
// Guess the option from the class name (Option)Model(View).
if (empty($this->option)) {
$r = null;
if (!preg_match('/(.*)Model/i', \get_class($this), $r)) {
throw new \Exception(Text::sprintf('JLIB_APPLICATION_ERROR_GET_NAME', __METHOD__), 500);
}
$this->option = ComponentHelper::getComponentName($this, $r[1]);
}
$this->setDbo(\array_key_exists('dbo', $config) ? $config['dbo'] : Factory::getDbo());
// Set the default view search path
if (\array_key_exists('table_path', $config)) {
$this->addTablePath($config['table_path']);
} elseif (\defined('JPATH_COMPONENT_ADMINISTRATOR')) {
$this->addTablePath(JPATH_COMPONENT_ADMINISTRATOR . '/tables');
$this->addTablePath(JPATH_COMPONENT_ADMINISTRATOR . '/table');
}
// @codeCoverageIgnoreEnd
// Set the clean cache event
if (isset($config['event_clean_cache'])) {
$this->event_clean_cache = $config['event_clean_cache'];
} elseif (empty($this->event_clean_cache)) {
$this->event_clean_cache = 'onContentCleanCache';
}
if ($factory) {
$this->setMVCFactory($factory);
return;
}
$component = Factory::getApplication()->bootComponent($this->option);
if ($component instanceof MVCFactoryServiceInterface) {
$this->setMVCFactory($component->getMVCFactory());
}
}