componenta/scope
Composer 安装命令:
composer require componenta/scope
包简介
Shared execution scope contracts and value objects for Componenta packages
README 文档
README
Shared execution scope contracts and value objects for Componenta packages.
Use this package when a framework component must declare or check where it is allowed to run: HTTP, CLI, WebSocket, queue worker, or a package-specific scope.
Installation
composer require componenta/scope
What It Provides
ScopeInterface: a scope marker with a stringvalueandmatches()comparison.ScopedInterface: implemented by objects that expose aScopescollection.Scopes: non-empty immutable collection ofScopeInterfacevalues.ScopeName: final value object for custom string scopes when a package-specific enum is not needed.
Concrete enums should live in the package that owns the execution mode. For example, componenta/app provides Componenta\App\Scope, and componenta/interceptor provides Componenta\Interceptor\Scope.
Defining Scopes
use Componenta\Scope\ScopeInterface; enum AppScope: string implements ScopeInterface { case HTTP = 'http'; case CLI = 'cli'; public function matches(ScopeInterface $scope): bool { return $this->value === $scope->value; } }
For ad-hoc scopes:
use Componenta\Scope\ScopeName; $scope = new ScopeName('worker');
Declaring Scoped Objects
use Componenta\Scope\ScopedInterface; use Componenta\Scope\Scopes; final class HttpOnlyService implements ScopedInterface { public Scopes $scopes { get => Scopes::of(AppScope::HTTP); } }
Matching
$scopes = Scopes::of(AppScope::HTTP, AppScope::CLI); $scopes->contains(new ScopeName('http')); // true $scopes->contains(new ScopeName('queue')); // false $other = Scopes::of(new ScopeName('worker'), new ScopeName('cli')); $scopes->containsAny($other); // true
Scopes::from() accepts any iterable of ScopeInterface values and rejects empty iterables.
Errors
InvalidScopeException: thrown whenScopeNamereceives an empty value orScopes::from()receives a non-scope value.EmptyScopesException: thrown whenScopes::from()receives an empty iterable.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 9
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-06-17