PAGI\Client\Result\DigitReadResult::__construct PHP Method

__construct() public method

Constructor.
public __construct ( PAGI\Client\Result\IResult $result ) : void
$result PAGI\Client\Result\IResult Result to decorate.
return void
    public function __construct(IResult $result)
    {
        parent::__construct($result);
        $this->digits = false;
        $this->timeout = false;
        $result = $result->getResult();
        switch ($result) {
            case -1:
                throw new ChannelDownException();
                break;
            case 0:
                $this->timeout = true;
                break;
            default:
                $this->digits = chr(intval($result));
                break;
        }
    }

Usage Example

Example #1
0
 /**
  * Constructor.
  *
  * @param IResult $result Result to decorate.
  */
 public function __construct(IResult $result)
 {
     parent::__construct($result);
     // Reset timeout flag. This is because wait-for-digit returns 0 on timeout
     // and the result is the ascii char of the digit read, while other read
     // functions return the digits and (timeout) on data to signal a timeout.
     $this->timeout = false;
     $this->digits = $result->getResult();
     if ($result->hasData()) {
         $this->timeout = strpos($result->getData(), '(timeout)') !== false;
     }
 }