I’m trying to use a library to merge PDFs, but I cannot figure out how I’m declaring it twice. Getting a this error: Cannot declare class PDFMerger, because the name is already in use …
I’ve tried lots of variations to get it to work. I’ve also tested the PDF library using the command line and it works perfectly outside of Nextcloud.
**Possible causes of the issue. **
- PDFMerger class name. The conversion of some names to camelcase makes me think this could be a problem.
- 3rd party classes are handled differently that isn’t shown in the docs.
- I’m re-declaring something in the controller that belongs in the container.
- I’m a terrible programmer.
One of these things is the cause of my issue. Any help is really appreciated.
Code: https://github.com/PaperlessHouse/nextcloud-faxapp
Library code: https://github.com/myokyawhtun/PDFMerger
I put the library at /lib/Vendor/PDFMerger/PDFMerger
Code in /lib/AppInfo/Application.php
// Import class
use OCA\FaxApp\Vendor\PDFMerger\PDFMerger;
// Controller with query to PDFMerger object
$container->registerService('FaxController', function($c){
return new FaxController(
$c->query('Logger'),
$c->query('AppName'),
$c->query('Request'),
$c->query('FaxService'),
$c->query('PDFMerger'),
$c->query('UserSession')->getUser()->getUID(),
$c->query('Config')
);
});
// Register PDFMerger
$container->registerService('PDFMerger', function($c){
return new PDFMerger(
);
});
In the Controller, I’ve got this code.
class FaxController extends Controller {
// I'm not sure if this is necessary, but based my code on the OCR app
/** @var PDFMerger */
private $PDFMerger;
/**
* @param ILogger $logger
* @param string $AppName
* @param IRequest $request
* @param FaxService $faxService
* @param PDFMerger $pdfMerger
* @param string $UserId
*/
public function __construct(ILogger $logger, $AppName, IRequest $request, $faxService, $pdfMerger, $UserId, IConfig $config){
parent::__construct($AppName, $request);
$this->logger = $logger;
$this->appName = $AppName;
$this->faxService = $faxService;
$this->pdfMerger = $pdfMerger;
$this->userId = $UserId;
$this->config = $config;