You are here

function uploadAndMatchContextDemo in TMGMT Translator Smartling 8.3

Same name and namespace in other branches
  1. 8.4 vendor/smartling/api-sdk-php/examples/context-example.php \uploadAndMatchContextDemo()
  2. 8.2 api-sdk-php/examples/context-example.php \uploadAndMatchContextDemo()
  3. 8.2 vendor/smartling/api-sdk-php/examples/context-example.php \uploadAndMatchContextDemo()

Parameters

\Smartling\AuthApi\AuthApiInterface $authProvider:

string $projectId:

string $fileUri: Context file uri.

string $contentFileUri: Uri of a file which contains source strings.

Return value

array

1 call to uploadAndMatchContextDemo()
context-example.php in vendor/smartling/api-sdk-php/examples/context-example.php

File

vendor/smartling/api-sdk-php/examples/context-example.php, line 127

Code

function uploadAndMatchContextDemo($authProvider, $projectId, $fileUri, $contentFileUri) {
  $response = FALSE;
  $context = \Smartling\Context\ContextApi::create($authProvider, $projectId);
  $matchParams = new MatchContextParameters();
  $matchParams
    ->setContentFileUri($contentFileUri);
  $params = new UploadContextParameters();
  $params
    ->setContent($fileUri);
  $params
    ->setMatchParams($matchParams);
  $params
    ->setName('context.html');
  $st = microtime(true);
  try {
    $response = $context
      ->uploadAndMatchContext($params);
  } 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;
}