Author: Marcelo Gornstein (marcelog@gmail.com)
Beispiel #1
0
 public function getCommonCallingCardValidations()
 {
     return array('cardExists' => Node::createValidatorInfo(function (Node $node) {
         $node->saveCustomData('myCardEntity', new Card());
         return true;
     }, 'pp/11'), 'cardIsNotExpired' => Node::createValidatorInfo(function (Node $node) {
         $card = $node->getCustomData('myCardEntity');
         return !$card->isExpired();
     }, 'pp/12'), 'cardIsNotDued' => Node::createValidatorInfo(function (Node $node) {
         $card = $node->getCustomData('myCardEntity');
         return !$card->isDued();
     }, 'pp/15'), 'cardIsNotInUse' => Node::createValidatorInfo(function (Node $node) {
         $card = $node->getCustomData('myCardEntity');
         return !$card->inUse();
     }, 'pp/34'));
 }
Beispiel #2
0
 /**
  * (non-PHPdoc)
  * @see PAGI\Node.Node::callClientMethods()
  */
 protected function callClientMethods($methods, $stopWhen = null)
 {
     $client = $this->getClient();
     $logger = $client->getLogger();
     $result = null;
     foreach ($methods as $callInfo) {
         foreach ($callInfo as $name => $arguments) {
             switch ($name) {
                 case 'streamFile':
                 case 'sayNumber':
                 case 'sayDigits':
                 case 'sayDateTime':
                     $this->sayInterruptable($name, $arguments);
                     break;
                 case 'waitDigit':
                     if (empty($this->mockedInput)) {
                         $client->onWaitDigit(false);
                     } else {
                         $digit = array_shift($this->mockedInput);
                         if ($digit == ' ') {
                             $client->onWaitDigit(false);
                         } else {
                             $client->onWaitDigit(true, $digit);
                         }
                     }
                     break;
                 default:
                     break;
             }
             $result = parent::callClientMethod($name, $arguments);
             if ($stopWhen !== null) {
                 if ($stopWhen($result)) {
                     return $result;
                 }
             }
         }
     }
     return $result;
 }
Beispiel #3
0
 /**
  * @test
  */
 public function can_create_validator_info()
 {
     $validatorInfo = Node::createValidatorInfo(function ($node) {
         return true;
     }, 'sound');
     $this->assertEquals($validatorInfo['soundOnError'], 'sound');
     $this->assertTrue($validatorInfo['callback'](null));
 }
Beispiel #4
0
 /**
  * Process the result of the given node. Returns false if no other nodes
  * should be run, or a string with the next node name.
  *
  * @param Node $node Node that was run.
  *
  * @return string|false
  */
 protected function processNodeResult(Node $node)
 {
     $ret = false;
     $name = $node->getName();
     if (isset($this->nodeResults[$name])) {
         foreach ($this->nodeResults[$name] as $resultInfo) {
             /* @var $resultInfo NodeActionCommand */
             if ($resultInfo->appliesTo($node)) {
                 if ($resultInfo->isActionHangup()) {
                     $this->logDebug("Hanging up after {$name}");
                     $this->client->hangup();
                 } elseif ($resultInfo->isActionJumpTo()) {
                     $data = $resultInfo->getActionData();
                     if (isset($data['nodeEval'])) {
                         $callback = $data['nodeEval'];
                         $nodeName = $callback($node);
                     } else {
                         $nodeName = $data['nodeName'];
                     }
                     $this->logDebug("Jumping from {$name} to {$nodeName}");
                     $ret = $nodeName;
                     break;
                 } elseif ($resultInfo->isActionExecute()) {
                     $this->logDebug("Executing callback after {$name}");
                     $data = $resultInfo->getActionData();
                     $callback = $data['callback'];
                     $callback($node);
                 }
             }
         }
     }
     return $ret;
 }