如何使Composer(PSR-4)与“ .class.php”一起使用延期? [英] How To Make Composer (PSR-4) To Work With ".class.php" Extension?

查看:74
本文介绍了如何使Composer(PSR-4)与“ .class.php”一起使用延期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了很多找不到类错误的问题。但是最近我意识到了最初的问题。我之前关于此问题的两个问题:-

I've been facing a lot of problem with "Class Not Found" error. But recently I recognized the original problem. My previous two questions regarding the issue:-

Composer出现错误,未找到类

PHP Composer PSR-4自动加载和子命名空间,未找到类

我对使用扩展名为 class.php 的类感兴趣 parent.class.php child.class.php 。但是作曲者似乎无法识别这些文件,并显示找不到类错误。如果我使用简单的.php扩展名( child.php parent.php ),则问题已解决。

I'm interested in working with classes having extension class.php, e.g. parent.class.php and child.class.php. But composer doesn't seem to recognize these files and "Class Not Found" error is displayed. The problem is resolved if I use simple .php extension (child.php and parent.php).

我想知道是否可以使用 .class.php 扩展名来使作曲家使用我的php类文件?

I was wondering if it is possible to make composer work with .class.php extension for my php class files?

推荐答案

如果您希望代码符合PSR-4,则必须格式 classname.php

If you want your code to be PSR-4 compliant, then you MUST have your filenames in the format classname.php.

根据PSR-4规范:


终止类名对应于以.php结尾的文件名。文件名必须与终止类名的大小写匹配。

The terminating class name corresponds to a file name ending in .php. The file name MUST match the case of the terminating class name.

http://www.php-fig.org/psr/psr-4/

因此,如果您坚持使用PSR-4,那么答案就是您不能使用 .class.php 文件名。只需更改文件名即可解决问题。

So if you're sticking with PSR-4 then the answer is that you can't use your .class.php filenames. Just change the filenames and the problem will be solved.

如果由于某些原因绝对必须保留现有文件名,那么您将需要编写解决方法。拥有自动装带器功能,或者只是以老式方式手动包括它们。 (但是请记住,如果您这样做,将不会遵循PSR-4)

If you absolutely have to keep the existing filenames for some reason, then you will need to work around it by writing your own autoloader function or just include them manually the old-school way. (But remember that you won't be conforming to PSR-4 if you do this)

这篇关于如何使Composer(PSR-4)与“ .class.php”一起使用延期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆