/** * Gets the base URL of the system * @return string */ public function getBaseUrl() { if ($this->baseUrl) { return $this->baseUrl; } $baseUrl = $this->zibo->getConfigValue(self::CONFIG_URL); if (!$baseUrl) { $baseUrl = $this->generateBaseUrl(); } return $this->baseUrl = rtrim($baseUrl, '/'); }
protected static function setInvertToCreatedFilter(AbstractInvertLogItemFilter $filter, Zibo $zibo, $name, $configBase) { $configInvert = $configBase . Module::CONFIG_INVERT; $invert = $zibo->getConfigValue($configInvert); if ($invert !== null) { $filter->setInvert($invert); } }
/** * Reads the routes from the provided file * @param zibo\library\filesystem\File $file * @return array Array with Route objects as value and their path as key */ private function readRoutesFromFile(File $file) { $dom = new Document(); $relaxNg = $this->zibo->getConfigValue(self::CONFIG_RNG); if ($relaxNg) { $dom->setRelaxNGFile($relaxNg); } $dom->load($file); return $this->getRoutesFromElement($file, $dom->documentElement); }
/** * Gets the MIME type of a file based on it's extension * @param zibo\core\Zibo $zibo Instance of Zibo * @param zibo\library\filesystem\File $file The file to get the MIME from * @return string The MIME type of the file */ public static function getMimeType(Zibo $zibo, File $file) { $extension = $file->getExtension(); if (empty($extension)) { return self::MIME_UNKNOWN; } $mime = $zibo->getConfigValue(self::CONFIG_MIME . $extension); if (!$mime) { $mime = self::MIME_UNKNOWN; } return $mime; }
/** * Create a new validator * @param string $validatorName name of the validator * @param array $options options for the validator * @return zibo\library\validation\validator\Validator * @throws zibo\ZiboException when the validator does not exist */ public function createValidator($validatorName, array $options = array()) { if (!String::isString($validatorName, String::NOT_EMPTY)) { throw new ZiboException('Provided validator name is empty or invalid'); } if (!isset($this->validators[$validatorName])) { $validatorClass = $this->zibo->getConfigValue(self::CONFIG_VALIDATOR . '.' . $validatorName); if (!$validatorClass) { throw new ZiboException('Unsupported validator: ' . $validatorName); } $this->registerValidator($validatorName, $validatorClass); } $className = $this->validators[$validatorName]; return new $className($options); }
private function loadListeners(Zibo $zibo) { $config = $zibo->getConfigValue(self::CONFIG_LOG); if (isset($config[self::CONFIG_LISTENER])) { unset($config[self::CONFIG_LISTENER]); } if (isset($config[self::CONFIG_FILTER])) { unset($config[self::CONFIG_FILTER]); } $listenerFactory = new LogListenerFactory($zibo); foreach ($config as $name => $parameters) { $listener = $listenerFactory->createListener($name); if ($listener != null) { $this->log->addLogListener($listener); } } }
/** * Loads the defined modules from the Zibo Configuration * @param zibo\core\Zibo $zibo Instance of Zibo * @return array Array with the defined modules * @throws zibo\ZiboException when a module could not be created * @see Module * @see CONFIG_MODULE */ public function loadModules(Zibo $zibo) { $configModules = $zibo->getConfigValue(self::CONFIG_MODULE); if (!$configModules) { return array(); } $objectFactory = new ObjectFactory(); $modules = array(); $configModules = Config::parseConfigTree($configModules); foreach ($configModules as $configKey => $moduleClass) { try { $modules[] = $objectFactory->create($moduleClass, self::INTERFACE_MODULE); } catch (ZiboException $exception) { throw new ZiboException('Could not create ' . $moduleClass . ' from the ' . $configKey . ' configuration key', 0, $exception); } } return $modules; }
protected static function addFiltersToCreatedListener(AbstractFilteredLogListener $listener, Zibo $zibo, $name, $configBase) { $configBase .= Module::CONFIG_FILTER; $config = $zibo->getConfigValue($configBase); if (empty($config)) { return; } if (isset($config[Module::CONFIG_FILTER_ALL])) { $listener->setFilterAllFilters($config[Module::CONFIG_FILTER_ALL]); unset($config[Module::CONFIG_FILTER_ALL]); } if (isset($config[Module::CONFIG_INVERT])) { $listener->setInvert($config[Module::CONFIG_INVERT]); unset($config[Module::CONFIG_INVERT]); } $filterFactory = new LogItemFilterFactory($zibo); foreach ($config as $name => $parameters) { $filterConfigBase = $configBase . Config::TOKEN_SEPARATOR . $name . Config::TOKEN_SEPARATOR; $filter = $filterFactory->createFilter($name, $filterConfigBase); if ($filter != null) { $listener->addFilter($filter); } } }
/** * Assign the smarty configuration to the engine * @param zibo\core\Zibo $zibo instance of Zibo to get the configuration from * @return null */ private function parseConfiguration(Zibo $zibo) { $this->smarty->caching = false; $this->smarty->compile_dir = $zibo->getConfigValue(self::CONFIG_COMPILE_DIRECTORY, self::DEFAULT_COMPILE_DIRECTORY); $directory = new File($this->smarty->compile_dir); $directory->create(); $smartyPluginDirectories = $zibo->getConfigValue(self::CONFIG_PLUGINS, array()); if (!is_array($smartyPluginDirectories)) { $smartyPluginDirectories = array($smartyPluginDirectories); } foreach ($smartyPluginDirectories as $directory) { $this->smarty->plugins_dir[] = $directory; } }
protected static function setParametersToCreatedListener(FileListener $listener, Zibo $zibo, $name, $configBase) { $configFileTruncateSize = $configBase . self::CONFIG_FILE_TRUNCATE_SIZE; $fileTruncateSize = $zibo->getConfigValue($configFileTruncateSize); if ($fileTruncateSize !== null) { $listener->setFileTruncateSize($fileTruncateSize); } $configDateFormat = $configBase . self::CONFIG_DATE_FORMAT; $dateFormat = $zibo->getConfigValue($configDateFormat); if ($dateFormat !== null) { $listener->setDateFormat($dateFormat); } }
/** * Loads the database connections from the Zibo configuration * @param zibo\core\Zibo $zibo Instance of Zibo * @return null * @throws zibo\library\database\exception\DatabaseException when the configuration contains an invalid connection * @throws zibo\library\database\exception\DatabaseException when the default connection does not exist */ private function loadConnectionsFromConfig(Zibo $zibo) { $zibo->runEvent(Zibo::EVENT_LOG, 'Loading database connections', '', 0, self::LOG_NAME); $connections = $zibo->getConfigValue(self::CONFIG_CONNECTION, array()); if (!is_array($connections)) { $connections = array(self::NAME_DEFAULT => $connections); } $defaultConnectionName = null; foreach ($connections as $name => $dsn) { if ($name == self::NAME_DEFAULT) { $defaultConnectionName = $name; } try { $dsn = new Dsn($dsn); $this->registerConnection($name, $dsn); } catch (DatabaseException $e) { if ($name == self::NAME_DEFAULT) { $defaultConnectionName = $dsn; } else { throw $e; } } } if ($defaultConnectionName != null) { $this->setDefaultConnectionName($defaultConnectionName); } }
/** * Sets the default action and controller to the router * @param zibo\core\Zibo $zibo * @return null */ private function setDefaultAction(Zibo $zibo) { $router = $zibo->getRouter(); if ($router === null) { $router = new GenericRouter(); $zibo->setRouter($router); } if (!$router instanceof GenericRouter) { return; } $defaultController = $router->getDefaultController(); if ($defaultController) { return; } $defaultController = $zibo->getConfigValue(self::CONFIG_CONTROLLER_DEFAULT, self::CONTROLLER_DEFAULT); $router->setDefaultAction($defaultController); }
/** * Initializes the hash algorithm from the Zibo configuration * @param zibo\core\Zibo $zibo The Zibo instance * @param zibo\library\ObjectFactory $objectFactory Instance of an object factory * @return null */ private function initializeHashAlgorithm(Zibo $zibo, ObjectFactory $objectFactory) { $hashAlgorithms = $zibo->getConfigValue(EncryptionModule::CONFIG_HASH_ALGORITHM); $hashAlgorithmName = $zibo->getConfigValue(self::CONFIG_HASH_ALGORITHM, self::DEFAULT_HASH_ALGORITHM); if (!array_key_exists($hashAlgorithmName, $hashAlgorithms)) { throw new ZiboException('Provided password hash algorithm ' . $hashAlgorithmName . ' could not be found'); } $hashAlgorithmClass = $hashAlgorithms[$hashAlgorithmName]; $this->hashAlgorithm = $objectFactory->create($hashAlgorithmClass, EncryptionModule::INTERFACE_HASH_ALGORITHM); }
/** * Loads the archive types from the Zibo configuration * @return null */ private function loadTypes(Zibo $zibo) { $this->types = array(); $types = $zibo->getConfigValue(self::CONFIG_TYPES, array()); foreach ($types as $typeName => $className) { $this->register($typeName, $className); } }