Use DI for the config

This commit is contained in:
Joas Schilling 2015-03-12 12:08:31 +01:00
parent c1f266db88
commit 1a1dc9b335
3 changed files with 23 additions and 13 deletions

View File

@ -6,7 +6,12 @@ use OCP\Preview\IProvider;
abstract class Provider implements IProvider {
private $options;
public function __construct($options) {
/**
* Constructor
*
* @param array $options
*/
public function __construct(array $options = []) {
$this->options = $options;
}

View File

@ -8,11 +8,13 @@
*/
namespace OC;
use OCP\Image;
use OCP\IPreview;
use OCP\Preview\IProvider;
class PreviewManager implements IPreview {
/** @var \OCP\IConfig */
protected $config;
/** @var array */
protected $providers = [];
@ -21,8 +23,11 @@ class PreviewManager implements IPreview {
/**
* Constructor
*
* @param \OCP\IConfig $config
*/
public function __construct() {
public function __construct(\OCP\IConfig $config) {
$this->config = $config;
$this->registerCoreProviders();
}
@ -37,7 +42,7 @@ class PreviewManager implements IPreview {
* @return void
*/
public function registerProvider($mimeTypeRegex, \Closure $callable) {
if (!\OC::$server->getConfig()->getSystemValue('enable_previews', true)) {
if (!$this->config->getSystemValue('enable_previews', true)) {
return;
}
@ -87,7 +92,7 @@ class PreviewManager implements IPreview {
* @return boolean
*/
public function isMimeSupported($mimeType = '*') {
if (!\OC::$server->getConfig()->getSystemValue('enable_previews', true)) {
if (!$this->config->getSystemValue('enable_previews', true)) {
return false;
}
@ -107,7 +112,7 @@ class PreviewManager implements IPreview {
* @return bool
*/
public function isAvailable(\OCP\Files\FileInfo $file) {
if (!\OC::$server->getConfig()->getSystemValue('enable_previews', true)) {
if (!$this->config->getSystemValue('enable_previews', true)) {
return false;
}
@ -165,7 +170,7 @@ class PreviewManager implements IPreview {
return $this->defaultProviders;
}
$this->defaultProviders = \OC::$server->getConfig()->getSystemValue('enabledPreviewProviders', [
$this->defaultProviders = $this->config->getSystemValue('enabledPreviewProviders', [
'OC\Preview\Image',
'OC\Preview\MP3',
'OC\Preview\TXT',
@ -180,10 +185,10 @@ class PreviewManager implements IPreview {
* @param string $class
* @param string $mimeType
*/
protected function registerCoreProvider($class, $mimeType) {
protected function registerCoreProvider($class, $mimeType, $options = []) {
if (in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) {
$this->registerProvider($mimeType, function () use ($class) {
return new $class([]);
$this->registerProvider($mimeType, function () use ($class, $options) {
return new $class($options);
});
}
}
@ -225,7 +230,7 @@ class PreviewManager implements IPreview {
if (count($checkImagick->queryFormats('PDF')) === 1) {
// Office previews are currently not supported on Windows
if (!\OC_Util::runningOnWindows() && \OC_Helper::is_function_enabled('shell_exec')) {
$officeFound = is_string(\OC::$server->getConfig()->getSystemValue('preview_libreoffice_path', null));
$officeFound = is_string($this->config->getSystemValue('preview_libreoffice_path', null));
if (!$officeFound) {
//let's see if there is libreoffice or openoffice on this machine

View File

@ -43,8 +43,8 @@ class Server extends SimpleContainer implements IServerContainer {
$this->registerService('ContactsManager', function ($c) {
return new ContactsManager();
});
$this->registerService('PreviewManager', function ($c) {
return new PreviewManager();
$this->registerService('PreviewManager', function (Server $c) {
return new PreviewManager($c->getConfig());
});
$this->registerService('TagMapper', function(Server $c) {
return new TagMapper($c->getDatabaseConnection());