Need to implement IBootstrap in Application to use Middleware?

Hi everyone :slight_smile:

A coworker reported a problem with our Workspace application.

In fact, when we execute a controller method (page#index, group#create and so on.), no middleware is triggered.

I read the documentation and I saw in an example we need to implement the IBootstrap interface in the Application class from Nextcloud 25 : Middlewares — Nextcloud latest Developer Manual latest documentation .

I wrote this code :

<?php

namespace OCA\Workspace\AppInfo;

use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;

class Application extends App implements IBootstrap {

	// code

	public function boot(IBootContext $contexte): void {
	}
}

Then, my middleware work!

I’m sure my problem comes from IBootstrap.
Furthermore, the Nextcloud 24 documentation doesn’t mention IBootstrap in Application : https://docs.nextcloud.com/server/24/developer_manual/basics/middlewares.html .

If that 's where my problem comes from the implementation of IBootstrap, why is not mention in the upgrade guideline : Upgrade to Nextcloud 25 — Nextcloud latest Developer Manual latest documentation ?

Is it an omission? If yes, I could create a PR to fill the documentation ?

The pull request Create the register function by zak39 · Pull Request #649 · arawa/workspace · GitHub broke it.

With IBootstrap

Services and Middlewares are registered in the register function.

Without IBoostrap

Services and Middlewares are registered in the class constructor.

Relevant documentation

2 Likes

Oooh okay, I missed something I think :thinking:

But, I don’t think it’s explicit enough or is it just me?

We are always happy about pull requests for our documentation!

1 Like

Cool, I will create a PR for this subject :slight_smile: