简体   繁体   English

如何使Wamp类名称区分大小写

[英]How to make wamp class names case sensitive

I've run into a problem when transfering files from a WAMP production environment to a LAMP staging/live environment. 将文件从WAMP生产环境传输到LAMP暂存/实时环境时,我遇到了问题。

In Yii, classes have to be named the same as their filenames so that they can be auto loaded. 在Yii中,必须使用与文件名相同的名称来命名类,以便可以自动加载它们。

The problem is that if the filename is the same but with a different case then it works on windows but not on linux. 问题是,如果文件名相同但大小写不同,则它可以在Windows上运行,但不能在Linux上运行。 How can I force WAMP to check for case sensitivity in the filename before it gets to the LAMP server? 如何强制WAMP在到达LAMP服务器之前检查文件名中是否区分大小写?

WAMP has nothing to do with names case. WAMP与名称大小写无关。 You need to pay attention when you create files. 创建文件时需要注意。 Naming convention is very important, as in larger projects you might get lost if your class/file names are inconsistent. 命名约定非常重要,因为在较大的项目中,如果类/文件名不一致,您可能会迷路。

Also check your file transfer tool, sometimes there are some setting to rename files to lowercase etc. 还要检查您的文件传输工具,有时会有一些设置将文件重命名为小写等。

EDIT : Well, you could use CFileHelper::findFiles(Yii::getPathOfAlias('application'), array('fileTypes' => array('php'))) , then compare filename with class name. 编辑 :嗯,您可以使用CFileHelper::findFiles(Yii::getPathOfAlias('application'), array('fileTypes' => array('php'))) ,然后将文件名与类名进行比较。 To get class name without including it, use below code snippet from this answer : 要获取类名而不包含它,请使用此答案中的以下代码片段:

$fp = fopen($file, 'r');
$class = $buffer = '';
$i = 0;
while (!$class) {
    if (feof($fp)) break;

    $buffer .= fread($fp, 512);
    $tokens = token_get_all($buffer);

    if (strpos($buffer, '{') === false) continue;

    for (;$i<count($tokens);$i++) {
        if ($tokens[$i][0] === T_CLASS) {
            for ($j=$i+1;$j<count($tokens);$j++) {
                if ($tokens[$j] === '{') {
                    $class = $tokens[$i+2][1];
                }
            }
        }
    }
}

Side note : To avoid bugs, use decent IDE like Eclipse or NetBeans and use new PHP Class instead of new PHP File option. 旁注 :为了避免错误,请使用像EclipseNetBeans这样的IDE,并使用new PHP Class而不是new PHP File选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM