配置php-cs-fixer和PATH变量

时间:2016-10-05 03:10:03

标签: php atom-editor

前段时间,我成功配置Atom以使用php-cs-fixer来美化我的PHP,但现在我需要在另一台Mac上完成相同的过程,并且不记得我是怎么做到的。

作为前端开发人员,我不是PHP专家,但据我所知,Atom插件只是中间人,使用php-cs-fixer进行实际修复,默认情况下,它不具备进入。安装修复程序后,我必须将其位置添加到PATH变量中。令人困惑的部分是我没有通过Atom(已检查〜/ .atom / packages)安装修复程序,也没有通过Homebrew安装(通过brew list确认),但是,该文件存在于/ usr / local / bin中。如果我移动它,Atom会返回原始错误,因此肯定会使用此文件:

See https://github.com/FriendsOfPHP/PHP-CS-Fixer for program installation instructions.
Your program is properly installed if running 'which php-cs-fixer' in your Terminal returns an absolute path to the executable. If this does not work then you have not installed the program correctly and so Atom Beautify will not find the program. Atom Beautify requires that the program be found in your PATH environment variable. 
Note that this is not an Atom Beautify issue if beautification does not work and the above command also does not work: this is expected behaviour, since you have not properly installed your program. Please properly setup the program and search through existing Atom Beautify issues before creating a new issue. See https://github.com/Glavin001/atom-beautify/search?q=php-cs-fixer&type=Issues for related Issues and https://github.com/Glavin001/atom-beautify/tree/master/docs for documentation. If you are still unable to resolve this issue on your own then please create a new issue and ask for help.
Hide Stack Trace
Error: Could not find 'php-cs-fixer'. The program may not be installed.
    at PHPCSFixer.module.exports.Beautifier.commandNotFoundError (/Users/ourcore/.atom/packages/atom-beautify/src/beautifiers/beautifier.coffee:204:14)
    at /Users/ourcore/.atom/packages/atom-beautify/src/beautifiers/beautifier.coffee:304:22
    at tryCatcher (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/promise.js:510:31)
    at Promise._settlePromise (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/promise.js:567:18)
    at Promise._settlePromise0 (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/promise.js:612:10)
    at Promise._settlePromises (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/promise.js:687:18)
    at Async._drainQueue (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/async.js:138:16)
    at Async._drainQueues (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/async.js:148:10)
    at Async.drainQueues (/Users/ourcore/.atom/packages/atom-beautify/node_modules/bluebird/js/release/async.js:17:14)
    at process._tickCallback (internal/process/next_tick.js:103:7)

which php-cs-fixer返回/usr/local/bin/php-cs-fixer,我的PATH变量目前包含/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Users/ourcore/.atom/packages/php-cs-fixer

我想我的问题是,如果PATH变量似乎在不同的位置指向它,那么修复工具如何工作?它是如何最终到达的?我的PATH中的位置是否重要,或者Atom插件是否知道查看/ usr / local / bin?我只是想在重复之前完全理解整个过程。

编辑:在进一步测试时,我从我的PATH中删除了Atom目录并且它没有影响插件,因此我将文件复制到第二台Mac上的同一目录中,它运行没有问题,无需编辑PATH。修复文件是否有人通知操作系统?

1 个答案:

答案 0 :(得分:0)

首先测试“哪个php-cs-fixer”或“哪里有php-cs-fixer”(取决于你正在运行的操作系统),如果终端没有返回任何内容,那么安装实际上有些问题最好的办法就是手动安装它。

前往https://github.com/FriendsOfPHP/PHP-CS-Fixer并从那里下载并按照安装步骤操作,之后一切都会很好