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

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

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

componenta/tokenizer

Composer 安装命令:

composer require componenta/tokenizer

包简介

Token-based PHP source inspection helpers for Componenta

README 文档

README

PHP declaration tokenizer used by class discovery.

Installation

composer require componenta/tokenizer

Requirements

  • PHP 8.4+

Related Packages

Package Why it matters here
componenta/class-finder Walks PHP files and uses this tokenizer for each source file.
componenta/app and *-app packages Use class discovery during application cache compilation.
PHP Reflection Used only when ClassInfo::$reflector is requested and the declaration is autoloadable.

What It Provides

  • TokenizerInterface: public contract for parsing PHP source.
  • Tokenizer: token-based parser for named declarations.
  • ClassInfo: immutable declaration metadata with lazy reflection.
  • DeclarationType: enum for class, interface, trait, and enum declarations.

Anonymous classes are ignored. The tokenizer assumes syntactically valid PHP input.

Parsing Source

use Componenta\Tokenizer\Tokenizer;

$declarations = (new Tokenizer())->parse(<<<'PHP'
<?php

namespace App;

final readonly class User {}
interface UserRepository {}
trait Timestamped {}
enum UserStatus: string { case Active = 'active'; }
PHP);

Each item is a ClassInfo:

$info = $declarations[0];

$info->fullyQualifiedName; // App\User
$info->name;               // User
$info->namespace;          // App
$info->type;               // DeclarationType::Class_
$info->isFinal;            // true
$info->isReadonly;         // true
$info->isConcrete;         // true

Search Modes

Use bitmasks to restrict declaration types:

use Componenta\Tokenizer\TokenizerInterface;

$classes = $tokenizer->parse($source, TokenizerInterface::SEARCH_CLASSES);
$contracts = $tokenizer->parse(
    $source,
    TokenizerInterface::SEARCH_INTERFACES | TokenizerInterface::SEARCH_TRAITS,
);

Available flags:

  • SEARCH_CLASSES
  • SEARCH_INTERFACES
  • SEARCH_TRAITS
  • SEARCH_ENUMS
  • SEARCH_ALL

Reflection

ClassInfo::$reflector is lazy and requires the declaration to already be loaded.

if ($info->exists()) {
    $reflector = $info->reflector;
}

统计信息

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

GitHub 信息

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

其他信息

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

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固