During December, symfony is releasing a chapter a day of the advent calendar. The articles are about advanced topics. So far we have read about routing, productivity enhancement, sending emails, custom widget and validators, forms, and one topic is about extending the Web Debug Toolbar.

The Web Debug Toolbar is one of the best features of symfony. It provides extensive information about your application (configuration & performance). The article explains how to extend the toolbar by adding custom panels. The possibilities are endless! Immediately after reading the article, I started thinking on different uses. I thought that a link checker would be a great addition. The idea would be to get all the links in the page currently looking at and detect broken links. So I started hacking something together. Here is the result.

Because the panel needs to check all links on the page, rendering the page gets slowed down considerably. So it becomes annoying after a few reloads, so I decided to only enable it by passing a parameter to the URL. By passing ?check_links to any URL in your project, it will check the links in the content of the response.

linkchecker_list

The panel also displays the title in red if there are any broken links by setting the status of the panel as described in the article. By clicking on the title, you get a list of all the links and its status.

linkchecker_status

I will prepare a plugin to encapsulate this functionality and I will release it. If you have any other ideas, let us know!

To install it, edit your config/ProjectConfiguration.class.php file and add this method:

  public function initialize()
  {
    $this->dispatcher->connect('debug.web.load_panels', array(
        'sgWebDebugPanelLinkChecker',
        'listenToLoadDebugWebPanelEvent'
    ));
  }

Then, download the sgWebDebugPanelLinkChecker.php class and put it in lib/debug. After that, add ?check_links to your URL and check it out. I actually found a couple of broken links in our site upon testing.

The article was great describing how to hide the panel, change its status and set the title and content, get a URL parameter, all features used in this example.

To do: Check https links.