Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.

addReturn/returnCase consistency, support for lambda value renderers

Choose a tag to compare

@fredemmott fredemmott released this 19 Feb 01:56
4525842

addReturn() and returnCase() consistency

These methods now take an IHackBuilderValueRenderer instance to be consistent with other methods such as addAssignment and addValue.

This means that addReturn('literal') is no longer valid - you can replace it with any of:

  • addReturn($any_literal, HackBuilderValues::literal())
  • addReturnf('some literal with no placeholders')
  • addReturnf('%s', $any_literal)

A similar change is needed for returnCase() -returnCasef() has also been added to this release

Lambda key/value renderers

If you need to generate code for a value in a way that hack-codegen doesn't have built-in support, you now have 3 options:

  • pre-process the data and use HackBuilderValues::literal() or HackBuilderKeys::literal()
  • add a new class implements IHackBuilderValueRenderer<T> or IHackBuilderKeyRenderer<T>
  • use HackBuilderKeys::lambda(($config, $value) ==> 'code') or HackBuilderValues::lambda(($config, $value) ==> $code)

The lambda approach is especially useful for containers.