Skip to content

Commit

Permalink
Improve Package status check from ouside the Package class
Browse files Browse the repository at this point in the history
- Introduced Package::hasContainer(), Package::isFailed(), Package::hasReachedStatus() to ease status check from ouside teh PAckage class
- Use the above methods to improve PackageProxyContainer access ot proxied container
  • Loading branch information
gmazzap committed Aug 27, 2024
1 parent d4ea195 commit e42759f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
7 changes: 2 additions & 5 deletions src/Container/PackageProxyContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,9 @@ private function tryContainer(): bool
return true;
}

/** TODO: We need a better way to deal with status checking besides equality */
if (
$this->package->statusIs(Package::STATUS_INITIALIZED)
|| $this->package->statusIs(Package::STATUS_MODULES_ADDED)
|| $this->package->statusIs(Package::STATUS_READY)
|| $this->package->statusIs(Package::STATUS_BOOTED)
$this->package->hasContainer()
|| $this->package->hasReachedStatus(Package::STATUS_INITIALIZED)
) {
$this->container = $this->package->container();
}
Expand Down
27 changes: 26 additions & 1 deletion src/Package.php
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ public function connect(Package $package): bool
}

// Don't connect, if already booted or boot failed
$failed = $this->statusIs(self::STATUS_FAILED);
$failed = $this->isFailed();
if ($failed || $this->checkStatus(self::STATUS_INITIALIZED, '>=')) {
$reason = $failed ? 'an errored package' : 'a package with a built container';
$status = $failed ? 'failed' : 'built_container';
Expand Down Expand Up @@ -606,6 +606,14 @@ public function container(): ContainerInterface
return $this->containerConfigurator->createReadOnlyContainer();
}

/**
* @return bool
*/
public function hasContainer(): bool
{
return $this->hasContainer;
}

/**
* @return string
*/
Expand All @@ -623,6 +631,23 @@ public function statusIs(int $status): bool
return $this->checkStatus($status);
}

/**
* @return bool
*/
public function isFailed(): bool
{
return $this->status === self::STATUS_FAILED;
}

/**
* @param int $status
* @return bool
*/
public function hasReachedStatus(int $status): bool
{
return ($this->status !== self::STATUS_FAILED) && $this->checkStatus($status, '>=');
}

/**
* @param int $status
* @param value-of<Package::OPERATORS> $operator
Expand Down

0 comments on commit e42759f

Please sign in to comment.