Use DI for the config
This commit is contained in:
parent
c1f266db88
commit
1a1dc9b335
|
@ -6,7 +6,12 @@ use OCP\Preview\IProvider;
|
||||||
abstract class Provider implements IProvider {
|
abstract class Provider implements IProvider {
|
||||||
private $options;
|
private $options;
|
||||||
|
|
||||||
public function __construct($options) {
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param array $options
|
||||||
|
*/
|
||||||
|
public function __construct(array $options = []) {
|
||||||
$this->options = $options;
|
$this->options = $options;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,13 @@
|
||||||
*/
|
*/
|
||||||
namespace OC;
|
namespace OC;
|
||||||
|
|
||||||
use OCP\Image;
|
|
||||||
use OCP\IPreview;
|
use OCP\IPreview;
|
||||||
use OCP\Preview\IProvider;
|
use OCP\Preview\IProvider;
|
||||||
|
|
||||||
class PreviewManager implements IPreview {
|
class PreviewManager implements IPreview {
|
||||||
|
/** @var \OCP\IConfig */
|
||||||
|
protected $config;
|
||||||
|
|
||||||
/** @var array */
|
/** @var array */
|
||||||
protected $providers = [];
|
protected $providers = [];
|
||||||
|
|
||||||
|
@ -21,8 +23,11 @@ class PreviewManager implements IPreview {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param \OCP\IConfig $config
|
||||||
*/
|
*/
|
||||||
public function __construct() {
|
public function __construct(\OCP\IConfig $config) {
|
||||||
|
$this->config = $config;
|
||||||
$this->registerCoreProviders();
|
$this->registerCoreProviders();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,7 +42,7 @@ class PreviewManager implements IPreview {
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function registerProvider($mimeTypeRegex, \Closure $callable) {
|
public function registerProvider($mimeTypeRegex, \Closure $callable) {
|
||||||
if (!\OC::$server->getConfig()->getSystemValue('enable_previews', true)) {
|
if (!$this->config->getSystemValue('enable_previews', true)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +92,7 @@ class PreviewManager implements IPreview {
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function isMimeSupported($mimeType = '*') {
|
public function isMimeSupported($mimeType = '*') {
|
||||||
if (!\OC::$server->getConfig()->getSystemValue('enable_previews', true)) {
|
if (!$this->config->getSystemValue('enable_previews', true)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,7 +112,7 @@ class PreviewManager implements IPreview {
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isAvailable(\OCP\Files\FileInfo $file) {
|
public function isAvailable(\OCP\Files\FileInfo $file) {
|
||||||
if (!\OC::$server->getConfig()->getSystemValue('enable_previews', true)) {
|
if (!$this->config->getSystemValue('enable_previews', true)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +170,7 @@ class PreviewManager implements IPreview {
|
||||||
return $this->defaultProviders;
|
return $this->defaultProviders;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->defaultProviders = \OC::$server->getConfig()->getSystemValue('enabledPreviewProviders', [
|
$this->defaultProviders = $this->config->getSystemValue('enabledPreviewProviders', [
|
||||||
'OC\Preview\Image',
|
'OC\Preview\Image',
|
||||||
'OC\Preview\MP3',
|
'OC\Preview\MP3',
|
||||||
'OC\Preview\TXT',
|
'OC\Preview\TXT',
|
||||||
|
@ -180,10 +185,10 @@ class PreviewManager implements IPreview {
|
||||||
* @param string $class
|
* @param string $class
|
||||||
* @param string $mimeType
|
* @param string $mimeType
|
||||||
*/
|
*/
|
||||||
protected function registerCoreProvider($class, $mimeType) {
|
protected function registerCoreProvider($class, $mimeType, $options = []) {
|
||||||
if (in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) {
|
if (in_array(trim($class, '\\'), $this->getEnabledDefaultProvider())) {
|
||||||
$this->registerProvider($mimeType, function () use ($class) {
|
$this->registerProvider($mimeType, function () use ($class, $options) {
|
||||||
return new $class([]);
|
return new $class($options);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -225,7 +230,7 @@ class PreviewManager implements IPreview {
|
||||||
if (count($checkImagick->queryFormats('PDF')) === 1) {
|
if (count($checkImagick->queryFormats('PDF')) === 1) {
|
||||||
// Office previews are currently not supported on Windows
|
// Office previews are currently not supported on Windows
|
||||||
if (!\OC_Util::runningOnWindows() && \OC_Helper::is_function_enabled('shell_exec')) {
|
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) {
|
if (!$officeFound) {
|
||||||
//let's see if there is libreoffice or openoffice on this machine
|
//let's see if there is libreoffice or openoffice on this machine
|
||||||
|
|
|
@ -43,8 +43,8 @@ class Server extends SimpleContainer implements IServerContainer {
|
||||||
$this->registerService('ContactsManager', function ($c) {
|
$this->registerService('ContactsManager', function ($c) {
|
||||||
return new ContactsManager();
|
return new ContactsManager();
|
||||||
});
|
});
|
||||||
$this->registerService('PreviewManager', function ($c) {
|
$this->registerService('PreviewManager', function (Server $c) {
|
||||||
return new PreviewManager();
|
return new PreviewManager($c->getConfig());
|
||||||
});
|
});
|
||||||
$this->registerService('TagMapper', function(Server $c) {
|
$this->registerService('TagMapper', function(Server $c) {
|
||||||
return new TagMapper($c->getDatabaseConnection());
|
return new TagMapper($c->getDatabaseConnection());
|
||||||
|
|
Loading…
Reference in New Issue