示例#1
0
文件: TierJig.php 项目: danack/tier
 public function createJigExecutable($templateName, InjectionParams $injectionParams = null)
 {
     if ($injectionParams === null) {
         $injectionParams = new InjectionParams();
     }
     $className = $this->jig->compile($templateName);
     $injectionParams->alias('Jig\\JigBase', $className);
     return new Executable(['Tier\\Bridge\\TierJig', 'createHtmlBody'], $injectionParams);
 }
示例#2
0
 /**
  * @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);
 }
示例#3
0
 public function testReturnInjectionParams()
 {
     $tierApp = new TierApp(new Injector(), new NullCallback());
     $addInjectionParamsFn = function () {
         $injectionParams = new InjectionParams();
         $injectionParams->alias('Fixtures\\FooInterface', 'Fixtures\\FooImplementation');
         return $injectionParams;
     };
     // When tier tries to instantiate this, it will fail if the alias
     // hasn't been added.
     $requiresInterfaceFn = function (\Fixtures\FooInterface $foo) {
         return TierApp::PROCESS_END;
     };
     $tierApp->addExecutable(10, $addInjectionParamsFn);
     $tierApp->addExecutable(20, $requiresInterfaceFn);
     $tierApp->executeInternal();
 }