Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #31 from jacobkiers/pami-setactionid

Allow setting the ActionID on an Action message.
  • Loading branch information...
commit 83fe5cf3a3fc48f204c70db416cd724dc2792a17 2 parents 13d3b92 + 4e22e44
@marcelog authored
View
27 src/mg/PAMI/Message/Action/ActionMessage.php
@@ -29,6 +29,7 @@
namespace PAMI\Message\Action;
use PAMI\Message\OutgoingMessage;
+use PAMI\Exception\PAMIException;
/**
* A generic action ami message.
@@ -56,4 +57,30 @@ public function __construct($what)
$this->setKey('Action', $what);
$this->setKey('ActionID', microtime(true));
}
+
+ /**
+ * Sets Action ID.
+ *
+ * The ActionID can be at most 69 characters long, according to
+ * {@link https://issues.asterisk.org/jira/browse/14847 Asterisk Issue 14847}.
+ *
+ * Therefore we'll throw an exception when the ActionID is too long.
+ *
+ * @param $actionID The Action ID to have this action known by
+ *
+ * @return void
+ * @throws PAMIException When the ActionID is more then 69 characters long
+ */
+ public function setActionID($actionID)
+ {
+ if (0 == strlen($actionID)) {
+ throw new PAMIException('ActionID cannot be empty.');
+ }
+
+ if (strlen($actionID) > 69) {
+ throw new PAMIException('ActionID can be at most 69 characters long.');
+ }
+
+ $this->setKey('ActionID', $actionID);
+ }
}
View
34 test/actions/Test_Actions.php
@@ -1386,5 +1386,39 @@ public function can_originate()
$action->setVariable('a', 'b');
$client = $this->_start($write, $action);
}
+
+ /**
+ * @test
+ */
+ public function can_set_actionid()
+ {
+ $action = new \PAMI\Message\Action\PingAction();
+ // ActionID is between 0 and 69 characters long.
+ $actionID = '121234567890123456789012345678901234567890';
+ $action->setActionID($actionID);
+ $this->assertSame($actionID, $action->getActionID());
+ }
+
+ /**
+ * @test
+ * @expectedException \PAMI\Exception\PAMIException
+ */
+ public function cannot_set_actionid_longer_than_69_characters()
+ {
+ $action = new \PAMI\Message\Action\PingAction();
+ // A 70-character long ActionID
+ $action->setActionID('1234567890123456789012345678901234567890123456789012345678901234567890');
+ }
+
+ /**
+ * @test
+ * @expectedException \PAMI\Exception\PAMIException
+ */
+ public function cannot_set_empty_actionid()
+ {
+ $action = new \PAMI\Message\Action\PingAction();
+ // An empty ActionID
+ $action->setActionID('');
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.