1<?php 2 3namespace React\Promise; 4 5class Deferred implements PromisorInterface 6{ 7 private $promise; 8 private $resolveCallback; 9 private $rejectCallback; 10 private $notifyCallback; 11 private $canceller; 12 13 public function __construct(callable $canceller = null) 14 { 15 $this->canceller = $canceller; 16 } 17 18 public function promise() 19 { 20 if (null === $this->promise) { 21 $this->promise = new Promise(function ($resolve, $reject, $notify) { 22 $this->resolveCallback = $resolve; 23 $this->rejectCallback = $reject; 24 $this->notifyCallback = $notify; 25 }, $this->canceller); 26 $this->canceller = null; 27 } 28 29 return $this->promise; 30 } 31 32 public function resolve($value = null) 33 { 34 $this->promise(); 35 36 \call_user_func($this->resolveCallback, $value); 37 } 38 39 public function reject($reason = null) 40 { 41 $this->promise(); 42 43 \call_user_func($this->rejectCallback, $reason); 44 } 45 46 /** 47 * @deprecated 2.6.0 Progress support is deprecated and should not be used anymore. 48 * @param mixed $update 49 */ 50 public function notify($update = null) 51 { 52 $this->promise(); 53 54 \call_user_func($this->notifyCallback, $update); 55 } 56 57 /** 58 * @deprecated 2.2.0 59 * @see Deferred::notify() 60 */ 61 public function progress($update = null) 62 { 63 $this->notify($update); 64 } 65} 66