protected static function &makeInstance($component, array $values = array(), $section = 'auto')
{
// Try to auto-detect some defaults
$tmpConfig = array_merge($values, array('componentName' => $component));
$tmpContainer = new Container($tmpConfig);
if (!in_array($section, array('site', 'admin'))) {
$section = $tmpContainer->platform->isBackend() ? 'admin' : 'site';
}
$appConfig = $tmpContainer->appConfig;
// Get the namespace from fof.xml
$namespace = $appConfig->get('container.componentNamespace', null);
// $values always overrides $namespace and fof.xml
if (isset($values['componentNamespace'])) {
$namespace = $values['componentNamespace'];
}
// If there is no namespace set, try to guess it.
if (empty($namespace)) {
$bareComponent = $component;
if (substr($component, 0, 4) == 'com_') {
$bareComponent = substr($component, 4);
}
$namespace = ucfirst($bareComponent);
}
// Get the default front-end/back-end paths
$frontEndPath = $appConfig->get('container.frontEndPath', JPATH_SITE . '/components/' . $component);
$backEndPath = $appConfig->get('container.backEndPath', JPATH_ADMINISTRATOR . '/components/' . $component);
// Parse path variables if necessary
$frontEndPath = $tmpContainer->parsePathVariables($frontEndPath);
$backEndPath = $tmpContainer->parsePathVariables($backEndPath);
// Apply path overrides
if (isset($values['frontEndPath'])) {
$frontEndPath = $values['frontEndPath'];
}
if (isset($values['backEndPath'])) {
$backEndPath = $values['backEndPath'];
}
$thisPath = $section == 'admin' ? $backEndPath : $frontEndPath;
// Get the namespaces for the front-end and back-end parts of the component
$frontEndNamespace = '\\' . $namespace . '\\Site\\';
$backEndNamespace = '\\' . $namespace . '\\Admin\\';
// Special case: if the frontend and backend paths are identical, we don't use the Site and Admin namespace
// suffixes after $this->componentNamespace (so you may use FOF with JApplicationWeb apps)
if ($frontEndPath == $backEndPath) {
$frontEndNamespace = '\\' . $namespace . '\\';
$backEndNamespace = '\\' . $namespace . '\\';
}
// Do we have to register the component's namespaces with the autoloader?
$autoloader = Autoloader::getInstance();
if (!$autoloader->hasMap($frontEndNamespace)) {
$autoloader->addMap($frontEndNamespace, $frontEndPath);
}
if (!$autoloader->hasMap($backEndNamespace)) {
$autoloader->addMap($backEndNamespace, $backEndPath);
}
// Get the Container class name
$classNamespace = $section == 'admin' ? $backEndNamespace : $frontEndNamespace;
$class = $classNamespace . 'Container';
// Get the values overrides from fof.xml
$values = array_merge(array('factoryClass' => '\\FOF30\\Factory\\BasicFactory', 'platformClass' => '\\FOF30\\Platform\\Joomla\\Platform', 'scaffolding' => false, 'saveScaffolding' => false, 'saveControllerScaffolding' => false, 'saveModelScaffolding' => false, 'saveViewScaffolding' => false, 'section' => $section), $values);
$values = array_merge($values, array('componentName' => $component, 'componentNamespace' => $namespace, 'frontEndPath' => $frontEndPath, 'backEndPath' => $backEndPath, 'thisPath' => $thisPath, 'rendererClass' => $appConfig->get('container.rendererClass', null), 'factoryClass' => $appConfig->get('container.factoryClass', $values['factoryClass']), 'platformClass' => $appConfig->get('container.platformClass', $values['platformClass']), 'scaffolding' => $appConfig->get('container.scaffolding', $values['scaffolding']), 'saveScaffolding' => $appConfig->get('container.saveScaffolding', $values['saveScaffolding']), 'saveControllerScaffolding' => $appConfig->get('container.saveControllerScaffolding', $values['saveControllerScaffolding']), 'saveModelScaffolding' => $appConfig->get('container.saveModelScaffolding', $values['saveModelScaffolding']), 'saveViewScaffolding' => $appConfig->get('container.saveViewScaffolding', $values['saveViewScaffolding'])));
if (empty($values['rendererClass'])) {
unset($values['rendererClass']);
}
$mediaVersion = $appConfig->get('container.mediaVersion', null);
if (!empty($mediaVersion)) {
$values['mediaVersion'] = $mediaVersion;
}
unset($appConfig);
unset($tmpConfig);
unset($tmpContainer);
if (class_exists($class, true)) {
$container = new $class($values);
} else {
$container = new Container($values);
}
return $container;
}