class SmartlingApiFactory in TMGMT Translator Smartling 8.2
Same name and namespace in other branches
- 8.4 src/Smartling/SmartlingApiFactory.php \Drupal\tmgmt_smartling\Smartling\SmartlingApiFactory
- 8.3 src/Smartling/SmartlingApiFactory.php \Drupal\tmgmt_smartling\Smartling\SmartlingApiFactory
Class SmartlingApiFactory @package Drupal\tmgmt_smartling\Smartling
Hierarchy
- class \Drupal\tmgmt_smartling\Smartling\SmartlingApiFactory
Expanded class hierarchy of SmartlingApiFactory
1 file declares its use of SmartlingApiFactory
- BufferLogger.php in src/
Logger/ BufferLogger.php
1 string reference to 'SmartlingApiFactory'
1 service uses SmartlingApiFactory
File
- src/
Smartling/ SmartlingApiFactory.php, line 22 - SmartlingApiFactory.php.
Namespace
Drupal\tmgmt_smartling\SmartlingView source
class SmartlingApiFactory {
/**
* Returns module version.
*
* @param string $name
* @param string $default
* @return string
*/
public static function getModuleVersion($name = 'tmgmt_smartling', $default = '8.x-2.x-dev') {
$info = system_get_info('module', $name);
$client_version = $default;
if (!empty($info['version'])) {
$client_version = $info['version'];
}
return $client_version;
}
/**
* Returns API object as a service.
*
* @param array $settings
* @param string $api_type
*
* @return \Smartling\BaseApiAbstract
* @throws \Exception
* @throws \Smartling\Exceptions\SmartlingApiException
*/
static function create(array $settings, $api_type) {
require_once __DIR__ . '/../../vendor/autoload.php';
if (empty($settings['user_id']) || empty($settings['project_id']) || empty($settings['token_secret'])) {
throw new SmartlingApiException('The "User Id", "Token Secret", or "Project Id" are not correct.');
}
BaseApiAbstract::setCurrentClientId('drupal-tmgmt-connector');
BaseApiAbstract::setCurrentClientVersion(self::getModuleVersion());
$auth_provider = AuthTokenProvider::create($settings['user_id'], $settings['token_secret']);
$logger = \Drupal::logger('smartling_api');
$api = NULL;
switch ($api_type) {
case 'file':
$api = FileApi::create($auth_provider, $settings['project_id'], $logger);
break;
case 'project':
$api = ProjectApi::create($auth_provider, $settings['project_id'], $logger);
break;
case 'context':
$api = ContextApi::create($auth_provider, $settings['project_id'], $logger);
break;
default:
throw new Exception('Unsupported API has been requested: ' . $api_type);
}
return $api;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
SmartlingApiFactory:: |
static | function | Returns API object as a service. | |
SmartlingApiFactory:: |
public static | function | Returns module version. |