seeddms-code/inc/inc.ClassConversionMgr.php

75 lines
1.8 KiB
PHP

<?php
/**
* Implementation of conversion manager
*
* @category DMS
* @package SeedDMS
* @license GPL 2
* @version @version@
* @author Uwe Steinmann <uwe@steinmann.cx>
* @copyright Copyright (C) 2021 Uwe Steinmann
* @version Release: @package_version@
*/
require_once("inc/inc.ClassConversionServiceExec.php");
require_once("inc/inc.ClassConversionServiceImageToImage.php");
require_once("inc/inc.ClassConversionServicePdfToImage.php");
require_once("inc/inc.ClassConversionServiceTextToText.php");
/**
* Implementation of conversion manager
*
* @category DMS
* @package SeedDMS
* @author Uwe Steinmann <uwe@steinmann.cx>
* @copyright Copyright (C) 2021 Uwe Steinmann
* @version Release: @package_version@
*/
class SeedDMS_ConversionMgr {
/**
* List of services for searching fulltext
*/
public $services;
public function __construct() {
$this->services = array();
}
public function addService($service) {
$this->services[$service->from][$service->to][] = $service;
return $service;
}
public function hasService($from, $to) {
if(!empty($this->services[$from][$to]))
return true;
else
return false;
}
public function getServices() {
return $this->services;
}
/**
* Convert a file
*
* @param string $file name of file to convert
* @param string $from mimetype of input file
* @param string $to mimetype of output file
*
* @return boolean true on success, other false
*/
public function convert($file, $from, $to, $target=null, $params=array()) {
if(isset($this->services[$from][$to])) {
$services = $this->services[$from][$to];
for(end($services); key($services)!==null; prev($services)) {
$service = current($services);
$text = $service->convert($file, $target, $params);
if($text !== false)
return $text;
}
}
}
}