componenta/scope 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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 string value and matches() comparison.
  • ScopedInterface: implemented by objects that expose a Scopes collection.
  • Scopes: non-empty immutable collection of ScopeInterface values.
  • 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 when ScopeName receives an empty value or Scopes::from() receives a non-scope value.
  • EmptyScopesException: thrown when Scopes::from() receives an empty iterable.

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 9
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-06-17

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固