super-kernel/composer-package-registry
Composer 安装命令:
composer require super-kernel/composer-package-registry
包简介
Composer installed package registry parser with per-package cache support for SuperKernel.
README 文档
README
A read-only Composer package registry component for SuperKernel.
It parses composer.json and composer.lock from a project root, resolves the root package and installed packages,
scans package autoload metadata, and stores each scanned package as an independent cache file under the configured
vendor directory. Path resolution is integrated with super-kernel/runtime-context, which acts as the runtime-root
provider and the root-relative path adapter for project-level path operations.
Features
- Parses the root package from
composer.json - Parses installed and dev-installed packages from
composer.lock - Treats the current project package as
root, regardless of its declared Composer type - Supports
psr-4,psr-0,classmap,files, andexclude-from-classmap - Keeps
autoloadandautoload-devstrictly separated - Skips only the missing scan target, never the whole registry load because of a single missing autoload-dev path
- Skips package scanning when the physical package directory does not exist
- Caches each package independently under
{vendor}/.super-kernel/packages/ - Reloads package objects from serialized cache files instead of returning the in-memory scan result directly
Requirements
- PHP
~8.4.0 super-kernel/runtime-context:dev-main
Installation
composer require super-kernel/composer-package-registry
Package Types
This component uses interface constants instead of enums.
use SuperKernel\ComposerPackageRegistry\Contract\PackageTypeInterface; PackageTypeInterface::ROOT; PackageTypeInterface::LIBRARY; PackageTypeInterface::METAPACKAGE; PackageTypeInterface::CUSTOM;
Public Contracts
PackageInterface
getName(): stringgetType(): stringgetRawType(): ?stringgetReference(): ?stringisRoot(): boolisDev(): boolgetComposerConfig(): arraygetRelativePath(): stringgetAutoload(): arraygetAutoloadDev(): arraygetFiles(bool $includeDev = true): arraygetClassMap(bool $includeDev = true): array
PackageRegistryInterface
getRootPackage(): PackageInterfacegetPackages(): arraygetPackagesByType(string $type): arraygetPackage(string $name): ?PackageInterfacehasPackage(string $name): boolhasDevPackages(): boolgetVendorDirectory(): stringgetCacheDirectory(): string
PackageRegistryLoaderInterface
load(string $projectRoot): PackageRegistryInterfaceloadCurrentRuntimeProject(): PackageRegistryInterface
Vendor Directory Resolution
The vendor directory is resolved with the following priority:
config.vendor-binconfig.vendor-dirvendor
Cache Layout
Cache files are stored under:
{vendor-directory}/.super-kernel/packages/
Examples:
vendor/.super-kernel/packages/root-package.cache
vendor/.super-kernel/packages/psr/log.cache
vendor/.super-kernel/packages/symfony/console.cache
A package name such as symfony/console therefore becomes a nested cache path.
Cache Refresh Rules
If a cache file already exists, it is refreshed when:
- the cached package reference is
null, or - the cached package reference differs from the currently installed reference
After refresh, the component reads the cache file again and returns the deserialized PackageInterface instance.
Scanning Rules
Missing package directory
If the resolved package directory does not exist, package scanning is skipped for that package only.
The package metadata still exists in the registry, but its scanned class map and files are empty.
Missing autoload or autoload-dev scan targets
A missing path inside psr-4, psr-0, classmap, or files does not invalidate the package.
Only that specific target is skipped.
This is especially important for autoload-dev: a missing dev path skips only the dev scan path, not the package scan.
Usage
<?php declare(strict_types=1); use SuperKernel\ComposerPackageRegistry\ComposerPackageRegistryLoader; use SuperKernel\ComposerPackageRegistry\Contract\PackageTypeInterface; $loader = new ComposerPackageRegistryLoader(); $registry = $loader->load(__DIR__); $root = $registry->getRootPackage(); var_dump($root->getName()); var_dump($root->getType() === PackageTypeInterface::ROOT); var_dump($root->getClassMap(includeDev: true)); $package = $registry->getPackage('psr/log'); if ($package !== null) { var_dump($package->isDev()); var_dump($package->getReference()); var_dump($package->getRelativePath()); var_dump($package->getFiles()); var_dump($package->getClassMap()); }
Testing
The PHPUnit suite uses self-bootstrap tests.
It parses the current repository's own composer.json and composer.lock, loads the current project as the root
package, and verifies cache generation under the configured vendor directory. It does not generate ad-hoc fixture
projects inside the test suite.
Run tests with:
composer phpunit
Current assertions cover:
- root package parsing from the current project
- installed package discovery from the current project's
composer.lock - package registry filtering, lookup, counting, and iteration
- separation between
autoloadandautoload-dev - cache file generation and cache payload deserialization under
{vendor}/.super-kernel/packages/ - loading through the current runtime project entrypoint
Notes
The class map builder scans PHP source files and extracts symbols directly instead of reproducing Composer's generated autoloader internals byte-for-byte.
For regular PSR-4, PSR-0, classmap, and files-based package layouts this is stable and predictable enough for framework-level metadata inspection.
License
This project is licensed under the MIT License.
See the LICENSE file for full license text.
super-kernel/composer-package-registry 适用场景与选型建议
super-kernel/composer-package-registry 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「package」 「autoload」 「composer」 「classmap」 「super-kernel」 「package-registry」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 super-kernel/composer-package-registry 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 super-kernel/composer-package-registry 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 super-kernel/composer-package-registry 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Environment processor and contexts autoloader
This composer plugin enables installation of GravityForms WordPress plugin and its addons.
Extension to autoload modules dynamically
Class loader implementation (PSR-0, PSR-4)
统计信息
- 总下载量: 1
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 33
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-15