/** * Public constructor. This does NOT go through the fof.xml file. You are advised to use getInstance() instead. * * @param array $values Overrides for the container configuration and services * * @throws \FOF30\Container\Exception\NoComponent If no component name is specified */ 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(); } }
*/ // Required to load FOF and Joomla! define('_JEXEC', 1); // Include the FOF autoloader. if (!class_exists('FOF30\\Autoloader\\Autoloader')) { require_once __DIR__ . '/../fof/Autoloader/Autoloader.php'; if (!class_exists('FOF30\\Autoloader\\Autoloader')) { echo 'ERROR: FOF Autoloader not found' . PHP_EOL; exit(1); } } require_once __DIR__ . '/../fof/Utils/helpers.php'; // Tell the FOF autoloader where to load test classes from (very useful for stubs!) \FOF30\Autoloader\Autoloader::getInstance()->addMap('FOF30\\Tests\\', __DIR__); \FOF30\Autoloader\Autoloader::getInstance()->addMap('Fakeapp\\', __DIR__ . '/Stubs/Fakeapp'); \FOF30\Autoloader\Autoloader::getInstance()->addMap('Dummyapp\\', __DIR__ . '/Stubs/Dummyapp'); // Include the Composer autoloader. if (false == (include_once __DIR__ . '/../vendor/autoload.php')) { echo 'ERROR: You need to install Composer and run `composer install` on FOF before running the tests.' . PHP_EOL; exit(1); } // Don't report strict errors. This is needed because sometimes a test complains about arguments passed as reference ini_set('zend.ze1_compatibility_mode', '0'); error_reporting(E_ALL & ~E_STRICT); ini_set('display_errors', 1); // Fix magic quotes on PHP 5.3 if (version_compare(PHP_VERSION, '5.4.0', 'lt')) { ini_set('magic_quotes_runtime', 0); } // Timezone fix; avoids errors printed out by PHP 5.3.3+ if (function_exists('date_default_timezone_get') && function_exists('date_default_timezone_set')) {