Skip to content

Commit

Permalink
move things to the register phase
Browse files Browse the repository at this point in the history
  • Loading branch information
ylebre committed Feb 7, 2024
1 parent 9debc68 commit c9c31b1
Showing 1 changed file with 16 additions and 22 deletions.
38 changes: 16 additions & 22 deletions solid/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
use OC\Server;

use OCA\Solid\Service\UserService;
use OCA\Solid\Service\SolidWebhookService;
use OCA\Solid\Db\SolidWebhookMapper;
use OCA\Solid\WellKnown\OpenIdConfigurationHandler;
use OCA\Solid\WellKnown\SolidHandler;
use OCA\Solid\Middleware\SolidCorsMiddleware;
Expand All @@ -33,33 +35,12 @@ class Application extends App implements IBootstrap {
public function __construct(array $urlParams = []) {
parent::__construct(self::APP_ID, $urlParams);

$container = $this->getContainer();

$container->registerService(SolidCorsMiddleware::class, function($c): SolidCorsMiddleware {
return new SolidCorsMiddleware(
$c->get(IRequest::class)
);
});

// executed in the order that it is registered
$container->registerMiddleware(SolidCorsMiddleware::class);

$container->registerService(SolidWebhookService::class, function($c): SolidWebhookService {
return new SolidWebhookService(
$c->query(SolidWebhookMapper::class)
);
});

$container->registerService(SolidWebhookMapper::class, function($c): SolidWebhookMapper {
return new SolidWebhookMapper(
$c->get(IDBConnection::class)
);
});
}

public function register(IRegistrationContext $context): void {
$context->registerWellKnownHandler(\OCA\Solid\WellKnown\OpenIdConfigurationHandler::class);
$context->registerWellKnownHandler(\OCA\Solid\WellKnown\SolidHandler::class);
$context->registerMiddleware(SolidCorsMiddleware::class);

/**
* Core class wrappers
Expand All @@ -79,6 +60,19 @@ public function register(IRegistrationContext $context): void {
$context->registerService('User', function($c) {
return $c->query('UserSession')->getUser();
});

/* webhook DB services */
$context->registerService(SolidWebhookService::class, function($c): SolidWebhookService {
return new SolidWebhookService(
$c->query(SolidWebhookMapper::class)
);
});

$context->registerService(SolidWebhookMapper::class, function($c): SolidWebhookMapper {
return new SolidWebhookMapper(
$c->get(IDBConnection::class)
);
});
}

public function boot(IBootContext $context): void {
Expand Down

0 comments on commit c9c31b1

Please sign in to comment.