/**
* @param array $options
* @return Data
* @throws Exception
* @SuppressWarnings(PHPMD.Superglobals)
*/
protected function _prepareOptions(array $options)
{
// Default data for current system
$this->_default['root_url'] = Url::root();
$this->_default['root_path'] = Sys::getDocRoot();
$options = array_merge($this->_default, $options);
// Check cache directory
$cachePath = FS::clean($options['cache_path']);
if (!$cachePath) {
throw new Exception('Option "cache_path" is empty!');
}
if (!FS::isDir($cachePath)) {
mkdir($cachePath, 0755, true);
}
$options['cache_path'] = FS::real($cachePath);
$options['root_url'] = rtrim($options['root_url'], '/');
$options['root_path'] = FS::real($options['root_path']);
$options['driver'] = ucfirst(strtolower(trim($options['driver'])));
// Check mixin paths
$lessFile = (array) $options['autoload'];
foreach ($lessFile as $key => $mixin) {
$lessFile[$key] = FS::real($mixin);
}
$options['autoload'] = array_filter($lessFile);
// Check imported paths
$importPaths = [];
foreach ((array) $options['import_paths'] as $path => $uri) {
if ($cleanPath = FS::real($path)) {
$importPaths[$cleanPath] = $uri;
}
}
$importPaths[$options['root_path']] = $options['root_url'];
// Forced add root path in the end of list!
$options['import_paths'] = array_filter($importPaths);
return new Data($options);
}