I’m still missing something. When I run this code, it throws an error:
Argument 1 passed to OC\AppFramework\Middleware\MiddlewareDispatcher::registerMiddleware() must be an instance of OCP\AppFramework\Middleware, string given
Here’s my code with just the relevant parts:
<?php
namespace OCA\Zzzzzzzzzzzzz\AppInfo;
use OCP\AppFramework\App;
use OCA\Zzzzzzzzzzzzz\Middleware\DomManipulationMiddleware;
class Application extends App {
public const APP_ID = 'zzzzzzzzzzzzz';
public function __construct() {
parent::__construct('zzzzzzzzzzzzz');
/* This registers the middleware to all applications (my brute-force attempt) */
foreach (OC_App::getEnabledApps() as $appId) {
if ($appId != 'zzzzzzzzzzzzz') {
$appContainer = $this->getContainer()->getServer()->getRegisteredAppContainer($appId);
$appContainer->registerService('DomManipulationMiddleware', function($c){
return new DomManipulationMiddleware();
});
$appContainer->registerMiddleware('DomManipulationMiddleware');
}
}
/**/
/* Registers the middleware for this app (I could do this in the previous loop, but
* I separated it out so I could try your method) */
$container = $this->getContainer();
$container->registerService('DomManipulationMiddleware', function($c){
return new DomManipulationMiddleware();
});
$container->registerMiddleware('DomManipulationMiddleware');
$this->getContainer()->query(\OC\AppFramework\Middleware\MiddlewareDispatcher::class)->registerMiddleware(new DomManipulationMiddleware());
$this->getContainer()->getServer()->query(\OC\AppFramework\Middleware\MiddlewareDispatcher::class)->registerMiddleware(new DomManipulationMiddleware());
}
}
(Recall that I named my app Zzzzzzzzzzzzz because I’ve been registering my middleware against all apps, and apps are instantiated alphabetically. This method successfully lets me register the middleware with installed apps, but I can’t use it to manipulate the login page, for example).