2016-12-05 81 views
5

在我Cloud09 IDE我启用了PHP设置“自定义代码格式化”PHP美化/格式化

但保存在一个错误的结果:No code formatter set for php: please check your project settings没有格式化预定义像JS(esformatter -i "$file")和谷歌是没有帮助的,以及...

enter image description here

如何使用此设置?

如何在Cloud9上安装PHP格式化程序?

我唯一的搜索显示this Pear package,但它似乎过时了。

回答

6

下载php-cs-fixerhttps://github.com/FriendsOfPHP/PHP-CS-Fixer您CLOUD9工作区:

$ wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.0.0/php-cs-fixer.phar -O ~/php-cs-fixer 

把它放在你~/bin目录:

$ mkdir ~/bin; mv ~/php-cs-fixer ~/bin 

使文件可执行:

$ chmod a+x ~/bin/php-cs-fixer 

配置IDE的自定义代码格式化程序设置PHP使用所述格式化与whatever rules you want

php-cs-fixer fix "$file" [email protected],@PSR2 

这就是我的~/workspace/.c9/project.settings文件的外观:

... 
"php": { 
    "@completion": true, 
    "@formatOnSave": true, 
    "@formatter": "php-cs-fixer fix \"$file\" [email protected],@PSR2", 
    "@path": ".:./vendor:/usr/local/bin" 
}, 
... 
+2

真棒,此感谢! –

+0

感谢其工作:) – user1510230