TextMate的一个小兼容问题

Posted by Leask on December 23, 2009

我手头有不少项目是用TextMate写的,虽然最近几天开始改用vim(改用vim主要是想保持一个统一的编辑环境,在Command Line和GUI之间。),在vim完全上手之前,还是需要用TextMate一段时间。

今天工作的时候,遇到一个很奇怪的问题,我无法用Textmate的FTP/SSH插件(http://fuerstnet.de/en/ftp-ssh-bundle-textmate)来上传程序到服务器。程序提示PHP错误:

才知道原来TextMate的FTP/SSH插件是通过PHP环境上传和下载文件的。
考虑到前几天我配置了Snow Leopard本地的PHP环境体换掉了MAMP集成环境。于是考虑是不是本地的PHP环境和TextMate的插件环境不兼容。

查看插件的源代码:

!!
usr/bin/env php
// Initialize variables and load helper functions
require($_ENV['TM_BUNDLE_SUPPORT'].'/lib/helper_functions.php');
// put file to the remote host
put_file($_ENV['TM_FILENAME'], $_ENV['TM_FILEPATH'], $_ENV['TM_DIRECTORY'], $PROJECT_DIR, $PREFS);
!!


不难看出TextMate通过PHP环境变量的方式传递变量给一个PHP Shell,然后由PHP Shell的Function()上传和下载文件。经过对php.ini的分析研究,发现原来php.ini中有关于环境变量的这一个描述:

!!
; This directive determines which super global arrays are registered when PHP
; starts up. If the register_globals directive is enabled, it also determines
; what order variables are populated into the global space. G,P,C,E & S are
; abbreviations for the following respective super globals: GET, POST, COOKIE,
; ENV and SERVER. There is a performance penalty paid for the registration of
; these arrays and because ENV is not as commonly used as the others, ENV is
; is not recommended on productions servers. You can still get access to
; the environment variables through getenv() should you need to.
; Default Value: "EGPCS"
; Development Value: "GPCS"
; Production Value: "GPCS";
; !!
variables_order = "GPCS"
!!


Snow Leopard在启用php.ini这个配置文件的时候,会更改PHP环境variables_order的默认值,然而这个设置将导致PHP定义全局环境变量的功能失效。于是尝试修改为:

variables_order = "EGPCS"


重新加载插件:

osascript -e 'tell app "TextMate" to reload bundles'


问题得到解决。

注意,如果你使用Snow Leoprad并使用系统内置的PHP环境,而且你用TextMate+FTP/SSH Bundle,你将遇到和我一样的问题。虽然variables_order = "EGPCS"并不是PHP推荐的设置值,但是目前看来只能这样了。期待TextMate的后续版本能解决这个问题。