public function BynderApi::__call in Bynder 8.3
Same name and namespace in other branches
- 8 src/BynderApi.php \Drupal\bynder\BynderApi::__call()
- 8.2 src/BynderApi.php \Drupal\bynder\BynderApi::__call()
- 4.0.x src/BynderApi.php \Drupal\bynder\BynderApi::__call()
File
- src/
BynderApi.php, line 446
Class
- BynderApi
- Bynder API service.
Namespace
Drupal\bynderCode
public function __call($method, $args) {
$bynder_configuration = $this->configFactory
->get('bynder.settings');
if ($bynder_configuration
->get('debug')) {
$this->loggerFactory
->get('bynder')
->debug('Method: %method is called with arguments: @args', [
'%method' => $method,
'@args' => print_r($args, TRUE),
]);
}
try {
// TODO cache getMediaItem()?
if (empty($args) && in_array($method, array_keys(self::CACHED_CALLS))) {
if ($cache_item = $this->cache
->get(self::CACHED_CALLS[$method], TRUE)) {
return $cache_item->data;
}
else {
$result = call_user_func_array([
$this
->getAssetBankManager(),
$method,
], $args)
->wait();
$this->cache
->set(self::CACHED_CALLS[$method], $result, $this->configFactory
->get('bynder.settings')
->get('cache_lifetime') + $this->time
->getRequestTime());
return $result;
}
}
else {
$result = call_user_func_array([
$this
->getAssetBankManager(),
$method,
], $args)
->wait();
}
if ($bynder_configuration
->get('debug')) {
$this->loggerFactory
->get('bynder')
->debug('Method: %method returns: @result', [
'%method' => $method,
'@result' => print_r($result, TRUE),
]);
}
return $result;
} catch (\Exception $e) {
if ($bynder_configuration
->get('debug')) {
$this->loggerFactory
->get('bynder')
->error('Method: %method throws error with message: @message', [
'%method' => $method,
'@message' => $e
->getMessage(),
]);
}
throw $e;
}
}