Skip to content

Commit

Permalink
Make user service registration optional (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
akadlec authored Jul 21, 2024
1 parent b59217f commit 722f011
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/DI/SimpleAuthExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ public function loadConfiguration(): void
$builder->addDefinition($this->prefix('security.annotationChecker'), new DI\Definitions\ServiceDefinition())
->setType(Security\AnnotationChecker::class);

$builder->addDefinition($this->prefix('security.user'), new DI\Definitions\ServiceDefinition())
->setType(Security\User::class);

/**
* Casbin
*/
Expand Down Expand Up @@ -261,6 +258,23 @@ public function beforeCompile(): void
$configuration = $this->getConfig();
assert($configuration instanceof stdClass);

/**
* Security
*/

$userContextServiceName = $builder->getByType(Security\User::class);

$userContext = null;

if ($userContextServiceName !== null) {
$userContext = $builder->getDefinition($userContextServiceName);
}

if ($userContext === null) {
$builder->addDefinition($this->prefix('security.user'), new DI\Definitions\ServiceDefinition())
->setType(Security\User::class);
}

/**
* Doctrine extension
*/
Expand Down

0 comments on commit 722f011

Please sign in to comment.