定制 mouf/classname-mapper 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

mouf/classname-mapper

最新稳定版本:v1.0.2

Composer 安装命令:

composer require mouf/classname-mapper

包简介

Provides a way to find in which PHP files a class will be looked upon.

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version License Scrutinizer Code Quality Build Status Coverage Status

ClassName mapper

What is it?

Some packages generate PHP classes. When a package generates a class, it needs to know in which directory to put the PHP file, so that the class can be autoloaded by the autoloader. This package is here to help you find in which directory to write your PHP file.

This package contains a simple ClassNameMapper PHP class.

This class will map a fully qualified class name (FQCN) to one or many possible file names according to PSR-0 or PSR-4 rules defined in your composer.json file.

So you pass the ClassNameMapper a FQCN, and it gives you back a list of file paths that will be checked by the Composer autoloader.

This is very useful in case you want to generate PHP classes, and you don't know where to write those classes.

Sample

Imagine your composer.json looks like this:

{
    "require" : {
        "mouf/classname-mapper": "~1.0"
    },
    "autoload" : {
        "psr-4" : {
            "Acme\\" : "src/"
        }
    }
}

Now, let's say you want to create a Acme\Controller\MyController class. Where should you put the class? To a PHP developer, it is obvious the class will go in src/Controller/MyController.php. To a PHP program, it is a tricky problem. The ClassNameMapper is here to solve the problem:

use Mouf\Composer\ClassNameMapper;

// This will create a mapper from your root composer file.
$mapper = ClassNameMapper::createFromComposerFile();

$files = $mapper->getPossibleFileNames('Acme\Controller\MyController');
// $files == ["src/Controller/MyController.php"];

You can also query the ClassNameMapper for a list of all namespaces that are configured in your composer.json file:

$namespaces = $mapper->getManagedNamespaces();
// $namespaces == ["Acme\\"];

统计信息

  • 总下载量: 2.29M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 11
  • 点击次数: 3
  • 依赖项目数: 8
  • 推荐数: 0

GitHub 信息

  • Stars: 11
  • Watchers: 5
  • Forks: 3
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固