ZF4 Blog

Builder Pattern Gets Closures

In a small feature change to the Builder Pattern library, I've added the ability for a build parameter to be defined as a closure. e.g.

    protected function setBuildItems()
        $this->buildItems = [
            'name' => '',
            'createdate' => new \DateTime(),
            'account' => new AccountBuilder(),
            'exportName => function(){return 'BuilderPattern!';}

This adds a greater degree of flexibility to the build mechanism. The chippyash\Zend\Acl XML builder makes of this.