PHPSTORM使用技巧

最近在部门内部做了一次关于PHPSTORM的使用分享,整理如下

Xdebug配置

  1. 配置xdebug.ini文件如下,我这里设置Xdebug的客户端地址为localhost:9999,修改完记得重启fpm
[xdebug]
zend_extension="/usr/local/opt/php70-xdebug/xdebug.so"

xdebug.profiler_enable=on
xdebug.trace_output_dir="/Users/Ponny/Documents/xdebug"
xdebug.profiler_output_dir="/Users/Ponny/Documents/xdebug"
xdebug.remote_enable=on
xdebug.remote_autostart=on
xdebug.remote_handler=dbgp
xdebug.remote_host=localhost
xdebug.remote_port=9999
xdebug.max_nesting_level=10000
xdebug.show_exception_trace=on
xdebug.auto_trace=on
xdebug.idekey="PHPSTORM"
  1. 配置PHPSTORM

    • 设置Xdebug客户端:Languages & Frameworks -> PHP -> DebugPHPSTORM使用技巧
    • 设置域名和代码目录映射:Languages & Frameworks -> PHP -> ServerPHPSTORM使用技巧
  2. 开始监听PHPSTORM使用技巧
  3. 访问lechat.com/dailysms/create,将自动跳转到PHPSTORM的Xdebug面板,可以看到功能相当之丰富PHPSTORM使用技巧
  4. 我们在第一步设置了xdebug.profiler_output_dir中,可以用PHPSTORM来分析profiler文件:Tools -> Analyze Xdebug Profiler Snapshot

PHPSTORM使用技巧

排除指定的目录

如果是PSR-0的代码,可能会出现相同的类名出现在不同的目录下,那么当查看类方法、常量定义的时候,自动跳转功能就失效了。遇到这种问题,我们可以选中这个目录,然后Mark Directory As Excluded

代码片段

配置路径:Editor -> Live Templates
制作代码片段:

  1. 填写片段名称、描述、模板PHPSTORM使用技巧
  2. 定义默认的变量名PHPSTORM使用技巧

ide-helper

安装的一些第三方扩展在PHPSTORM上不能进行类跳转、类搜索等功能。
解决这个问题,可以在github上搜索相应的ide-helper,在PHPSTORM上include进来。

下面以swoole扩展为例:

  1. 在Github上搜索swoole ide helper
  2. 选择git@github.com:eaglewu/swoole-ide-helper.git,并clone到本机
  3. 配置PHPSTORMPHPSTORM使用技巧
  4. 使用效果PHPSTORM使用技巧

Macros

macros提供了一种方便的方式来自动执行重复的程序,可以录制、编辑、回放自定义的macros

过程:

  1. 开始录制:Edit -> Macros -> Start Macro Recording
  2. 在PHPSTORM上编写代码,但最好不要用快捷键来自动补全代码,因为不识别
  3. 录制完成后,点击右下角的结束按钮,并为macros命名
  4. Edit -> Macros下选择要播放的macros,PHPSTORM会自动将你录制的macros重放到编辑器里

行选择模式

能在多行多列间进行选择、操作

路径:Edit -> Column Selection ModePHPSTORM使用技巧

快速查阅PHP文档

选中需要查阅的函数,自动跳转到php.net中相应的文档

路径:View -> External Document

快捷键:shift + F1

演示代码模式

当开会需要在投影上演示代码时,可以用此模式,排版显示会更利于观看

路径:View -> Enter Presention Mode

相关推荐