Skip to content
This repository was archived by the owner on Feb 7, 2025. It is now read-only.
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add onApiCallMethod
  • Loading branch information
camaxtly committed May 30, 2021
commit dfad157530d7f44adba11f1ae39377f94c7cb89b
24 changes: 22 additions & 2 deletions src/bitrix24.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ class Bitrix24 implements iBitrix24
*/
protected $_onExpiredToken;

/**
* @var callable callback after api method called
*/
protected $_onCallApiMethod;

/**
* @var bool ssl verify for checking CURLOPT_SSL_VERIFYPEER and CURLOPT_SSL_VERIFYHOST
*/
Expand Down Expand Up @@ -204,6 +209,16 @@ public function setOnExpiredToken(callable $callback)
$this->_onExpiredToken = $callback;
}

/**
* Set function called after api method executed. Callback receives instance as first parameter, method name as second.
*
* @param callable $callback
*/
public function setOnCallApiMethod(callable $callback)
{
$this->_onCallApiMothod = $callback;
}

/**
* Get a random string to sign protected api-call. Use salt for argument "state" in secure api-call
* random string is a result of mt_rand function
Expand Down Expand Up @@ -1114,8 +1129,13 @@ public function processBatchCalls($halt = 0, $delay = self::BATCH_DELAY)
public function call($methodName, array $additionalParameters = array())
{
try {
$result = $this->getWebhookUsage() ? $this->_call_webhook($methodName, $additionalParameters)
: $this->_call($methodName, $additionalParameters);
$result = $this->getWebhookUsage() ? $this->_call_webhook($methodName, $additionalParameters)
: $this->_call($methodName, $additionalParameters);

if (is_callable($this->_onCallApiMothod)) {
call_user_func($this->_onCallApiMothod, $this, $methodName);
}

} catch (Bitrix24TokenIsExpiredException $e) {
if (!is_callable($this->_onExpiredToken)) {
throw $e;
Expand Down