duanpen9294 2013-08-23 06:50
浏览 35

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

I've run into a problem when transfering files from a WAMP production environment to a LAMP staging/live environment.

In Yii, classes have to be named the same as their filenames so that they can be auto loaded.

The problem is that if the filename is the same but with a different case then it works on windows but not on linux. How can I force WAMP to check for case sensitivity in the filename before it gets to the LAMP server?

  • 写回答

1条回答 默认 最新

  • duanmeng3126 2013-08-23 10:51
    关注

    WAMP has nothing to do with names case. 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. 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.

    评论

报告相同问题?

悬赏问题

  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据