Пример #1
0
 public function testPath()
 {
     $fn1 = function () {
         return "actual";
     };
     $fn2 = function () {
         return "setup";
     };
     $injectionParams = new InjectionParams();
     $exec = new Executable($fn1, $injectionParams, $fn2);
     $exec->getInjectionParams();
     $callable = $exec->getCallable();
     $setupCallable = $exec->getSetupCallable();
     $this->assertEquals("setup", $setupCallable());
     $this->assertEquals("actual", $callable());
 }
Пример #2
0
 /**
  * @param $result
  * @return TierException
  */
 public static function getWrongTypeException($result, Executable $executable)
 {
     $messageStart = self::RETURN_VALUE;
     $messageStart .= " Instead %s returned, when calling executable %s";
     if ($result === null) {
         $detail = 'null';
     } else {
         if (is_object($result) === true) {
             $detail = "object of type '" . get_class($result) . "'";
         } else {
             $detail = "variable of type '" . gettype($result) . "'";
         }
     }
     $callableInfo = var_export($executable->getCallable(), true);
     $message = sprintf($messageStart, $detail, $callableInfo);
     return new InvalidReturnException($message, $result);
 }
Пример #3
0
 /**
  * @param Executable $tier
  * @param Injector $injector
  * @return mixed
  */
 public static function executeExecutable(Executable $tier, Injector $injector)
 {
     // Setup the information created by the previous Tier.
     if (($injectionParams = $tier->getInjectionParams()) !== null) {
         $injectionParams->addToInjector($injector);
     }
     // If the next Tier has a setup function, call it.
     $setupCallable = $tier->getSetupCallable();
     if ($setupCallable !== null) {
         $injector->execute($setupCallable);
     }
     // Call this Tier's callable.
     return $injector->execute($tier->getCallable());
 }