/** * @param $templateName * @param InjectionParams $injectionParams * @return Executable */ public static function create($templateName, InjectionParams $injectionParams = null) { if ($injectionParams === null) { $injectionParams = new InjectionParams(); } // This uses double-dispatch so that the first Executable can have it's // dependency injected, and then the second Exectuable that actually renders the // template has its dependencies injected separately. $fn = function (Jig $jigRender) use($templateName, $injectionParams) { $className = $jigRender->compile($templateName); $injectionParams->alias('Jig\\JigBase', $className); $fn = function (Injector $injector) use($className) { return $injector->make($className); }; $injectionParams->delegate('Jig\\JigBase', $fn); return new Executable(['Tier\\Bridge\\JigExecutable', 'createHtmlBody'], $injectionParams); }; return new Executable($fn); }