project-example.php in TMGMT Translator Smartling 8.4
File
vendor/smartling/api-sdk-php/examples/project-example.php
View source
<?php
error_reporting(E_ALL);
$longOpts = [
'project-id:',
'user-id:',
'secret-key:',
];
$options = getopt('', $longOpts);
if (!array_key_exists('project-id', $options) || !array_key_exists('user-id', $options) || !array_key_exists('secret-key', $options)) {
echo 'Missing required params.' . PHP_EOL;
exit;
}
$autoloader = '../vendor/autoload.php';
if (!file_exists($autoloader) || !is_readable($autoloader)) {
echo 'Error. Autoloader not found. Seems you didn\'t run:' . PHP_EOL . ' composer update' . PHP_EOL;
exit;
}
else {
require_once '../vendor/autoload.php';
}
$projectId = $options['project-id'];
$userIdentifier = $options['user-id'];
$userSecretKey = $options['secret-key'];
$authProvider = \Smartling\AuthApi\AuthTokenProvider::create($userIdentifier, $userSecretKey);
function projectDetailsDemo($authProvider, $projectId) {
$response = false;
$project = \Smartling\Project\ProjectApi::create($authProvider, $projectId);
$st = microtime(true);
try {
$response = $project
->getProjectDetails();
} catch (\Smartling\Exceptions\SmartlingApiException $e) {
var_dump($e
->getErrors());
}
$et = microtime(true);
$time = $et - $st;
echo vsprintf('Request took %s seconds.%s', [
round($time, 3),
"\n\r",
]);
if (!empty($response)) {
var_dump($response);
}
return $response;
}
$response = projectDetailsDemo($authProvider, $projectId);