Example #1
0
 /**
  *
  * @param Store $store
  * @throws PromiseException
  */
 public function __construct($promiseData = [], $result = null)
 {
     parent::__construct($promiseData);
     $this->data[Store::STATE] = PromiseInterface::REJECTED;
     if (isset($this->data[Store::RESULT]) || is_null($result)) {
         return;
     }
     if ($result instanceof \Exception) {
         $reason = "Exception with class '" . get_class($result) . "' was thrown. Promise: " . $this->data[Store::ID];
         $result = new RejectedException($reason, 0, $result);
         $this->data[Store::RESULT] = $this->serializeResult($result);
         return;
     }
     //
     //        if ($result instanceof PromiseInterface) {
     //            $result = $result->getId();
     //        }
     if (!$this->isId($result) && !$result instanceof PromiseInterface) {
         set_error_handler(function ($number, $string) {
             throw new PromiseException("RejectedPromise. String: {$string},  Number: {$number}", null, null);
         });
         try {
             //result can be converted to string
             $result = new RejectedException(strval($result));
         } catch (\Exception $exc) {
             //result can not be converted to string
             $reason = 'Reason cannot be converted to string.  Promise: ' . $this->data[Store::ID];
             $result = new RejectedException($reason, 0, $exc);
         }
         restore_error_handler();
     }
     $this->data[Store::RESULT] = $this->serializeResult($result);
 }
Example #2
0
 /**
  *
  * @param Store $store
  * @throws PromiseException
  */
 public function __construct($promiseData = [], $result = null)
 {
     parent::__construct($promiseData);
     $this->data[Store::STATE] = PromiseInterface::FULFILLED;
     if (!isset($this->data[Store::RESULT]) && !is_null($result)) {
         $this->data[Store::RESULT] = $this->serializeResult($result);
     }
 }