Laravel4, Open source by IDE on clicking file

Tags : Laravel4  

Yesterday, I tried to change the code to display stack trace when an exception happened, for Laravel 4. Because I don't want to remember file name and line number, then open it by IDE/editor. So I wanted to show code by click the file as link.

And found the word 'xdebug.file_link_format'. And suddenly remember it. Laravel 4 worked for it?? So, I want to use it!

Then I set up to use it on Linux (openSUSE 12.3) with NetBeans( or your favored IDE/editor)

Oversee

XDebug supported 'file_link_format' option to put links with specific protocol on files in stack trace. Firefox can specify a program for each protocol on links. NetBeans(also normally most of IDEs and editors) can open a file with moving the cursor to specific line number by option on command-line command.

Protocol name

Protocol name is just a string. You can select freely without already exist.

On this example, I used 'netbeans' as protocol name.

Making Script

At first, we will make a shell script. It is most easy way I tried. And widely apply for another IDEs/editors.

Ideally make a file to /home/Your-User-Name/bin/netbeans, or somewhere got the 'PATH' to execute command. (Of course, you can use favored file name.)

#!/bin/bash

f=`echo $1 | cut -d @ -f 1 | sed 's/netbeans:\/\///'`
l=`echo $1 | cut -d @ -f 2`

/home/Your-User-Name/netbeans-7.3/bin/netbeans --open $f:$l

On the last line, I tried to work netbeans on my environment. Please put full path to your favored program to see source of the file you clicked on stack trace.

And please change file specified option. It is different with your program to open the source code. Check how to use options to specify file and line number, and put them on the last command.

$f change to file name. $l cange to line number.

And 'netbeans' is protocol name I used in the following line.

f=`echo $1 | cut -d @ -f 1 | sed 's/netbeans:\/\///'`

So change it to your protocol name.

Firefox setting

It is FF setting on linux.

Ref: Register protocol

  1. Put about:config on above location bar. Then hit ENTER key. Warning dialog will come up, then click 'OK' to progress.
  2. List setting names and values. On them, it is be OK on anywhere, right click mouse button. Select 'Create new item' (or simuller item, I didn't check English strings. Sorry) then choice 'Boolean'.
  3. Specify "network.protocol-handler.expose.netbeans" as name, "false" as value. On this step, 'netbeans' storing is protocol name, so you must change your protocol name.

On this time, execute program didn't bind with your protocol. It will come up when you click the first link with your protocol.

php.int

Change php.ini. (Or recently, most of linux distributions used /etc/php5/conf.d to sort options. So in it case, /etc/php5/conf.d/xdebug.ini is the file you must change.)

Add the line:

xdebug.file_link_format = "netbeans://%f@%l"

By this. specified link will put on files in stack trace when an exception happened. For example, an exception happened on /home/user/a.php, line 10, the link is "netbeans://home/user/a.php@10".

And don't forget to restart your apache after changing PHP setting.

Specify the program for your protocol

Start your NetBeans (or your IDE/Editor), and make error code on Laravel 4 environment. Then access the page error will happen.

It will show an exception message, and stack trace. Check the files. Put on the mouse cursor. It will show link to filename @ line number with your protocol.

Now click it. Firefox will ask which program use for your protocol. Please select the script we made at first. Don't specify IDE/editor directly.

From here, you can open the file with line number by just click file link on stack trace.