/** * @param $result mixed The result produced by running the previous executable. * @param Executable $executable The executable that was just run to produce * the result. * @return int * @throws TierException * @throws \Auryn\ConfigException */ protected function processResult($result, Executable $executable) { // If it's a new Tier to run, setup the next loop. if ($result instanceof InjectionParams) { $result->addToInjector($this->injector); return self::PROCESS_CONTINUE; } // If it's a new Tier to run, setup the next loop. if ($result instanceof Executable) { $this->executableListByTier->addExecutable($result); return self::PROCESS_CONTINUE; } if ($result === null && $executable->isAllowedToReturnNull() === true) { return self::PROCESS_CONTINUE; } // if (is_array($result) === true && // count($result) !== 0) { // //It's an array of tiers to run. // foreach ($result as $executableOrCallable) { // if (($executableOrCallable instanceof Executable) === true) { // $this->executableListByTier->addExecutable($executableOrCallable); // continue; // } // else if (is_callable($executableOrCallable) === true) { // $newExecutable = new Executable($executableOrCallable); // $this->executableListByTier->addExecutable($newExecutable); // continue; // } // // throw InvalidReturnException::getWrongTypeException($result, $executable); // } // return self::PROCESS_CONTINUE; // } if ($result === false) { // The executed tier wasn't able to handle it e.g. a caching layer // There should be another tier to execute in this stage. return self::PROCESS_CONTINUE; } // If the $result is an expected product share it for further stages foreach ($this->expectedProducts as $expectedProduct => $created) { if ($result instanceof $expectedProduct) { if (is_subclass_of($result, $expectedProduct) === true) { //product is a sub-class of the expected product. Setup an //alias for it $this->injector->alias($expectedProduct, get_class($result)); } $this->expectedProducts[$expectedProduct] = true; $this->injector->share($result); return self::PROCESS_CONTINUE; } } if ($result === self::PROCESS_CONTINUE || $result === self::PROCESS_END) { return $result; } // Otherwise it's an error throw InvalidReturnException::getWrongTypeException($result, $executable); }
/** * @param $result * @throws InvalidReturnException * @throws TierException * @return int */ private function processResult($result) { // If it's a new Tier to run, setup the next loop. if ($result instanceof Executable) { $this->executableListByTier->addNextStageTier($result); return self::PROCESS_CONTINUE; } if (is_array($result) && count($result) != 0) { //It's an array of tiers to run. foreach ($result as $tier) { if (!$tier instanceof Executable) { throw new InvalidReturnException(self::RETURN_VALUE, $result); } $this->executableListByTier->addNextStageTier($tier); } return self::PROCESS_CONTINUE; } if ($result === false) { // The executed tier wasn't able to handle it e.g. a caching layer // There should be another tier to execute in this stage. return self::PROCESS_CONTINUE; } // If the $result is an expected product share it for further stages foreach ($this->expectedProducts as $expectedProduct => $created) { if ($result instanceof $expectedProduct) { if (strcasecmp($expectedProduct, get_class($result)) !== 0) { //product is a sub-class of the expected product. Setup an //alias for it $this->injector->alias($expectedProduct, get_class($result)); $this->expectedProducts[$expectedProduct] = true; } $this->injector->share($result); return self::PROCESS_END_STAGE; } } if ($result === self::PROCESS_END_STAGE || $result === self::PROCESS_CONTINUE || $result === self::PROCESS_END) { return $result; } // Otherwise it's an error throw InvalidReturnException::getWrongTypeException($result); }