serenata/name-qualification-utilities
Composer 安装命令:
composer require serenata/name-qualification-utilities
包简介
Provides utilities for dealing with PHP name qualifications, such as resolving and localizing names.
README 文档
README
Provides various utilities related to name qualification in PHP:
- Determine what namespace and imports are active at a specific location in a file
- Resolve names to their fully qualified name based on use statements and namespaces
- Localize names from a fully qualified name back to a local name based on use statements and namespaces
This project falls under the Serenata umbrella.
Installation
composer require "serenata/name-qualification-utilities"
Usage
<?php
use Serenata\Common\Position;
use Serenata\Common\FilePosition;
use Serenata\NameQualificationUtilities;
// NOTE: Implement a suitable provider in your code.
$fileNamespaceProvider = new class implements NameQualificationUtilities\FileNamespaceProviderInterface {
public function provide(string $file): array
{
return $arrayOfNamespaceObjectsWithImportsAttached;
}
};
$positionalNamespaceDeterminer = new NameQualificationUtilities\PositionalNamespaceDeterminer($fileNamespaceProvider);
$factory = new NameQualificationUtilities\PositionalNameResolverFactory($positionalNamespaceDeterminer);
// Create a name resolver that can resolve names using the imports and namespace that apply at the specified position.
$position = new Position($someLineNumber, $someCharacterIndexOnLine);
$filePosition = new FilePosition('MyPhpFile.php', $position);
$nameResolver = $factory->create($filePosition);
$result = $nameResolver->resolve('A', NameQualificationUtilities\NameKind::CLASSLIKE);
// $result will now contain the FQCN of the class, e.g. '\A', '\SomeNamespace\A', ...
Not a PHP parser
Actual parsing of code to find available imports and namespaces is not provided, but you can use a tool such as php-parser for this. Instead, the available imports and namespaces have to be provided by the user of this library by implementing the interface FileNamespaceProviderInterface.
What is the "kind" parameter all about?
It is necessary because PHP supports use statements or imports with the same name, as long as their "kind" is different. In other words, you can import a constant with the same name as a class:
<?php
use A\B;
use function A\B;
use const A\B;
What is the difference between NamespaceNameResolver and StructureAwareNameResolver?
Some constant and function names can be ambiguous, for example:
<?php
namespace A;
$a = SOME_CONSTANT;
SOME_CONSTANT can refer to \A\SOME_CONSTANT or \SOME_CONSTANT, PHP determines which one to use at runtime:
- Resolve to
\A\SOME_CONSTANTif it exists - Resolve to
\SOME_CONSTANTif it exists - Resolve to
\A\SOME_CONSTANTagain and fail because neither exist
NamespaceNameResolver does not know how to handle this situation and will bail out with an exception that the name is ambiguous.
StructureAwareNameResolver will request additional information - from a provider you must inject into it - to determine which structures actually exist in order to successfully resolve the name.

serenata/name-qualification-utilities 适用场景与选型建议
serenata/name-qualification-utilities 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 10.29k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 05 月 05 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「utilities」 「name」 「localizing」 「qualification」 「resolving」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 serenata/name-qualification-utilities 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 serenata/name-qualification-utilities 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 serenata/name-qualification-utilities 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP Interface for Babel Street Text Analytics
A collection of enhancements and utilities for the Silverstripe UserForms module
A package to create readable, meaningful, random strings from animal names, colors and adjectives.
PHP traits to use in every project :)
A Laravel SDK for interacting with the DaData API, providing seamless integration for address validation, data enrichment, and other data processing features.
Library for inflecting Russian and Ukrainian Names. Fork of http://namecaselib.com/
统计信息
- 总下载量: 10.29k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 6
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: GPL-3.0-or-later
- 更新时间: 2018-05-05