Skip to content

Commit

Permalink
Merge pull request #232 from jolicode/set-a-default-context
Browse files Browse the repository at this point in the history
Fix issue when using `ContextRegistry::getCurrentContext()` without setting first a context
  • Loading branch information
lyrixx committed Jan 11, 2024
2 parents 4374f8e + ab38691 commit 1ff3f1a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

## Not released yet

## 0.11.1 (2024-01-11)

* Fix issue when using `ContextRegistry::getCurrentContext()` without setting first a context
* Calling `ContextRegistry::getCurrentContext()` without `setCurrentContext()`
is deprecated. Pass a `$context` instead to the function, or set a current
context before.

## 0.11.0 (2024-01-11)

* Add `AsListener` attribute to register an event listener
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
class Application extends SymfonyApplication
{
public const NAME = 'castor';
public const VERSION = 'v0.11.0';
public const VERSION = 'v0.11.1';

// "Current" objects availables at some point of the lifecycle
private InputInterface $input;
Expand Down
8 changes: 7 additions & 1 deletion src/ContextRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,13 @@ public function setCurrentContext(Context $context): void

public function getCurrentContext(): Context
{
return $this->currentContext ?? throw new \LogicException('Current context not set yet.');
if (isset($this->currentContext)) {
return $this->currentContext;
}

trigger_deprecation('castor', '0.11.1', 'Calling getCurrentContext() without setCurrentContext() is deprecated. Pass a context instead to the function, or set a Current context before.');

return new Context();
}

/**
Expand Down

0 comments on commit 1ff3f1a

Please sign in to comment.