public function __construct(array $values = array())
{
// Initialise
$this->bareComponentName = '';
$this->componentName = '';
$this->componentNamespace = '';
$this->frontEndPath = '';
$this->backEndPath = '';
$this->thisPath = '';
$this->factoryClass = 'FOF30\\Factory\\BasicFactory';
$this->platformClass = 'FOF30\\Platform\\Joomla\\Platform';
// Try to construct this container object
parent::__construct($values);
// Make sure we have a component name
if (empty($this['componentName'])) {
throw new Exception\NoComponent();
}
$bareComponent = substr($this->componentName, 4);
$this['bareComponentName'] = $bareComponent;
// Try to guess the component's namespace
if (empty($this['componentNamespace'])) {
$this->componentNamespace = ucfirst($bareComponent);
} else {
$this->componentNamespace = trim($this->componentNamespace, '\\');
}
// Make sure we have front-end and back-end paths
if (empty($this['frontEndPath'])) {
$this->frontEndPath = JPATH_SITE . '/components/' . $this->componentName;
}
if (empty($this['backEndPath'])) {
$this->backEndPath = JPATH_ADMINISTRATOR . '/components/' . $this->componentName;
}
// Get the namespaces for the front-end and back-end parts of the component
$frontEndNamespace = '\\' . $this->componentNamespace . '\\Site\\';
$backEndNamespace = '\\' . $this->componentNamespace . '\\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 ($this->frontEndPath == $this->backEndPath) {
$frontEndNamespace = '\\' . $this->componentNamespace . '\\';
$backEndNamespace = '\\' . $this->componentNamespace . '\\';
}
// Do we have to register the component's namespaces with the autoloader?
$autoloader = Autoloader::getInstance();
if (!$autoloader->hasMap($frontEndNamespace)) {
$autoloader->addMap($frontEndNamespace, $this->frontEndPath);
}
if (!$autoloader->hasMap($backEndNamespace)) {
$autoloader->addMap($backEndNamespace, $this->backEndPath);
}
// Inflector service
if (!isset($this['inflector'])) {
$this['inflector'] = function (Container $c) {
return new Inflector();
};
}
// Filesystem abstraction service
if (!isset($this['filesystem'])) {
$this['filesystem'] = function (Container $c) {
return new JoomlaFilesystem($c);
};
}
// Platform abstraction service
if (!isset($this['platform'])) {
if (empty($c['platformClass'])) {
$c['platformClass'] = 'FOF30\\Platform\\Joomla\\Platform';
}
$this['platform'] = function (Container $c) {
$className = $c['platformClass'];
return new $className($c);
};
}
if (empty($this['thisPath'])) {
$this['thisPath'] = $this['frontEndPath'];
if ($this->platform->isBackend()) {
$this['thisPath'] = $this['backEndPath'];
}
}
// MVC Factory service
if (!isset($this['factory'])) {
$this['factory'] = function (Container $c) {
if (empty($c['factoryClass'])) {
$c['factoryClass'] = 'FOF30\\Factory\\BasicFactory';
}
if (strpos($c['factoryClass'], '\\') === false) {
$class = $c->getNamespacePrefix() . 'Factory\\' . $c['factoryClass'];
if (class_exists($class)) {
$c['factoryClass'] = $class;
} else {
$c['factoryClass'] = '\\FOF30\\Factory\\' . ucfirst($c['factoryClass']) . 'Factory';
}
}
if (!class_exists($c['factoryClass'], true)) {
$c['factoryClass'] = 'FOF30\\Factory\\BasicFactory';
}
$factoryClass = $c['factoryClass'];
/** @var FactoryInterface $factory */
$factory = new $factoryClass($c);
if (isset($c['scaffolding'])) {
$factory->setScaffolding($c['scaffolding']);
}
if (isset($c['saveScaffolding'])) {
$factory->setSaveScaffolding($c['saveScaffolding']);
}
if (isset($c['saveControllerScaffolding'])) {
$factory->setSaveControllerScaffolding($c['saveControllerScaffolding']);
}
if (isset($c['saveModelScaffolding'])) {
$factory->setSaveModelScaffolding($c['saveModelScaffolding']);
}
if (isset($c['saveViewScaffolding'])) {
$factory->setSaveViewScaffolding($c['saveViewScaffolding']);
}
if (isset($c['section'])) {
$factory->setSection($c['section']);
}
return $factory;
};
}
// Component Configuration service
if (!isset($this['appConfig'])) {
$this['appConfig'] = function (Container $c) {
$class = $c->getNamespacePrefix() . 'Configuration\\Configuration';
if (!class_exists($class, true)) {
$class = '\\FOF30\\Configuration\\Configuration';
}
return new $class($c);
};
}
// Component Params service
if (!isset($this['params'])) {
$this['params'] = function (Container $c) {
return new Params($c);
};
}
// Blade view template compiler service
if (!isset($this['blade'])) {
$this['blade'] = function (Container $c) {
return new Blade();
};
}
// Database Driver service
if (!isset($this['db'])) {
$this['db'] = function (Container $c) {
return $c->platform->getDbo();
};
}
// Request Dispatcher service
if (!isset($this['dispatcher'])) {
$this['dispatcher'] = function (Container $c) {
return $c->factory->dispatcher();
};
}
// Component toolbar provider
if (!isset($this['toolbar'])) {
$this['toolbar'] = function (Container $c) {
return $c->factory->toolbar();
};
}
// Component toolbar provider
if (!isset($this['transparentAuth'])) {
$this['transparentAuth'] = function (Container $c) {
return $c->factory->transparentAuthentication();
};
}
// View renderer
if (!isset($this['renderer'])) {
$this['renderer'] = function (Container $c) {
if (isset($c['rendererClass']) && class_exists($c['rendererClass'])) {
$class = $c['rendererClass'];
$renderer = new $class($c);
if ($renderer instanceof RenderInterface) {
return $renderer;
}
}
$filesystem = $c->filesystem;
// Try loading the stock renderers shipped with F0F
$path = dirname(__FILE__) . '/../Render/';
$renderFiles = $filesystem->folderFiles($path, '.php');
$renderer = null;
$priority = 0;
if (!empty($renderFiles)) {
foreach ($renderFiles as $filename) {
if ($filename == 'RenderBase.php') {
continue;
}
if ($filename == 'RenderInterface.php') {
continue;
}
$className = 'FOF30\\Render\\' . basename($filename, '.php');
if (!class_exists($className, true)) {
continue;
}
/** @var RenderInterface $o */
$o = new $className($c);
$info = $o->getInformation();
if (!$info->enabled) {
continue;
}
if ($info->priority > $priority) {
$priority = $info->priority;
$renderer = $o;
}
}
}
return $renderer;
};
}
// Input Access service
if (isset($this['input']) && (!is_object($this['input']) || !$this['input'] instanceof \FOF30\Input\Input || !$this['input'] instanceof \JInput)) {
// This swap is necessary to prevent infinite recursion
$this['rawInputData'] = array_merge($this['input']);
unset($this['input']);
$this['input'] = function (Container $c) {
$input = new \FOF30\Input\Input($c['rawInputData']);
unset($c['rawInputData']);
return $input;
};
}
if (!isset($this['input'])) {
$this['input'] = function () {
return new \FOF30\Input\Input();
};
}
// Session service
if (!isset($this['session'])) {
$this['session'] = function () {
return \JFactory::getSession();
};
}
// Template service
if (!isset($this['template'])) {
$this['template'] = function (Container $c) {
return new Template($c);
};
}
// Media version string
if (!isset($this['mediaVersion'])) {
$this['mediaVersion'] = $this->getDefaultMediaVersion();
}
}