Symfony bundle using Hack

1 minute read

I’ve been working with the website the last couple of weeks. In a discussion on Github we argued how a nice excerpt should look like. We decided that the excerpt twig filter should take a HTML string as input and make it shorter without breaking the HTML. It should also remove tables and convert headings.

Since runs on HHVM I decided to write the Twig filter in Hack. The bundle is not optimized or optimal, it is written to demonstrate some cool Hack features. You will find the bundle here and the cool hack features is found in this file. I wanted to make sure you could run the website on a normal PHP installation as well. So I added two excerpt services. One written in PHP and one written in Hack. In the dependency injection configuration I made a check if HACK_VERSION is defined to decide which service to load.

If you want to try the Hack bundle with the project I recommend you reading my post about how to install HHVM and Hack.

What to look at

When you are reading the HackExcerpt class pay extra attention to:

  • the first rows declaring the Heading shape
  • the constructor
  • the method declaration of getDefaults
  • the preg_replace_callback function in convertHeadings

Leave a Comment